1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15function parse (txt) { 16 try { 17 eval (txt) 18 assert (false) 19 } catch (e) { 20 assert (e instanceof SyntaxError) 21 } 22} 23 24var a = 21; 25var b = 10; 26var c; 27 28parse ("c = a++b"); 29parse ("c = a--b"); 30 31parse ("c = a +* b"); 32parse ("c = a -* b"); 33parse ("c = a +/ b"); 34parse ("c = a -/ b"); 35parse ("c = a +% b"); 36parse ("c = a -% b"); 37 38parse ("a =* b"); 39parse ("a =/ b"); 40parse ("a =% b"); 41 42parse ("c = a+"); 43parse ("c = a-"); 44 45parse("a++\n()"); 46parse("a--\n.b"); 47 48assert((-2 .toString()) === -2); 49 50Number.prototype[0] = 123; 51assert(-2[0] === -123); 52 53function f() { 54 var a = 0; 55 function g() {} 56 57 try { 58 eval ("g(this, 'a' = 1)"); 59 assert (false); 60 } catch (e) { 61 assert (e instanceof ReferenceError); 62 } 63 64 try { 65 eval ("g(this, 'a' += 1)"); 66 assert (false); 67 } catch (e) { 68 assert (e instanceof ReferenceError); 69 } 70 71 assert (a === 0); 72} 73f(); 74 75function g(a, b) 76{ 77 assert(b === "undefined"); 78} 79g(this, typeof undeclared_var) 80 81function h() 82{ 83 var done = false; 84 var o = { a: function () { done = (this === o) } } 85 function f() {} 86 87 with (o) { 88 f(this, a()); 89 } 90 assert(done); 91} 92h(); 93