diff --git a/test/built-ins/Proxy/apply/call-parameters.js b/test/built-ins/Proxy/apply/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..cf7bb758daad5f44082f057566e48ea14c628f28 --- /dev/null +++ b/test/built-ins/Proxy/apply/call-parameters.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + trap is called with handler object as its context, and parameters are: + target, the call context and and an array list with the called arguments +info: > + [[Call]] (thisArgument, argumentsList) + + 9. Return Call(trap, handler, «target, thisArgument, argArray»). +---*/ + +var _target, _args, _handler, _context; +var target = function(a, b) { return a + b; }; +var handler = { + apply: function(t, c, args) { + _handler = this; + _target = t; + _context = c; + _args = args; + } +}; +var p = new Proxy(target, handler); + +var context = {}; + +p.call(context, 1, 2); + +assert.sameValue(_handler, handler, "trap context is the handler object"); +assert.sameValue(_target, target, "first parameter is the target object"); +assert.sameValue(_context, context, "second parameter is the call context"); +assert.sameValue(_args.length, 2, "arguments list contains all call arguments"); +assert.sameValue(_args[0], 1, "arguments list has first call argument"); +assert.sameValue(_args[1], 2, "arguments list has second call argument"); diff --git a/test/built-ins/Proxy/apply/call-result.js b/test/built-ins/Proxy/apply/call-result.js new file mode 100644 index 0000000000000000000000000000000000000000..e027fc3d9b0b9e6df8d78b61c3a654e25dc3fe7c --- /dev/null +++ b/test/built-ins/Proxy/apply/call-result.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + Return the result from the trap method. +info: > + [[Call]] (thisArgument, argumentsList) + + 9. Return Call(trap, handler, «target, thisArgument, argArray»). +---*/ + +var target = function(a, b) { return a + b; }; +var result = {}; +var handler = { + apply: function(t, c, args) { + return result; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(p.call(), result); diff --git a/test/built-ins/Proxy/apply/null-handler.js b/test/built-ins/Proxy/apply/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..5906aef045bee1f118ad03fd0ba4d75ae99a6059 --- /dev/null +++ b/test/built-ins/Proxy/apply/null-handler.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + [[Call]] (thisArgument, argumentsList) + + 2. If handler is null, throw a TypeError exception. +---*/ + + +var p = Proxy.revocable(function() {}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy(); +}); diff --git a/test/built-ins/Proxy/apply/return-abrupt.js b/test/built-ins/Proxy/apply/return-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..41211f332519f710c06dd97fce4e4c0b705c2600 --- /dev/null +++ b/test/built-ins/Proxy/apply/return-abrupt.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + Return is an abrupt completion +includes: [Test262Error.js] +---*/ + +var target = function(a, b) { return a + b; }; +var p = new Proxy(target, { + apply: function(t, c, args) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.call(); +}); diff --git a/test/built-ins/Proxy/apply/trap-is-not-callable.js b/test/built-ins/Proxy/apply/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..b033e8dd418258ae3bb868c505c1a6de00377778 --- /dev/null +++ b/test/built-ins/Proxy/apply/trap-is-not-callable.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + Throws if trap is not callable. +---*/ + +var p = new Proxy(function() {}, { + apply: {} +}); + +assert.throws(TypeError, function() { + p(); +}); diff --git a/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js b/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js new file mode 100644 index 0000000000000000000000000000000000000000..65f5810b558ab10ee7868dc08cb1a3989f9b9399 --- /dev/null +++ b/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + If trap is undefined, propagate the call to the target object. +info: > + [[Call]] (thisArgument, argumentsList) + + 7. If trap is undefined, then Return Call(target, thisArgument, + argumentsList). +---*/ + +var target = function(a, b) { + return a + b; +}; +var p = new Proxy(target, {}); + +assert.sameValue(p(1, 2), 3); diff --git a/test/built-ins/Proxy/apply/trap-is-undefined.js b/test/built-ins/Proxy/apply/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..f16cadaa6ea81f992209c48f3fa2bbaa53a0d84e --- /dev/null +++ b/test/built-ins/Proxy/apply/trap-is-undefined.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.13 +description: > + If trap is undefined, propagate the call to the target object. +info: > + [[Call]] (thisArgument, argumentsList) + + 7. If trap is undefined, then Return Call(target, thisArgument, + argumentsList). +---*/ + +var target = function(a, b) { + return a + b; +}; +var p = new Proxy(target, { + apply: undefined +}); + +assert.sameValue(p(1, 2), 3); diff --git a/test/built-ins/Proxy/construct/call-parameters.js b/test/built-ins/Proxy/construct/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..8ccd164b421937b5b562d7dfc9519e7e561b95ea --- /dev/null +++ b/test/built-ins/Proxy/construct/call-parameters.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + trap is called with handler object as its context, and parameters are: + target, an array list with the called arguments and the new target, and the + constructor new.target. +info: > + [[Construct]] ( argumentsList, newTarget) + + 9. Let newObj be Call(trap, handler, «target, argArray, newTarget »). +---*/ + +var _target, _handler, _args, _P; +function Target() {} + +var handler = { + construct: function(t, args, newTarget) { + _handler = this; + _target = t; + _args = args; + _P = newTarget; + + return new t(args[0], args[1]); + } +}; +var P = new Proxy(Target, handler); + +new P(1, 2); + +assert.sameValue(_handler, handler, "trap context is the handler object"); +assert.sameValue(_target, Target, "first parameter is the target object"); +assert.sameValue(_args.length, 2, "arguments list contains all call arguments"); +assert.sameValue(_args[0], 1, "arguments list has first call argument"); +assert.sameValue(_args[1], 2, "arguments list has second call argument"); +assert.sameValue(_P, P, "constructor is sent as the third parameter"); diff --git a/test/built-ins/Proxy/construct/call-result.js b/test/built-ins/Proxy/construct/call-result.js new file mode 100644 index 0000000000000000000000000000000000000000..00709d9a1a21dcfa819d1fd37a0fe88e918312b3 --- /dev/null +++ b/test/built-ins/Proxy/construct/call-result.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Return the result from the trap method. +info: > + [[Construct]] ( argumentsList, newTarget) + + 12. Return newObj +---*/ + +function Target(a, b) { + this.sum = a + b; +}; +var handler = { + construct: function(t, c, args) { + return { sum: 42 }; + } +}; +var P = new Proxy(Target, handler); + +assert.sameValue((new P(1, 2)).sum, 42); diff --git a/test/built-ins/Proxy/construct/null-handler.js b/test/built-ins/Proxy/construct/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..3c60321618318ee2130d00585eaf16e30f7ad2c8 --- /dev/null +++ b/test/built-ins/Proxy/construct/null-handler.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + [[Construct]] ( argumentsList, newTarget) + + 2. If handler is null, throw a TypeError exception. +---*/ + + +var p = Proxy.revocable(function() {}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + new p.proxy(); +}); diff --git a/test/built-ins/Proxy/construct/return-is-abrupt.js b/test/built-ins/Proxy/construct/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..fb607446df5047f84002a7b01909a5795bed673b --- /dev/null +++ b/test/built-ins/Proxy/construct/return-is-abrupt.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Return abrupt from constructor call. +info: > + [[Construct]] ( argumentsList, newTarget) + + 9. Let newObj be Call(trap, handler, «target, argArray, newTarget »). + 10. ReturnIfAbrupt(newObj). +includes: [Test262Error.js] +---*/ + +function Target() {} +var P = new Proxy(Target, { + construct: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + new P(); +}); diff --git a/test/built-ins/Proxy/construct/return-not-object-throws-boolean.js b/test/built-ins/Proxy/construct/return-not-object-throws-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..c9681ee6286aada7096d783f3c5aa2497179f234 --- /dev/null +++ b/test/built-ins/Proxy/construct/return-not-object-throws-boolean.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Throws a TypeError if trap result is not an Object: Boolean +info: > + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +---*/ + +function Target() { + this.attr = "done"; +}; +var P = new Proxy(Target, { + construct: function() { + return true; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); diff --git a/test/built-ins/Proxy/construct/return-not-object-throws-number.js b/test/built-ins/Proxy/construct/return-not-object-throws-number.js new file mode 100644 index 0000000000000000000000000000000000000000..ad00e2b0032d15f5684cc19b2ed76caad214e821 --- /dev/null +++ b/test/built-ins/Proxy/construct/return-not-object-throws-number.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Throws a TypeError if trap result is not an Object: Number +info: > + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +---*/ + +function Target() { + this.attr = "done"; +}; +var P = new Proxy(Target, { + construct: function() { + return 0; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); diff --git a/test/built-ins/Proxy/construct/return-not-object-throws-string.js b/test/built-ins/Proxy/construct/return-not-object-throws-string.js new file mode 100644 index 0000000000000000000000000000000000000000..5fd1e1c44d6a45f94b9b4892dcc30b88dc12f90a --- /dev/null +++ b/test/built-ins/Proxy/construct/return-not-object-throws-string.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Throws a TypeError if trap result is not an Object: String +info: > + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +---*/ + +function Target() { + this.attr = "done"; +}; +var P = new Proxy(Target, { + construct: function() { + return ""; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); diff --git a/test/built-ins/Proxy/construct/return-not-object-throws-symbol.js b/test/built-ins/Proxy/construct/return-not-object-throws-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a72544f7b4abb6c06f3190fd594c23ba2ec51f86 --- /dev/null +++ b/test/built-ins/Proxy/construct/return-not-object-throws-symbol.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Throws a TypeError if trap result is not an Object: Symbol +info: > + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +function Target() { + this.attr = "done"; +}; +var P = new Proxy(Target, { + construct: function() { + return Symbol(); + } +}); + +assert.throws(TypeError, function() { + new P(); +}); diff --git a/test/built-ins/Proxy/construct/return-not-object-throws-undefined.js b/test/built-ins/Proxy/construct/return-not-object-throws-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..07297159003c2ca499d8ebe8b55d4afe5a857b7d --- /dev/null +++ b/test/built-ins/Proxy/construct/return-not-object-throws-undefined.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Throws a TypeError if trap result is not an Object: undefined +info: > + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +---*/ + +function Target() { + this.attr = "done"; +}; +var P = new Proxy(Target, { + construct: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); diff --git a/test/built-ins/Proxy/construct/trap-is-not-callable.js b/test/built-ins/Proxy/construct/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..f0c66394a5e1d266e178b3a8af4d471d8003308a --- /dev/null +++ b/test/built-ins/Proxy/construct/trap-is-not-callable.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + Throws if trap is not callable. +---*/ + +function Target() {} +var p = new Proxy(Target, { + construct: {} +}); + +assert.throws(TypeError, function() { + new p(); +}); diff --git a/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js b/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js new file mode 100644 index 0000000000000000000000000000000000000000..57e2c3be2f17256e27748b8010ba257e14bb1363 --- /dev/null +++ b/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + If trap is undefined, propagate the construct to the target object. +info: > + [[Construct]] ( argumentsList, newTarget) + + 7. If trap is undefined, then + b. Return Construct(target, argumentsList, newTarget). +---*/ + +function Target(arg) { + this.attr = arg; +} +var P = new Proxy(Target, {}); + +assert.sameValue((new P("foo")).attr, "foo"); diff --git a/test/built-ins/Proxy/construct/trap-is-undefined.js b/test/built-ins/Proxy/construct/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..fb9a4a23775cdd08f8285ac4585bd255c965a98b --- /dev/null +++ b/test/built-ins/Proxy/construct/trap-is-undefined.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.14 +description: > + If trap is undefined, propagate the construct to the target object. +info: > + [[Construct]] ( argumentsList, newTarget) + + 7. If trap is undefined, then + b. Return Construct(target, argumentsList, newTarget). +---*/ + +function Target(arg) { + this.attr = arg; +} +var P = new Proxy(Target, { + construct: undefined +}); + +assert.sameValue((new P("foo")).attr, "foo"); diff --git a/test/built-ins/Proxy/constructor.js b/test/built-ins/Proxy/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..1fff16b9674925e512fc0e8074d06abca3196a48 --- /dev/null +++ b/test/built-ins/Proxy/constructor.js @@ -0,0 +1,10 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.1 +description: > + The Proxy constructor is the %Proxy% intrinsic object and the + initial value of the Proxy property of the global object. +---*/ + +assert.sameValue(typeof Proxy, "function", "`typeof Proxy` is `'function'`"); diff --git a/test/built-ins/Proxy/create-handler-is-revoked-proxy.js b/test/built-ins/Proxy/create-handler-is-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..5126e4cb0f8c08b1aae7f42165f040ba96111808 --- /dev/null +++ b/test/built-ins/Proxy/create-handler-is-revoked-proxy.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 4. If handler is a Proxy exotic object and the value of the + [[ProxyHandler]] internal slot of handler is null, throw a + TypeError exception. + ... +---*/ + +var revocable = Proxy.revocable({}, {}); + +revocable.revoke(); + +assert.throws(TypeError, function() { + new Proxy({}, revocable.proxy); +}); diff --git a/test/built-ins/Proxy/create-handler-not-object-throw-boolean.js b/test/built-ins/Proxy/create-handler-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..891c1826b183b2ddc2752fea8aec03741e30c287 --- /dev/null +++ b/test/built-ins/Proxy/create-handler-not-object-throw-boolean.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 3. If Type(handler) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy({}, false); +}); diff --git a/test/built-ins/Proxy/create-handler-not-object-throw-null.js b/test/built-ins/Proxy/create-handler-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..7abcc0b2dbdc422f4c872d0b747c246dc838a836 --- /dev/null +++ b/test/built-ins/Proxy/create-handler-not-object-throw-null.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 3. If Type(handler) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy({}, null); +}); diff --git a/test/built-ins/Proxy/create-handler-not-object-throw-number.js b/test/built-ins/Proxy/create-handler-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..7cb41f20b5ed73ef38ab8a635b99626f74bad0a2 --- /dev/null +++ b/test/built-ins/Proxy/create-handler-not-object-throw-number.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 3. If Type(handler) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy({}, 0); +}); diff --git a/test/built-ins/Proxy/create-handler-not-object-throw-string.js b/test/built-ins/Proxy/create-handler-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..25f1982ec3f6ab620ad2d9731cfd775b5dd6cf9c --- /dev/null +++ b/test/built-ins/Proxy/create-handler-not-object-throw-string.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 3. If Type(handler) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy({}, ""); +}); diff --git a/test/built-ins/Proxy/create-handler-not-object-throw-symbol.js b/test/built-ins/Proxy/create-handler-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..38013342310f75d5c878224f39b62fc2c41a4839 --- /dev/null +++ b/test/built-ins/Proxy/create-handler-not-object-throw-symbol.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 3. If Type(handler) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + new Proxy({}, Symbol()); +}); diff --git a/test/built-ins/Proxy/create-handler-not-object-throw-undefined.js b/test/built-ins/Proxy/create-handler-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8dd8f172b44e0dabac5a185d67e9818ff9fce8f6 --- /dev/null +++ b/test/built-ins/Proxy/create-handler-not-object-throw-undefined.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 3. If Type(handler) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy({}, undefined); +}); diff --git a/test/built-ins/Proxy/create-target-is-not-callable.js b/test/built-ins/Proxy/create-target-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..696403483a8580e2d49f8eaca6c684af829de6f5 --- /dev/null +++ b/test/built-ins/Proxy/create-target-is-not-callable.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + A Proxy exotic object is only callable if the given target is callable. +info: > + Proxy ( target, handler ) + + 7. If IsCallable(target) is true, then + a. Set the [[Call]] internal method of P as specified in 9.5.13. + ... + + + 12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, + tailPosition ) + + 4. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, {}); + +assert.throws(TypeError, function() { + p.call(); +}); diff --git a/test/built-ins/Proxy/create-target-is-not-constructor.js b/test/built-ins/Proxy/create-target-is-not-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..f69d63d927937b10c3eec7f9fea6ddfe71d50572 --- /dev/null +++ b/test/built-ins/Proxy/create-target-is-not-constructor.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + A Proxy exotic object only accepts a constructor call if target is + constructor. +info: > + Proxy ( target, handler ) + + 7. If IsCallable(target) is true, then + b. If target has a [[Construct]] internal method, then + i. Set the [[Construct]] internal method of P as specified in + 9.5.14. + ... + + 12.3.3.1.1 Runtime Semantics: EvaluateNew(constructProduction, arguments) + + 8. If IsConstructor (constructor) is false, throw a TypeError exception. +---*/ + +var p = new Proxy(eval, {}); + +p(); // the Proxy object is callable + +assert.throws(TypeError, function() { + new p(); +}); diff --git a/test/built-ins/Proxy/create-target-is-revoked-proxy.js b/test/built-ins/Proxy/create-target-is-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..f68607b36dab7cd8f533d0988043bcfd3aab1f91 --- /dev/null +++ b/test/built-ins/Proxy/create-target-is-revoked-proxy.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 2. If target is a Proxy exotic object and the value of the + [[ProxyHandler]] internal slot of target is null, throw a + TypeError exception. + ... +---*/ + +var revocable = Proxy.revocable({}, {}); + +revocable.revoke(); + +assert.throws(TypeError, function() { + new Proxy(revocable.proxy, {}); +}); diff --git a/test/built-ins/Proxy/create-target-not-object-throw-boolean.js b/test/built-ins/Proxy/create-target-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..d43e653e9860cb5998732735370a5cba9e26c32b --- /dev/null +++ b/test/built-ins/Proxy/create-target-not-object-throw-boolean.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy(false, {}); +}); diff --git a/test/built-ins/Proxy/create-target-not-object-throw-null.js b/test/built-ins/Proxy/create-target-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..845cb6592fcfb8d68469cb6eb6d3f282e34dbdea --- /dev/null +++ b/test/built-ins/Proxy/create-target-not-object-throw-null.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy(null, {}); +}); diff --git a/test/built-ins/Proxy/create-target-not-object-throw-number.js b/test/built-ins/Proxy/create-target-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..2dae22e7983beb3bae8eca9f67fb4960086b6486 --- /dev/null +++ b/test/built-ins/Proxy/create-target-not-object-throw-number.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy(0, {}); +}); diff --git a/test/built-ins/Proxy/create-target-not-object-throw-string.js b/test/built-ins/Proxy/create-target-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..d442b2e1503e8d8e9a1485934606e13890fecf95 --- /dev/null +++ b/test/built-ins/Proxy/create-target-not-object-throw-string.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy("", {}); +}); diff --git a/test/built-ins/Proxy/create-target-not-object-throw-symbol.js b/test/built-ins/Proxy/create-target-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a3569f23db1bcd3f315932d334c99d50a1c2d299 --- /dev/null +++ b/test/built-ins/Proxy/create-target-not-object-throw-symbol.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + new Proxy(Symbol(), {}); +}); diff --git a/test/built-ins/Proxy/create-target-not-object-throw-undefined.js b/test/built-ins/Proxy/create-target-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..9cda79c82988d8ab6ada707f19eedf44db48a517 --- /dev/null +++ b/test/built-ins/Proxy/create-target-not-object-throw-undefined.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.15 +description: > + Proxy ( target, handler ) + ... + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + new Proxy(undefined, {}); +}); diff --git a/test/built-ins/Proxy/defineProperty/call-parameters.js b/test/built-ins/Proxy/defineProperty/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..82db233a1f00b99391131b9edf475d739456152b --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/call-parameters.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Trap is called with handler as context and parameters are target, P, and the + descriptor object. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 9. Let descObj be FromPropertyDescriptor(Desc). + 10. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, + descObj»)). + ... +---*/ + +var _handler, _target, _prop, _desc; +var target = {}; +var descriptor = { + configurable: true, + enumerable: true, + writable: true, + value: 1 +}; +var handler = { + defineProperty: function(t, prop, desc) { + _handler = this; + _target = t; + _prop = prop; + _desc = desc; + + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(p, "attr", descriptor); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); + +assert.sameValue( + Object.keys(_desc).length, 4, + "descriptor arg has the same amount of keys as given descriptor" +); + +assert(_desc.configurable); +assert(_desc.writable); +assert(_desc.enumerable); +assert.sameValue(_desc.value, 1); diff --git a/test/built-ins/Proxy/defineProperty/null-handler.js b/test/built-ins/Proxy/defineProperty/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..ffbf14733787daa65c7bafef2098efba6e587184 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/null-handler.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.defineProperty(p.proxy, "foo", { + configurable: true, + enumerable: true + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js b/test/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js new file mode 100644 index 0000000000000000000000000000000000000000..2e4699cbf6e65d74cd269b458d8ce758e36966bc --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js @@ -0,0 +1,46 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + If a property has a corresponding target object property then applying the + Property Descriptor of the property to the target object using + [[DefineOwnProperty]] will not throw an exception. +features: [Reflect] +includes: [propertyHelper.js] +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return Object.defineProperty(t, prop, desc); + } +}); + +var result = Reflect.defineProperty(p, "attr", { + configurable: true, + enumerable: true, + writable: true, + value: 1 +}); + +assert.sameValue(result, true, "result === true"); + +verifyEqualTo(target, "attr", 1); +verifyWritable(target, "attr"); +verifyEnumerable(target, "attr"); +verifyConfigurable(target, "attr"); + +result = Reflect.defineProperty(p, "attr", { + configurable: false, + enumerable: false, + writable: false, + value: 2 +}); + +assert.sameValue(result, true, "result === true"); + +verifyEqualTo(target, "attr", 2); +verifyNotWritable(target, "attr"); +verifyNotEnumerable(target, "attr"); +verifyNotConfigurable(target, "attr"); diff --git a/test/built-ins/Proxy/defineProperty/return-is-abrupt.js b/test/built-ins/Proxy/defineProperty/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..ad5727ae0e509de22891bb424ef2f79607debe6f --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/return-is-abrupt.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Trap return is an abrupt. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 10. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, + descObj»)). + 11. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + defineProperty: function(t, prop, desc) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.defineProperty(p, "foo", {}); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js b/test/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..4c26d4c093d76e3f8b4304659260a49cf3a23cc5 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc is not configurable and target property + descriptor is configurable and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + b. If settingConfigFalse is true and targetDesc.[[Configurable]] is + true, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.defineProperty(target, "foo", { + value: 1, + configurable: true +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1, + configurable: false + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js new file mode 100644 index 0000000000000000000000000000000000000000..8617001c6cdaa2f6389bbb8f42b4278093f4b627 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc and target property descriptor are not + compatible and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc , + targetDesc) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.defineProperty(target, "foo", { + value: 1, + configurable: false +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1, + configurable: true + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..abc0c8665e5137877c14203c67f4673a82a3f596 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc and target property descriptor are not + compatible and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc , + targetDesc) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.defineProperty(target, "foo", { + value: 1 +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 2 + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..c9c6f05be6a44bdac02223cadc2b772932fdd935 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc is not configurable and target property + descriptor is undefined, and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 19. If targetDesc is undefined, then + ... + b. If settingConfigFalse is true, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + configurable: false + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..85df7c30aeaeb6d5711c834a7d3f9836d0fa5e3e --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc is not configurable and target is not + extensible, and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 19. If targetDesc is undefined, then + a. If extensibleTarget is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", {}); +}); diff --git a/test/built-ins/Proxy/defineProperty/trap-is-not-callable.js b/test/built-ins/Proxy/defineProperty/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..115605a860c272e466977a01225b8fdc0eb726e2 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/trap-is-not-callable.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if trap is not callable. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 6. Let trap be GetMethod(handler, "defineProperty"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: {} +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1 + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/trap-is-undefined.js b/test/built-ins/Proxy/defineProperty/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..a7578da92a3f2c3bb39aa3f5ca10702d2d8a85da --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/trap-is-undefined.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Return target.[[DefineOwnProperty]](P, Desc) if trap is undefined. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 8. If trap is undefined, then + a. Return target.[[DefineOwnProperty]](P, Desc). + ... +includes: [propertyHelper.js] +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +Object.defineProperty(p, "attr", { + configurable: true, + enumerable: true, + writable: true, + value: 1 +}); + +verifyEqualTo(target, "attr", 1); +verifyWritable(target, "attr"); +verifyEnumerable(target, "attr"); +verifyConfigurable(target, "attr"); + +Object.defineProperty(p, "attr", { + configurable: false, + enumerable: false, + writable: false, + value: 2 +}); + +verifyEqualTo(target, "attr", 2); +verifyNotWritable(target, "attr"); +verifyNotEnumerable(target, "attr"); +verifyNotConfigurable(target, "attr"); diff --git a/test/built-ins/Proxy/defineProperty/trap-return-is-false.js b/test/built-ins/Proxy/defineProperty/trap-return-is-false.js new file mode 100644 index 0000000000000000000000000000000000000000..3481dbb57bd7904aafebae0271f14c06f70e8616 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/trap-return-is-false.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Trap returns a boolean. Checking on false values. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 12. If booleanTrapResult is false, return false. + ... +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return 0; + } +}); + +assert.sameValue(Reflect.defineProperty(p, "attr", {}), false); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); diff --git a/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js new file mode 100644 index 0000000000000000000000000000000000000000..148a7b81af97996f8e5842ae23a310684157582b --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + The result is a Boolean value. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + deleteProperty: function() { + return 0; + } +}); + +Object.defineProperties(target, { + isConfigurable: { + value: 1, + configurable: true + }, + notConfigurable: { + value: 1, + configurable: false + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); +assert.sameValue(Reflect.deleteProperty(p, "isConfigurable"), false); +assert.sameValue(Reflect.deleteProperty(p, "notConfigurable"), false); diff --git a/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js new file mode 100644 index 0000000000000000000000000000000000000000..fe506f109e46ebd1b23f77d14119ed27fbb0f018 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + The result is a Boolean value. +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return 1; + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), true); diff --git a/test/built-ins/Proxy/deleteProperty/call-parameters.js b/test/built-ins/Proxy/deleteProperty/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..38a4f57fd9f2d374a5815e88adfd69d19d41c4d4 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/call-parameters.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). +info: > + 6.1.7.2 Object Internal Methods and Internal Slots + + (...) Receiver is used as the this value when evaluating the code +---*/ + +var _handler, _target, _prop; +var target = { + attr: 1 +}; +var handler = { + deleteProperty: function(t, prop) { + _handler = this; + _target = t; + _prop = prop; + return delete t[prop]; + } +}; +var p = new Proxy(target, handler); + +delete p.attr; + +assert.sameValue(_handler, handler, "handler object as the trap context"); +assert.sameValue(_target, target, "first argument is the target object"); +assert.sameValue(_prop, "attr", "second argument is the property name"); diff --git a/test/built-ins/Proxy/deleteProperty/null-handler.js b/test/built-ins/Proxy/deleteProperty/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..1b280f79ed2282c68c7fd88cd15fa4f69f0a79ae --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/null-handler.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 3. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({ + attr: 1 +}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + delete p.proxy.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/return-false-not-strict.js b/test/built-ins/Proxy/deleteProperty/return-false-not-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..c0785c90bf5f31a4ce1966f039e995f594ebd122 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/return-false-not-strict.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 11. If booleanTrapResult is false, return false. +flags: [noStrict] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return false; + } +}); + +assert.sameValue(delete p.attr, false); diff --git a/test/built-ins/Proxy/deleteProperty/return-false-strict.js b/test/built-ins/Proxy/deleteProperty/return-false-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..94d33a91e35c31ebe24c575c91f3f98f231969ac --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/return-false-strict.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 11. If booleanTrapResult is false, return false. +flags: [onlyStrict] +features: [Reflect] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return false; + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); diff --git a/test/built-ins/Proxy/deleteProperty/return-is-abrupt.js b/test/built-ins/Proxy/deleteProperty/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..7a37fc91f5b56256998d39e1e9fcccb7a2a56bad --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/return-is-abrupt.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + Trap return is an abrupt. +info: > + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + 10. ReturnIfAbrupt(booleanTrapResult). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + deleteProperty: function(t, prop) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + delete p.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js b/test/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..13af3bbc53be926fb220beb4cdcafb669cf2ad71 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + A property cannot be reported as deleted, if it exists as a non-configurable + own property of the target object. +info: > + 14. If targetDesc.[[Configurable]] is false, throw a TypeError exception. +---*/ + +var target = {}; +var p = new Proxy(target, { + deleteProperty: function() { + return true; + } +}); + +Object.defineProperty(target, "attr", { + configurable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js b/test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js new file mode 100644 index 0000000000000000000000000000000000000000..fc70773fa7df2ebe8c2b79642d1dc8bdbbec5b14 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 14. If targetDesc is undefined, return true. +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return true; + } +}); + +assert.sameValue(delete p.attr, true); diff --git a/test/built-ins/Proxy/deleteProperty/trap-is-not-callable.js b/test/built-ins/Proxy/deleteProperty/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..756e3103843b8482bba2c8f7974562ab92ea1cb6 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/trap-is-not-callable.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + Throws when trap is not callable. +info: > + 9.5.10 [[Delete]] (P) + + 6. Let trap be GetMethod(handler, "deleteProperty"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, { + deleteProperty: {} +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..3adf23123b344d719e2ee7cc53a8533701d76e60 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 8. If trap is undefined, then Return target.[[Delete]](P). +flags: [noStrict] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(delete p.attr, true); +assert.sameValue(delete p.notThere, true); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +assert.sameValue(delete p.attr, false); diff --git a/test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.js b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..070fba7f5ab91699c0fd352040ef99ab9ad48988 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.10 +description: > + [[Delete]] (P) + + 8. If trap is undefined, then Return target.[[Delete]](P). +flags: [onlyStrict] +features: [Reflect] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(delete p.attr, true); +assert.sameValue(delete p.notThere, true); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); diff --git a/test/built-ins/Proxy/enumerate/call-parameters.js b/test/built-ins/Proxy/enumerate/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..b87cbace43ff681d19af314507f1b8973470a202 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/call-parameters.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + Trap called as trap.call(handler, target) +info: > + [[Enumerate]] () + + 8. Let trapResult be Call(trap, handler, «target»). +---*/ + +var x, _target, _handler; +var target = { + attr: 1 +}; +var handler = { + enumerate: function(t) { + _target = t; + _handler = this; + } +}; +var p = new Proxy(target, handler); + +try { + for (x in p) {} +} catch(e) {} + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/enumerate/null-handler.js b/test/built-ins/Proxy/enumerate/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..de38e6622906b2eb084888cce9b43d6334ddcc14 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/null-handler.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + 2. If handler is null, throw a TypeError exception. +---*/ + +var x; +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + for (x in p.proxy) { + x; + } +}); diff --git a/test/built-ins/Proxy/enumerate/result-not-an-object-throws-boolean.js b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..05fcd28b9b8dea2312881b45e626ae1c800e54cf --- /dev/null +++ b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-boolean.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + The result must be an Object +---*/ + +var x; +var target = { + attr: 1 +}; +var p = new Proxy(target, { + enumerate: function() { + return true; + } +}); + +assert.throws(TypeError, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/result-not-an-object-throws-number.js b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-number.js new file mode 100644 index 0000000000000000000000000000000000000000..acd98fb004cc972d2688282c04a4dea5a955f071 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-number.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + The result must be an Object +---*/ + +var x; +var target = { + attr: 1 +}; +var p = new Proxy(target, { + enumerate: function() { + return 1; + } +}); + +assert.throws(TypeError, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/result-not-an-object-throws-string.js b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-string.js new file mode 100644 index 0000000000000000000000000000000000000000..71a63f9c7f00fe046f285660f99ec67415af99aa --- /dev/null +++ b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + The result must be an Object +---*/ + +var x; +var target = { + attr: 1 +}; +var p = new Proxy(target, { + enumerate: function() { + return ""; + } +}); + +assert.throws(TypeError, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/result-not-an-object-throws-symbol.js b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..f17559d24b8ab2611a6bca279c07801b22d6b5bc --- /dev/null +++ b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-symbol.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + The result must be an Object +features: [Symbol] +---*/ + +var x; +var target = { + attr: 1 +}; +var p = new Proxy(target, { + enumerate: function() { + return Symbol(); + } +}); + +assert.throws(TypeError, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/result-not-an-object-throws-undefined.js b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..6e0651ce984fd14e5e3460c033c642a8c0ad6296 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/result-not-an-object-throws-undefined.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + The result must be an Object +---*/ + +var x; +var target = { + attr: 1 +}; +var p = new Proxy(target, { + enumerate: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/return-is-abrupt.js b/test/built-ins/Proxy/enumerate/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..c5f55f473e65a493da4f51a01a642e4ddd59d258 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/return-is-abrupt.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + Trap returns abrupt. +info: > + [[Enumerate]] () + + 8. Let trapResult be Call(trap, handler, «target»). + 9. ReturnIfAbrupt(trapResult). +includes: [Test262Error.js] +---*/ + +var x; +var p = new Proxy({}, { + enumerate: function(t) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/return-trap-result-no-value.js b/test/built-ins/Proxy/enumerate/return-trap-result-no-value.js new file mode 100644 index 0000000000000000000000000000000000000000..208150d55dc4dda2e615da636a0c30e494ab1571 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/return-trap-result-no-value.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + Trap returns an iterator whose IteratorResult does not contain a value + property. +info: > + [[Enumerate]] () + + 11. Return trapResult +---*/ + +var x; +var p = new Proxy([1,2,3], { + enumerate: function(t) { + return {next: function() { return { done:true }; } }; + } +}); + +for (x in p) { + $ERROR("returned iterable interface from trap is flagged as done."); +} diff --git a/test/built-ins/Proxy/enumerate/return-trap-result.js b/test/built-ins/Proxy/enumerate/return-trap-result.js new file mode 100644 index 0000000000000000000000000000000000000000..7d4678def2373c943f69d340893ad942c22fa093 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/return-trap-result.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + Trap returns a iterable result. +info: > + [[Enumerate]] () + + 11. Return trapResult +includes: [compareArray.js] +---*/ + +var x; +var iter = [ + {done: false, value: 1}, + {done: false, value: 2}, + {done: false, value: 3}, + {done: true, value: 42} +]; +var target = { + attr: 1 +}; +var foo = { bar: 1 }; +var p = new Proxy(target, { + enumerate: function() { + return { next: function() { return iter.shift(); } }; + } +}); + +var results = []; +for (x in p) { + results.push(x); +} + +assert(compareArray(results, [1,2,3])); diff --git a/test/built-ins/Proxy/enumerate/trap-is-not-callable.js b/test/built-ins/Proxy/enumerate/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..1af02ef4c229f5c837126542023284afef7a2b90 --- /dev/null +++ b/test/built-ins/Proxy/enumerate/trap-is-not-callable.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + Trap is not callable. +info: > + [[Enumerate]] () + + 5. Let trap be GetMethod(handler, "enumerate"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var x; +var p = new Proxy({attr:1}, { + enumerate: {} +}); + +assert.throws(TypeError, function() { + for (x in p) {} +}); diff --git a/test/built-ins/Proxy/enumerate/trap-is-undefined.js b/test/built-ins/Proxy/enumerate/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..71efad48d20b68cc69cc78a5be840f6f1c2e221f --- /dev/null +++ b/test/built-ins/Proxy/enumerate/trap-is-undefined.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.11 +description: > + [[Enumerate]] () + + 7. If trap is undefined, then Return target.[[Enumerate]](). +---*/ + +var x; +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +var count = 0; +for (x in p) { + count++; +} + +assert.sameValue(count, 1); diff --git a/test/built-ins/Proxy/function-prototype.js b/test/built-ins/Proxy/function-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..e501f9160e626f0c998d9da20dc1a31be832fae4 --- /dev/null +++ b/test/built-ins/Proxy/function-prototype.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2 +description: > + The value of the [[Prototype]] internal slot of the Proxy + constructor is the intrinsic object %FunctionPrototype% (19.2.3). +---*/ + +assert.sameValue( + Object.getPrototypeOf(Proxy), + Function.prototype, + "`Object.getPrototypeOf(Proxy)` returns `Function.prototype`" +); diff --git a/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js b/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..15a3cebd1ba643e85964b4d2b1d0c4e5808a916b --- /dev/null +++ b/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + if trap result is not undefined, then proxy must report the same value for a + non-configurable accessor property with an undefined get. +info: > + 13. If targetDesc is not undefined, then + b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] + is false and targetDesc.[[Get]] is undefined, then + i. If trapResult is not undefined, throw a TypeError exception. + +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + get: undefined +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); diff --git a/test/built-ins/Proxy/get/call-parameters.js b/test/built-ins/Proxy/get/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..55f7e71fcf675221bb471390d0a6d1a08a25afab --- /dev/null +++ b/test/built-ins/Proxy/get/call-parameters.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). +info: > + 6.1.7.2 Object Internal Methods and Internal Slots + + (...) Receiver is used as the this value when evaluating the code +---*/ + +var _target, _handler, _prop, _receiver; +var target = { + attr: 1 +}; +var handler = { + get: function(t, prop, receiver) { + _handler = this; + _target = t; + _prop = prop; + _receiver = receiver; + } +}; +var p = new Proxy(target, handler); + +p.attr; + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); +assert.sameValue(_receiver, p, "receiver is the Proxy object"); + +_prop = null; +p["attr"]; +assert.sameValue( + _prop, "attr", + "trap is triggered both by p.attr and p['attr']" +); diff --git a/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js b/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..97eff7da68235b21ff2c4967126a11264218360d --- /dev/null +++ b/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Throws if proxy return has not the same value for a non-writable, + non-configurable property +info: > + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); diff --git a/test/built-ins/Proxy/get/null-handler.js b/test/built-ins/Proxy/get/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..82dc3a187c986cddee2587c9b1ac509a1160cbcd --- /dev/null +++ b/test/built-ins/Proxy/get/null-handler.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 2. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.attr; +}); + +assert.throws(TypeError, function() { + p.proxy['attr']; +}); diff --git a/test/built-ins/Proxy/get/return-is-abrupt.js b/test/built-ins/Proxy/get/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..ea6a7c4bb598c76684fd99f50679252ddedd7e21 --- /dev/null +++ b/test/built-ins/Proxy/get/return-is-abrupt.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Trap returns abrupt. +info: > + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). + 10. ReturnIfAbrupt(trapResult). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.attr; +}); + +assert.throws(Test262Error, function() { + p["attr"]; +}); diff --git a/test/built-ins/Proxy/get/return-trap-result-accessor-property.js b/test/built-ins/Proxy/get/return-trap-result-accessor-property.js new file mode 100644 index 0000000000000000000000000000000000000000..560bd56506f4d9492ee03af69faa309552578ffc --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-accessor-property.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + get: function() { + return 1; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js b/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js new file mode 100644 index 0000000000000000000000000000000000000000..46ddaeff0b3abf4bedf1d7efb9a8658edc3069cf --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: true, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js b/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..930265b6e6b39bd33dbcfe3e2e9a366a0e86b984 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + get: undefined +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js b/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js new file mode 100644 index 0000000000000000000000000000000000000000..1ad1eca0a657b2d67701ec6b97dad3c962d30c82 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js b/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js new file mode 100644 index 0000000000000000000000000000000000000000..bec57837e9cc1061be5c31e3740a7224f8e88117 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Proxy must report the same value for a non-writable, non-configurable + property. +info: > + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. + ... + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 1; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 1); +assert.sameValue(p['attr'], 1); diff --git a/test/built-ins/Proxy/get/return-trap-result.js b/test/built-ins/Proxy/get/return-trap-result.js new file mode 100644 index 0000000000000000000000000000000000000000..d045e1492763d02fb2db383123ddee8f9c60a009 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p.foo, 2); + +assert.sameValue(p['attr'], 2); +assert.sameValue(p['foo'], 2); diff --git a/test/built-ins/Proxy/get/trap-is-not-callable.js b/test/built-ins/Proxy/get/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..9ea5caed59563e3f854187f9399a693792bf184b --- /dev/null +++ b/test/built-ins/Proxy/get/trap-is-not-callable.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Trap is not callable. +info: > + [[Get]] (P, Receiver) + + 6. Let trap be GetMethod(handler, "get"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, { + get: {} +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p["attr"]; +}); diff --git a/test/built-ins/Proxy/get/trap-is-undefined-no-property.js b/test/built-ins/Proxy/get/trap-is-undefined-no-property.js new file mode 100644 index 0000000000000000000000000000000000000000..c9d107f5926b9996b76b2ed2cb8ea140ddee0811 --- /dev/null +++ b/test/built-ins/Proxy/get/trap-is-undefined-no-property.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); +assert.sameValue(p['attr'], 1, 'return target.attr'); +assert.sameValue(p['foo'], undefined, 'return target.foo'); diff --git a/test/built-ins/Proxy/get/trap-is-undefined.js b/test/built-ins/Proxy/get/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..4c2257aa612e4cea51c002276fe46eb7be9e3947 --- /dev/null +++ b/test/built-ins/Proxy/get/trap-is-undefined.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). + +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: undefined +}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/call-parameters.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..1e785ce64f3ff8bd30d59df5e899a1c5ccebe25c --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/call-parameters.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Trap is called with hander context and parameters are target and P +info: > + [[GetOwnProperty]] (P) + + ... + 9. Let trapResultObj be Call(trap, handler, «target, P»). + ... +---*/ + +var _target, _handler, _prop; +var target = {attr: 1}; +var handler = { + getOwnPropertyDescriptor: function(t, prop) { + _target = t; + _handler = this; + _prop = prop; + + return Object.getOwnPropertyDescriptor(t); + } +}; +var p = new Proxy(target, handler); + +Object.getOwnPropertyDescriptor(p, "attr"); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/null-handler.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..a908e072b849ba268fb54e6ad9f96390e141bb7a --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/null-handler.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p.proxy); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-target-is-not-extensible.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-target-is-not-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..ababda6b3e9b92b210732dcdcf987361b4598fb8 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-target-is-not-extensible.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is undefined and target is not + extensible +info: > + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + ... + e. If ToBoolean(extensibleTarget) is false, throw a TypeError exception. + ... +---*/ + +var target = { + foo: 1 +}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-not-configurable.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..fe88f63afc0e6130fdd6d9fe1c2a6f456edcc028 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-not-configurable.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is undefined and target property + descriptor is not configurable +info: > + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + ... + b. If targetDesc.[[Configurable]] is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +Object.defineProperty(target, "foo", { + configurable: false, + enumerable: false, + value: 1 +}); + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return; + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-undefined.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..814bbf587af42c5483af73384c5d557c4b856e0c --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is undefined and target property + descriptor is undefined. +info: > + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + a. If targetDesc is undefined, return undefined. + ... +---*/ + +var t = {}; +var trapped; +var p = new Proxy(t, { + getOwnPropertyDescriptor: function(target, prop) { + trapped = true; + return; + } +}); + +assert.sameValue( + Object.getOwnPropertyDescriptor(p, "attr"), + undefined +); + +assert(trapped); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..0153d6add7789a8511fe700abc90bbc19452cbbb --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return undefined if trap result is undefined and target is extensible and + the target property descriptor is configurable. +info: > + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + ... + f. Return undefined. + ... +---*/ + +var target = { + attr: 1 +}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return; + } +}); + +assert.sameValue(Object.getOwnPropertyDescriptor(p, "attr"), undefined); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..3c31c62c9633766903b80a7c2cfbe951c7e50a5d --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is neither Object nor Undefined +info: > + [[GetOwnProperty]] (P) + + ... + 11. If Type(trapResultObj) is neither Object nor Undefined, throw a + TypeError exception. + ... +features: [Symbol] +---*/ + +var target = { + number: 1, + symbol: Symbol(), + string: '', + boolean: true, + fn: function() {} +}; +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return t[prop]; + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "number"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "string"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "symbol"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "boolean"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "fn"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-invalid-descriptor.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-invalid-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..6d2396b1aa7d70f782b050eb1c8729ebb611edb4 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-invalid-descriptor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result and target property descriptors + are not compatible. +info: > + [[GetOwnProperty]] (P) + + ... + 20. Let valid be IsCompatiblePropertyDescriptor (extensibleTarget, + resultDesc, targetDesc). + 21. If valid is false, throw a TypeError exception. +---*/ + +var target = {}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + var foo = { bar: 1 }; + + return Object.getOwnPropertyDescriptor(foo, "bar"); + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "bar"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-configurable.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..85e4bd235c4d52ba9bb424f5fad5821a4b948f23 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-configurable.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is not configurable but target + property descriptor is configurable. +info: > + [[GetOwnProperty]] (P) + + ... + 22. If resultDesc.[[Configurable]] is false, then + a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, + then + i. Throw a TypeError exception. + ... +---*/ + +var target = { + bar: 1 +}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + var foo = {}; + + Object.defineProperty(foo, "bar", { + configurable: false, + enumerable: true, + value: 1 + }); + + return Object.getOwnPropertyDescriptor(foo, prop); + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "bar"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-undefined.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..357cc14a6606441937a5f45d1cd75599e92450ff --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-undefined.js @@ -0,0 +1,47 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is not configurable but target + property descriptor is undefined. +info: > + [[GetOwnProperty]] (P) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "getOwnPropertyDescriptor"). + ... + 9. Let trapResultObj be Call(trap, handler, «target, P»). + ... + 12. Let targetDesc be target.[[GetOwnProperty]](P). + ... + 17. Let resultDesc be ToPropertyDescriptor(trapResultObj). + ... + 22. If resultDesc.[[Configurable]] is false, then + a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, then + i. Throw a TypeError exception. + +---*/ + +var target = {}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + var foo = {}; + + Object.defineProperty(foo, "bar", { + configurable: false, + enumerable: true, + value: 1 + }); + + return Object.getOwnPropertyDescriptor(foo, prop); + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "bar"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-configurable.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..13f46ca31b7942c31fb053e1872e8893efb84150 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-configurable.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return descriptor from trap result if it has the same value as the target + property descriptor. +---*/ + +var target = {}; +var descriptor = { + configurable: true, + enumerable: true, + value: 1 +}; + +Object.defineProperty(target, "bar", descriptor); + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return Object.getOwnPropertyDescriptor(t, prop); + } +}); + +var proxyDesc = Object.getOwnPropertyDescriptor(p, "bar"); + +assert(proxyDesc.configurable); +assert(proxyDesc.enumerable); +assert.sameValue(proxyDesc.value, 1); +assert.sameValue(proxyDesc.writable, false); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-not-configurable.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..cc25cc694b2e2edc241fd39a12cf4fc393d3a4a3 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-not-configurable.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return descriptor from trap result if it has the same value as the target + property descriptor and they're not configurable. +---*/ + +var target = {}; + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return Object.getOwnPropertyDescriptor(t, prop); + } +}); + +var proxyDesc = Object.getOwnPropertyDescriptor(p, "attr"); + +assert.sameValue(proxyDesc.configurable, false); +assert(proxyDesc.enumerable); +assert.sameValue(proxyDesc.value, 1); +assert.sameValue(proxyDesc.writable, false); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/return-is-abrupt.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..c98e60bd099f3cee97848ac35293035e659458b5 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/return-is-abrupt.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Trap returns abrupt. +info: > + [[GetOwnProperty]] (P) + + ... + 9. Let trapResultObj be Call(trap, handler, «target, P»). + 10. ReturnIfAbrupt(trapResultObj). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + getOwnPropertyDescriptor: function(t, prop) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.getOwnPropertyDescriptor(p, "attr"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..5fc459e59b8b1d823838bb1befbd530ac188eca9 --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[GetOwnProperty]] (P) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "getOwnPropertyDescriptor"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + getOwnPropertyDescriptor: {} +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); diff --git a/test/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js b/test/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..7e2e472378ccefc91732f09d46761642a6f3040a --- /dev/null +++ b/test/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return target.[[GetOwnProperty]](P) if trap is undefined. +info: > + [[GetOwnProperty]] (P) + + ... + 8. If trap is undefined, then + a. Return target.[[GetOwnProperty]](P). + ... +includes: [propertyHelper.js] +---*/ + +var target = {attr: 1}; +var p = new Proxy(target, {}); + +var proxyDesc = Object.getOwnPropertyDescriptor(p, "attr"); + +verifyEqualTo(p, "attr", 1); +verifyWritable(p, "attr"); +verifyEnumerable(p, "attr"); +verifyConfigurable(p, "attr"); diff --git a/test/built-ins/Proxy/getPrototypeOf/call-parameters.js b/test/built-ins/Proxy/getPrototypeOf/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..8476b7c4aadb0517aad2b646150c0a54ab78868a --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/call-parameters.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Trap is called with handler as context and target as the first parameter. +info: > + [[GetPrototypeOf]] ( ) + + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + +---*/ + +var _handler, _target; +var target = {}; +var handler = { + getPrototypeOf: function(t) { + _handler = this; + _target = t; + return {}; + } +}; + +var p = new Proxy(target, handler); + +Object.getPrototypeOf(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js b/test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js new file mode 100644 index 0000000000000000000000000000000000000000..10ee96187e89ef4fac99eb5d35e96883610d9841 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Return trap result if it's an Object and target is extensible. +info: > + [[GetPrototypeOf]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 4. Let target be the value of the [[ProxyTarget]] internal slot of O. + 5. Let trap be GetMethod(handler, "getPrototypeOf"). + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + 11. Let extensibleTarget be IsExtensible(target). + 12. ReturnIfAbrupt(extensibleTarget). + 13. If extensibleTarget is true, return handlerProto. + ... + +---*/ + +var prot = { foo: 1 }; +var p = new Proxy({}, { + getPrototypeOf: function() { + return prot; + } +}); + +assert.sameValue(Object.getPrototypeOf(p), prot); diff --git a/test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js b/test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7a31e7fb9218a95628dbc2e15e2cfc97732c5a68 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throws a TypeError if the target is not extensible and the trap result is + not the same as the target.[[GetPrototypeOf]] result. +info: > + [[GetPrototypeOf]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 4. Let target be the value of the [[ProxyTarget]] internal slot of O. + 5. Let trap be GetMethod(handler, "getPrototypeOf"). + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + 11. Let extensibleTarget be IsExtensible(target). + ... + 14. Let targetProto be target.[[GetPrototypeOf]](). + 15. ReturnIfAbrupt(targetProto). + 16. If SameValue(handlerProto, targetProto) is false, throw a TypeError + exception. + ... +---*/ + +var target = Object.create({ foo: 1 }); + +var p = new Proxy(target, { + getPrototypeOf: function() { + return {}; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js b/test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js new file mode 100644 index 0000000000000000000000000000000000000000..c9143a014b6bab179b6d86befe273560c8cd8a9e --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Return trap result is target is not extensible, but trap result has the same + value as target.[[GetPrototypeOf]] result. +info: > + [[GetPrototypeOf]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 4. Let target be the value of the [[ProxyTarget]] internal slot of O. + 5. Let trap be GetMethod(handler, "getPrototypeOf"). + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + 11. Let extensibleTarget be IsExtensible(target). + ... + 14. Let targetProto be target.[[GetPrototypeOf]](). + ... + 17. Return handlerProto. + +---*/ + +var target = Object.create(Array.prototype); + +var p = new Proxy(target, { + getPrototypeOf: function() { + return Array.prototype; + } +}); + +Object.preventExtensions(target); + +assert.sameValue(Object.getPrototypeOf(p), Array.prototype); diff --git a/test/built-ins/Proxy/getPrototypeOf/null-handler.js b/test/built-ins/Proxy/getPrototypeOf/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..38c8e7e4934ac33c37ce757f14fdc96486bcdb1d --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/null-handler.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p.proxy); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js b/test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..88a46a7a436ee72e59b98ce857b8625f6826d2eb --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Trap returns abrupt. +info: > + 8. Let handlerProto be Call(trap, handler, «target»). + 9. ReturnIfAbrupt(handlerProto). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js b/test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..e6335e46a535a5aa4d9112a48c2f623bf42d8533 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throws if trap is not callable. +---*/ + +var p = new Proxy({}, { + getPrototypeOf: {} +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js b/test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..efa9dcd1009f05d163bb0697e957cb648b26bf50 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js @@ -0,0 +1,12 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Return target.[[GetPrototypeOf]]() if trap is undefined. +---*/ + +var target = Object.create(Array.prototype); +var p = new Proxy(target, {}); + +assert.sameValue(Object.getPrototypeOf(p), Array.prototype); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..c8c0543ba8310725e39bd360f496ec50ffc96e0e --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throw a TypeError exception if trap result is false. +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return false; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js new file mode 100644 index 0000000000000000000000000000000000000000..d0533f518ca2716667f44139f1e0c980b132d9a7 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throw a TypeError exception if trap result is a Number. +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return 0; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js new file mode 100644 index 0000000000000000000000000000000000000000..34bea0d5fc4b6629f1d4bd7e46bcc23625eeab9d --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + throw a TypeError exception if trap result is a String. +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return ""; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..9b47cf9a9f5a42446f53b0a1d92e24ac1a3e6cd6 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throw a TypeError exception if trap result is a Symbol. +features: [Symbol] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return Symbol(); + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8e5143d3d87bc3b6c31c3639dbe333b4f1ffd04e --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.1 +description: > + Throw a TypeError exception if trap result is undefined. +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); diff --git a/test/built-ins/Proxy/has/call-in.js b/test/built-ins/Proxy/has/call-in.js new file mode 100644 index 0000000000000000000000000000000000000000..380a3c1a2058cf1a844fe92588badb2d69e0c3c1 --- /dev/null +++ b/test/built-ins/Proxy/has/call-in.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + A `in` check trigger trap.call(handler, target, P); +info: > + [[HasProperty]] (P) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + ... +---*/ + +var _handler, _target, _prop; +var target = {}; +var handler = { + has: function(t, prop) { + _handler = this; + _target = t; + _prop = prop; + + return prop in t; + } +}; +var p = new Proxy(target, handler); + +"attr" in p; + +assert.sameValue(_handler, handler, "handler is context"); +assert.sameValue(_target, target, "target is the first parameter"); +assert.sameValue(_prop, "attr", "given prop is the second paramter"); diff --git a/test/built-ins/Proxy/has/call-object-create.js b/test/built-ins/Proxy/has/call-object-create.js new file mode 100644 index 0000000000000000000000000000000000000000..90f5199c8f08ada051cb5834360e84d3fec4b1dd --- /dev/null +++ b/test/built-ins/Proxy/has/call-object-create.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + `.. in Object.create(proxy)` triggers trap.call(handler, target, P); +info: > + [[HasProperty]] (P) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "has"). + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + ... +---*/ + +var _handler, _target, _prop; +var target = {}; +var handler = { + has: function(t, prop) { + _handler = this; + _target = t; + _prop = prop; + + return false; + } +}; +var p = new Proxy(target, handler); + +"attr" in Object.create(p); + +assert.sameValue(_handler, handler, "handler is context"); +assert.sameValue(_target, target, "target is the first parameter"); +assert.sameValue(_prop, "attr", "given prop is the second paramter"); diff --git a/test/built-ins/Proxy/has/call-with.js b/test/built-ins/Proxy/has/call-with.js new file mode 100644 index 0000000000000000000000000000000000000000..53f92ca6997d2daece8886ed4539b6e2ee2d6ef5 --- /dev/null +++ b/test/built-ins/Proxy/has/call-with.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + A `with` variable check trigger trap.call(handler, target, P); +info: > + [[HasProperty]] (P) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + ... +flags: [noStrict] +---*/ + +var _handler, _target, _prop; +var target = {}; +var handler = { + has: function(t, prop) { + _handler = this; + _target = t; + _prop = prop; + + return true; + } +}; +var p = new Proxy(target, handler); + +with (p) { + (attr); +} + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); diff --git a/test/built-ins/Proxy/has/null-handler-using-with.js b/test/built-ins/Proxy/has/null-handler-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..06bd4eaf0ec94a629b019af8171be06cd6cf8cc8 --- /dev/null +++ b/test/built-ins/Proxy/has/null-handler-using-with.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Throws a TypeError exception if handler is null. +flags: [noStrict] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + with (p.proxy) { + (attr); + } +}); diff --git a/test/built-ins/Proxy/has/null-handler.js b/test/built-ins/Proxy/has/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..90deca388baa1c2449a8368ce47723eee4979b84 --- /dev/null +++ b/test/built-ins/Proxy/has/null-handler.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + "attr" in p.proxy; +}); diff --git a/test/built-ins/Proxy/has/return-false-target-not-extensible-using-with.js b/test/built-ins/Proxy/has/return-false-target-not-extensible-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..6bc735aba5794a4f5f5e93a2ffa6a5b6889e7921 --- /dev/null +++ b/test/built-ins/Proxy/has/return-false-target-not-extensible-using-with.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + A property cannot be reported as non-existent, if it exists as an own + property of the target object and the target object is not extensible. +info: > + [[HasProperty]] (P) + + ... + 11. If booleanTrapResult is false, then + a. Let targetDesc be target.[[GetOwnProperty]](P). + b. ReturnIfAbrupt(targetDesc). + c. If targetDesc is not undefined, then + ... + ii. Let extensibleTarget be IsExtensible(target). + ... + iv. If extensibleTarget is false, throw a TypeError exception. + ... +flags: [noStrict] +---*/ + +var target = {}; +var handler = { + has: function(t, prop) { + return 0; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: true, + value: 1 +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + with (p) { + (attr); + } +}); diff --git a/test/built-ins/Proxy/has/return-false-target-not-extensible.js b/test/built-ins/Proxy/has/return-false-target-not-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..731e22d46a2726545d67ac29836573daa17ae43f --- /dev/null +++ b/test/built-ins/Proxy/has/return-false-target-not-extensible.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + A property cannot be reported as non-existent, if it exists as an own + property of the target object and the target object is not extensible. +info: > + [[HasProperty]] (P) + + ... + 11. If booleanTrapResult is false, then + a. Let targetDesc be target.[[GetOwnProperty]](P). + b. ReturnIfAbrupt(targetDesc). + c. If targetDesc is not undefined, then + ... + ii. Let extensibleTarget be IsExtensible(target). + ... + iv. If extensibleTarget is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var handler = { + has: function(t, prop) { + return 0; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: true, + value: 1 +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + "attr" in p; +}); diff --git a/test/built-ins/Proxy/has/return-false-target-prop-exists-using-with.js b/test/built-ins/Proxy/has/return-false-target-prop-exists-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..94f253acb164375e894ac5ddd9d96be071a21d16 --- /dev/null +++ b/test/built-ins/Proxy/has/return-false-target-prop-exists-using-with.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + The result of [[HasProperty]] is a Boolean value and will affect has + checkings. False returned when target property exists; +info: > + [[HasProperty]] (P) + + ... + 12. Return booleanTrapResult. +flags: [noStrict] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + has: function(t, prop) { + return false; + } +}); + +var attr = 0; +with (p) { + assert.sameValue(attr, 0); +} diff --git a/test/built-ins/Proxy/has/return-false-target-prop-exists.js b/test/built-ins/Proxy/has/return-false-target-prop-exists.js new file mode 100644 index 0000000000000000000000000000000000000000..eff332a66a37009a935c889870aef5eef4f87947 --- /dev/null +++ b/test/built-ins/Proxy/has/return-false-target-prop-exists.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + The result of [[HasProperty]] is a Boolean value and will affect has + checkings. False returned when target property exists; +info: > + [[HasProperty]] (P) + + ... + 12. Return booleanTrapResult. +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + has: function(t, prop) { + return false; + } +}); + +assert.sameValue(("attr" in p), false); diff --git a/test/built-ins/Proxy/has/return-false-targetdesc-not-configurable-using-with.js b/test/built-ins/Proxy/has/return-false-targetdesc-not-configurable-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..2ecf01cd6f0420daef9fae84726c4cb6438c0f47 --- /dev/null +++ b/test/built-ins/Proxy/has/return-false-targetdesc-not-configurable-using-with.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + A property cannot be reported as non-existent, if it exists as a + non-configurable own property of the target object. +info: > + [[HasProperty]] (P) + + ... + 11. If booleanTrapResult is false, then + ... + c. If targetDesc is not undefined, then + i. If targetDesc.[[Configurable]] is false, throw a TypeError + exception. + ... +flags: [noStrict] +---*/ + +var target = {}; +var handler = { + has: function(t, prop) { + return 0; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + with (p) { + (attr); + } +}); diff --git a/test/built-ins/Proxy/has/return-false-targetdesc-not-configurable.js b/test/built-ins/Proxy/has/return-false-targetdesc-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..dce7a6d3906af7060bd1e77e10e68a79b604ec8e --- /dev/null +++ b/test/built-ins/Proxy/has/return-false-targetdesc-not-configurable.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + A property cannot be reported as non-existent, if it exists as a + non-configurable own property of the target object. +info: > + [[HasProperty]] (P) + + ... + 11. If booleanTrapResult is false, then + ... + c. If targetDesc is not undefined, then + i. If targetDesc.[[Configurable]] is false, throw a TypeError + exception. + ... +---*/ + +var target = {}; +var handler = { + has: function(t, prop) { + return 0; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + "attr" in p; +}); diff --git a/test/built-ins/Proxy/has/return-is-abrupt-in.js b/test/built-ins/Proxy/has/return-is-abrupt-in.js new file mode 100644 index 0000000000000000000000000000000000000000..a9ae9f31ee116af0a5de63894acead9a951f0e8c --- /dev/null +++ b/test/built-ins/Proxy/has/return-is-abrupt-in.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Trap returns abrupt. Using `prop in obj`. +info: > + [[HasProperty]] (P) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + 10. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + has: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + "attr" in p; +}); diff --git a/test/built-ins/Proxy/has/return-is-abrupt-with.js b/test/built-ins/Proxy/has/return-is-abrupt-with.js new file mode 100644 index 0000000000000000000000000000000000000000..97ff469cd2ff4af2752427a846fca3635d2eae24 --- /dev/null +++ b/test/built-ins/Proxy/has/return-is-abrupt-with.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Trap returns abrupt. Using `with`. +info: > + [[HasProperty]] (P) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + 10. ReturnIfAbrupt(booleanTrapResult). + ... +flags: [noStrict] +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + has: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + with (p) { + (attr); + } +}); diff --git a/test/built-ins/Proxy/has/return-true-target-prop-exists-using-with.js b/test/built-ins/Proxy/has/return-true-target-prop-exists-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..145073b72022c4907be9e1f69974f8be928d2891 --- /dev/null +++ b/test/built-ins/Proxy/has/return-true-target-prop-exists-using-with.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + The result of [[HasProperty]] is a Boolean value and will affect has + checkings. True returned when target property exists; +flags: [noStrict] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + has: function(t, prop) { + if (prop !== "assert") { + return 42; + } + } +}); + +var attr = 0; +with (p) { + assert.sameValue(attr, 1); +} diff --git a/test/built-ins/Proxy/has/return-true-target-prop-exists.js b/test/built-ins/Proxy/has/return-true-target-prop-exists.js new file mode 100644 index 0000000000000000000000000000000000000000..9c5a409da6fd55bdbf09758a607c25b51d11ed00 --- /dev/null +++ b/test/built-ins/Proxy/has/return-true-target-prop-exists.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + The result of [[HasProperty]] is a Boolean value and will affect has + checkings. True returned when target property exists; +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + has: function(t, prop) { + return 1; + } +}); + +assert.sameValue(("attr" in p), true); diff --git a/test/built-ins/Proxy/has/return-true-without-same-target-prop.js b/test/built-ins/Proxy/has/return-true-without-same-target-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..9186074a7d2cc4640bc1d180c0ae9ac749a3bf6f --- /dev/null +++ b/test/built-ins/Proxy/has/return-true-without-same-target-prop.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + The result of [[HasProperty]] is a Boolean value and will affect has + checkings. True returned when target property doesn't exists; +---*/ + +var p = new Proxy({}, { + has: function(t, prop) { + return true; + } +}); + +assert.sameValue(("attr" in p), true); diff --git a/test/built-ins/Proxy/has/trap-is-not-callable-using-with.js b/test/built-ins/Proxy/has/trap-is-not-callable-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..ae837ea9e04b682e9bc11e0c41ace1f3efa46bf0 --- /dev/null +++ b/test/built-ins/Proxy/has/trap-is-not-callable-using-with.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[HasProperty]] (P) + + ... + 6. Let trap be GetMethod(handler, "has"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +flags: [noStrict] +---*/ + +var target = {}; +var p = new Proxy(target, { + has: {} +}); + +assert.throws(TypeError, function() { + with (p) { + (attr); + } +}); diff --git a/test/built-ins/Proxy/has/trap-is-not-callable.js b/test/built-ins/Proxy/has/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..7547fd398ca10a9922e25a2c4932b27f3d5dafa6 --- /dev/null +++ b/test/built-ins/Proxy/has/trap-is-not-callable.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[HasProperty]] (P) + + ... + 6. Let trap be GetMethod(handler, "has"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + has: {} +}); + +assert.throws(TypeError, function() { + "attr" in p; +}); diff --git a/test/built-ins/Proxy/has/trap-is-undefined-using-with.js b/test/built-ins/Proxy/has/trap-is-undefined-using-with.js new file mode 100644 index 0000000000000000000000000000000000000000..2bba67f3541c981962b1f7605b45927eee946e24 --- /dev/null +++ b/test/built-ins/Proxy/has/trap-is-undefined-using-with.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Return target.[[HasProperty]](P) if trap is undefined. +info: > + [[HasProperty]] (P) + + ... + 8. If trap is undefined, then + a. Return target.[[HasProperty]](P). + ... +flags: [noStrict] +---*/ + +var target = Object.create(Array.prototype); +var p = new Proxy(target, {}); + +var foo = 3; +with (target) { + assert.sameValue(length, 0); + assert.sameValue(foo, 3); +} diff --git a/test/built-ins/Proxy/has/trap-is-undefined.js b/test/built-ins/Proxy/has/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..1fa90717835c160dcaf1941e2c3d314f94f6a702 --- /dev/null +++ b/test/built-ins/Proxy/has/trap-is-undefined.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.7 +description: > + Return target.[[HasProperty]](P) if trap is undefined. +info: > + [[HasProperty]] (P) + + ... + 8. If trap is undefined, then + a. Return target.[[HasProperty]](P). + ... +---*/ + +var target = Object.create(Array.prototype); +var p = new Proxy(target, {}); + +assert.sameValue(("foo" in p), false); +assert.sameValue(("length" in p), true); diff --git a/test/built-ins/Proxy/isExtensible/call-parameters.js b/test/built-ins/Proxy/isExtensible/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..e2e5db3cc3d9a2c8cda8e76582a3b2db450329f6 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/call-parameters.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + The trap is called with handler on its context and the target object as the + first parabeter +info: > + [[IsExtensible]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + ... + +---*/ + +var _target, _handler; +var target = {}; +var handler = { + isExtensible: function(t) { + _handler = this; + _target = t; + return Object.isExtensible(t); + } +} +var p = new Proxy(target, handler); + +Object.isExtensible(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/isExtensible/null-handler.js b/test/built-ins/Proxy/isExtensible/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..d8d14bf7c86dca4ac46307628a1ee1537e93700c --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/null-handler.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + Throws a TypeError exception if handler is null +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.isExtensible(p.proxy); +}); diff --git a/test/built-ins/Proxy/isExtensible/return-is-abrupt.js b/test/built-ins/Proxy/isExtensible/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..d288dee824b71c238850278112aa0a1f8a440b78 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-is-abrupt.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + Trap returns abrupt. +info: > + [[IsExtensible]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + 9. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + isExtensible: function(t) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.isExtensible(p); +}); diff --git a/test/built-ins/Proxy/isExtensible/return-is-boolean.js b/test/built-ins/Proxy/isExtensible/return-is-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..29d54369ed8c51d644850898b20d07b61d07face --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-is-boolean.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + The trap returns a boolean result. +---*/ + +var target = {}; +var p = new Proxy(target, { + isExtensible: function(t) { + if ( Object.isExtensible(t) ) { + return 1; + } else { + return 0; + } + } +}); + +assert.sameValue(Object.isExtensible(p), true); + +Object.preventExtensions(target); + +assert.sameValue(Object.isExtensible(p), false); diff --git a/test/built-ins/Proxy/isExtensible/return-is-different-from-target.js b/test/built-ins/Proxy/isExtensible/return-is-different-from-target.js new file mode 100644 index 0000000000000000000000000000000000000000..9c5ee18c99312413bbee1560cedaa922a38916aa --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-is-different-from-target.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + Throws a TypeError exception if boolean trap result is not the same as + target.[[IsExtensible]]() result +info: > + [[IsExtensible]] ( ) + + ... + 12. If SameValue(booleanTrapResult, targetResult) is false, throw a + TypeError exception. + ... +---*/ + +var p = new Proxy({}, { + isExtensible: function(t) { + return false; + } +}); + +assert.throws(TypeError, function() { + Object.isExtensible(p); +}); diff --git a/test/built-ins/Proxy/isExtensible/return-same-result-from-target.js b/test/built-ins/Proxy/isExtensible/return-same-result-from-target.js new file mode 100644 index 0000000000000000000000000000000000000000..4858765c37643c0251f37eefb48335e637331819 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-same-result-from-target.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + Return trap result. +---*/ + +var target = {}; +var p = new Proxy(target, { + isExtensible: function(t) { + return Object.isExtensible(t); + } +}); + +assert.sameValue(Object.isExtensible(p), true); + +Object.preventExtensions(target); + +assert.sameValue(Object.isExtensible(p), false); diff --git a/test/built-ins/Proxy/isExtensible/trap-is-not-callable.js b/test/built-ins/Proxy/isExtensible/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..adca7938336a90e22d6d7020aed968b875054ea4 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/trap-is-not-callable.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[IsExtensible]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let trap be GetMethod(handler, "isExtensible"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + + +var target = {}; +var p = new Proxy(target, { + isExtensible: {} +}); + +assert.throws(TypeError, function() { + Object.isExtensible(p); +}); diff --git a/test/built-ins/Proxy/isExtensible/trap-is-undefined.js b/test/built-ins/Proxy/isExtensible/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..a69acac26ddfc5b68765123438f4d187f1064121 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/trap-is-undefined.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.3 +description: > + Return target.[[IsExtensible]]() if trap is undefined. +info: > + [[IsExtensible]] ( ) + + ... + 7. If trap is undefined, then + a. Return target.[[IsExtensible]](). + ... +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +assert.sameValue(Object.isExtensible(p), true); + +Object.preventExtensions(target); + +assert.sameValue(Object.isExtensible(p), false); diff --git a/test/built-ins/Proxy/length.js b/test/built-ins/Proxy/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6f3d21449435e628eaaef12a8356925e6c807e2f --- /dev/null +++ b/test/built-ins/Proxy/length.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2 +description: > + Properties of the Proxy Constructor + + Besides the length property (whose value is 2) + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Proxy.length, 2, "The value of `Proxy.length` is `2`"); + +verifyNotEnumerable(Proxy, "length"); +verifyNotWritable(Proxy, "length"); +verifyConfigurable(Proxy, "length"); diff --git a/test/built-ins/Proxy/name.js b/test/built-ins/Proxy/name.js new file mode 100644 index 0000000000000000000000000000000000000000..e081f7e1e3c88cd9f6733f6ddbeb84f0132dbe35 --- /dev/null +++ b/test/built-ins/Proxy/name.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.1.1 +description: > + Proxy ( target, handler ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Proxy.name, "Proxy", "The value of `Proxy.name` is `'Proxy'`"); + +verifyNotEnumerable(Proxy, "name"); +verifyNotWritable(Proxy, "name"); +verifyConfigurable(Proxy, "name"); diff --git a/test/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertynames.js b/test/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertynames.js new file mode 100644 index 0000000000000000000000000000000000000000..b7bde1412ef169c7f94c3d1eb39c03e647ead69d --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertynames.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + [[OwnPropertyKeys]] ( ) + + 8. Let trapResultArray be Call(trap, handler, «target»). +---*/ + +var _target, _handler; +var target = { + foo: 1, + bar: 2 +}; + +var handler = { + ownKeys: function(t) { + _handler = this; + _target = t; + return Object.getOwnPropertyNames(t); + } +} +var p = new Proxy(target, handler); + +var names = Object.getOwnPropertyNames(p); + +assert.sameValue(names[0], "foo"); +assert.sameValue(names[1], "bar"); +assert.sameValue(names.length, 2); +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js b/test/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js new file mode 100644 index 0000000000000000000000000000000000000000..39f3c7bd7585ee7167603c64ab2861b46e76aaa1 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + [[OwnPropertyKeys]] ( ) + + 8. Let trapResultArray be Call(trap, handler, «target»). +features: [Symbol] +---*/ + +var _target, _handler; +var target = {}; +var a = Symbol('a'); +var b = Symbol('b'); + +target[a] = 1; +target[b] = 2; + +var handler = { + ownKeys: function(t) { + _handler = this; + _target = t; + return Object.getOwnPropertySymbols(t); + } +} +var p = new Proxy(target, handler); + +var symbols = Object.getOwnPropertySymbols(p); + +assert.sameValue(symbols[0], a); +assert.sameValue(symbols[1], b); +assert.sameValue(symbols.length, 2); +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/ownKeys/call-parameters-object-keys.js b/test/built-ins/Proxy/ownKeys/call-parameters-object-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..0db31999b9ff551098cd335b4a4780b455311b93 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/call-parameters-object-keys.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + [[OwnPropertyKeys]] ( ) + + 8. Let trapResultArray be Call(trap, handler, «target»). +---*/ + +var _target, _handler; +var target = { + foo: 1, + bar: 2 +}; +var handler = { + ownKeys: function(t) { + _handler = this; + _target = t; + return Object.keys(t); + } +}; +var p = new Proxy(target, handler); + +var keys = Object.keys(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); +assert.sameValue(keys.length, 2); +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/ownKeys/extensible-return-trap-result-absent-not-configurable-keys.js b/test/built-ins/Proxy/ownKeys/extensible-return-trap-result-absent-not-configurable-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..c17002ebb08389b0488f818a13eda8fdad326cbe --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/extensible-return-trap-result-absent-not-configurable-keys.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + If target is extensible, return the non-falsy trap result if target doesn't + contain any non-configurable keys. +info: > + [[OwnPropertyKeys]] ( ) + + ... + 19. If extensibleTarget is true and targetNonconfigurableKeys is empty, then + a. Return trapResult. +---*/ + +var p = new Proxy({attr: 42}, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +var keys = Object.getOwnPropertyNames(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); diff --git a/test/built-ins/Proxy/ownKeys/extensible-return-trap-result.js b/test/built-ins/Proxy/ownKeys/extensible-return-trap-result.js new file mode 100644 index 0000000000000000000000000000000000000000..b99a3ad13d7f95d90be27abb2919899975ab1896 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/extensible-return-trap-result.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + If target is extensible, return the non-falsy trap result if it contains all + of target's non-configurable keys. +info: > + [[OwnPropertyKeys]] ( ) + + ... + 22. If extensibleTarget is true, return trapResult. +---*/ + +var target = {}; + +Object.defineProperty(target, "foo", { + configurable: false, + enumerable: true, + value: true +}); + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +var keys = Object.getOwnPropertyNames(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); diff --git a/test/built-ins/Proxy/ownKeys/not-extensible-missing-keys-throws.js b/test/built-ins/Proxy/ownKeys/not-extensible-missing-keys-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..6da38c0d8b245c807c52d5552f67273539aef45f --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/not-extensible-missing-keys-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + If target is not extensible, the result must contain all the keys of the own + properties of the target object. +info: > + [[OwnPropertyKeys]] ( ) + + ... + 23. Repeat, for each key that is an element of targetConfigurableKeys, + a. If key is not an element of uncheckedResultKeys, throw a TypeError + exception. +---*/ + +var target = { + foo: 1, + bar: 2 +}; + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo"]; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/not-extensible-new-keys-throws.js b/test/built-ins/Proxy/ownKeys/not-extensible-new-keys-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..d00c536f6690b123639fe414237a01f21f586075 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/not-extensible-new-keys-throws.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + If target is not extensible, the result can't contain keys names not + contained in the target object. +info: > + [[OwnPropertyKeys]] ( ) + + ... + 24. If uncheckedResultKeys is not empty, throw a TypeError exception. +---*/ + +var target = { + foo: 1 +}; + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/not-extensible-return-keys.js b/test/built-ins/Proxy/ownKeys/not-extensible-return-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..c1ad2af7deb2575a5d80a4692de22d5ff3b8ac28 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/not-extensible-return-keys.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + If target is not extensible, the result must contain all the keys of the own + properties of the target object and no other values +info: > + [[OwnPropertyKeys]] ( ) + + ... + 25. Return trapResult. +---*/ + +var target = { + foo: 1, + bar: 2 +}; + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +Object.preventExtensions(target); + +var keys = Object.keys(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); diff --git a/test/built-ins/Proxy/ownKeys/null-handler.js b/test/built-ins/Proxy/ownKeys/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..91e1b224ac952b725b9ea5b92d935015f5ddf95e --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/null-handler.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + [[OwnPropertyKeys]] ( ) + + 2. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.keys(p.proxy); +}); diff --git a/test/built-ins/Proxy/ownKeys/return-all-non-configurable-keys.js b/test/built-ins/Proxy/ownKeys/return-all-non-configurable-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..a8e4e9958ac868164867e7102bf42907460c6ed5 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/return-all-non-configurable-keys.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + The result List must contain the keys of all non-configurable own properties + of the target object. +info: > + [[OwnPropertyKeys]] ( ) + + ... + 21. Repeat, for each key that is an element of targetNonconfigurableKeys, + a. If key is not an element of uncheckedResultKeys, throw a TypeError + exception. +---*/ + +var target = { + foo: 1 +}; + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: true +}); + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo"]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/return-is-abrupt.js b/test/built-ins/Proxy/ownKeys/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..a95adc4111a96865fae2e49bfae90aacbee4b342 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/return-is-abrupt.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + Trap returns abrupt. +info: > + [[OwnPropertyKeys]] ( ) + + ... + 8. Let trapResultArray be Call(trap, handler, «target»). + 9. Let trapResult be CreateListFromArrayLike(trapResultArray, «â€String, Symbol»). + 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) + + 1. ReturnIfAbrupt(obj). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/return-not-list-object-throws.js b/test/built-ins/Proxy/ownKeys/return-not-list-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..147b0b05d6ece65568d7cc9ddd809c925eb15c7e --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/return-not-list-object-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + If return is not a list object, throw a TypeError exception +info: > + [[OwnPropertyKeys]] ( ) + + 8. Let trapResultArray be Call(trap, handler, «target»). + 9. Let trapResult be CreateListFromArrayLike(trapResultArray, «â€String, + Symbol»). + ... + 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) + 3. If Type(obj) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var target = {}; +var p = new Proxy(target, { + ownKeys: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/trap-is-not-callable.js b/test/built-ins/Proxy/ownKeys/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..417b675d1be749ac60736d96677d1ec5a238264d --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/trap-is-not-callable.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + Trap is not callable. +info: > + [[OwnPropertyKeys]] ( ) + + 5. Let trap be GetMethod(handler, "ownKeys"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({attr:1}, { + ownKeys: {} +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/trap-is-undefined.js b/test/built-ins/Proxy/ownKeys/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..ec95ac21b87c8b1a9770ffeb02d604833f8fb8df --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/trap-is-undefined.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.12 +description: > + [[OwnPropertyKeys]] ( ) + + 7. If trap is undefined, then Return target.[[OwnPropertyKeys]]() +---*/ + +var target = { + foo: 1, + bar: 2 +}; +var p = new Proxy(target, {}); + +var keys = Object.keys(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); diff --git a/test/built-ins/Proxy/preventExtensions/call-parameters.js b/test/built-ins/Proxy/preventExtensions/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..16007d3980d31360620908525f4dba3cf91798ed --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/call-parameters.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Trap is called with handler on its context and target as the first + parameter. +info: > + [[PreventExtensions]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + ... +---*/ + +var _target, _handler; +var target = {}; +var handler = { + preventExtensions: function(t) { + _handler = this; + _target = t; + + return Object.preventExtensions(target); + } +}; +var p = new Proxy(target, handler); + +Object.preventExtensions(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/preventExtensions/null-handler.js b/test/built-ins/Proxy/preventExtensions/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..12b7ee8657c554fbcb607ed49187f78d56b7ee95 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/null-handler.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.preventExtensions(p.proxy); +}); diff --git a/test/built-ins/Proxy/preventExtensions/return-false.js b/test/built-ins/Proxy/preventExtensions/return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..c448d70e80e5aab0fd28a8a2078667cece326b9e --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-false.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + If boolean trap result if false, return false. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy({}, { + preventExtensions: function(t) { + return 0; + } +}); + +assert.sameValue(Reflect.preventExtensions(p), false); + +Object.preventExtensions(target); + +assert.sameValue(Reflect.preventExtensions(p), false); diff --git a/test/built-ins/Proxy/preventExtensions/return-is-abrupt.js b/test/built-ins/Proxy/preventExtensions/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..8daf7b318735963d1cecadde79eba732ec83bcf5 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-is-abrupt.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Trap returns abrupt. +info: > + [[PreventExtensions]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + 9. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + preventExtensions: function(t) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js b/test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..7676c139f1cf8b5579b2e28362bc765a9036e0a2 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Throws a TypeError exception if boolean trap result is true and target is + extensible. +info: > + [[PreventExtensions]] ( ) + + ... + 10. If booleanTrapResult is true, then + ... + c. If targetIsExtensible is true, throw a TypeError exception. + 11. Return booleanTrapResult. + ... +---*/ + +var p = new Proxy({}, { + preventExtensions: function(t) { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js b/test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..14143824f490c05baaec8484759f093487565b25 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Return boolean trap result if its true and target is not extensible. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + preventExtensions: function(t) { + return 1; + } +}); + +Object.preventExtensions(target); + +assert(Reflect.preventExtensions(p)); diff --git a/test/built-ins/Proxy/preventExtensions/trap-is-not-callable.js b/test/built-ins/Proxy/preventExtensions/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..77e2966ee67f484e2ab57df27196b9fc752ab88a --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/trap-is-not-callable.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[PreventExtensions]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let trap be GetMethod(handler, "preventExtensions"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + preventExtensions: {} +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Proxy/preventExtensions/trap-is-undefined.js b/test/built-ins/Proxy/preventExtensions/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..0cd82e501b4833d8f1f4163dd6244c49b4c2bf44 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/trap-is-undefined.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.4 +description: > + Return target.[[PreventExtensions]]() if target is undefined. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +assert.sameValue(Reflect.preventExtensions(p), true); diff --git a/test/built-ins/Proxy/proxy-newtarget.js b/test/built-ins/Proxy/proxy-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..2c1ef6f6f9360ee16c58c269d7d80d6c4e91ac30 --- /dev/null +++ b/test/built-ins/Proxy/proxy-newtarget.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.1.1 +description: > + Proxy ( target, handler ) + + When Proxy is called with arguments target and handler performs + the following steps: + + ... + 2. Return ProxyCreate(target, handler). (9.5.15) + ... + 9.5.15 ProxyCreate(target, handler) + ... + 5. Let P be a newly created object. + ... + 10. Return P. + +---*/ + +var p1 = new Proxy({}, {}); + +assert.sameValue( + typeof p1, + 'object', + 'Return a newly created Object' +); \ No newline at end of file diff --git a/test/built-ins/Proxy/proxy-no-prototype.js b/test/built-ins/Proxy/proxy-no-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..027a2a8b4771d8e389dced6efdbe9c6404a48dbf --- /dev/null +++ b/test/built-ins/Proxy/proxy-no-prototype.js @@ -0,0 +1,11 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2 +description: > + The Proxy constructor does not have a prototype property because + proxy exotic objects do not have a [[Prototype]] internal slot + that requires initialization. +---*/ + +assert.sameValue(Object.hasOwnProperty.call(Proxy, 'prototype'), false); diff --git a/test/built-ins/Proxy/proxy-undefined-newtarget.js b/test/built-ins/Proxy/proxy-undefined-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..add91caf8eff67c502edbb60a4eb2c586d72b2b0 --- /dev/null +++ b/test/built-ins/Proxy/proxy-undefined-newtarget.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.1.1 +description: > + Proxy ( target, handler ) + + When Proxy is called with arguments target and handler performs + the following steps: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + Proxy(); +}); + +assert.throws(TypeError, function() { + Proxy([]); +}); diff --git a/test/built-ins/Proxy/proxy.js b/test/built-ins/Proxy/proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..0ec873338db7a5f0861b18038ce6489ab3a7e5e3 --- /dev/null +++ b/test/built-ins/Proxy/proxy.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.1.1 +description: > + Proxy ( target, handler ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, "Proxy"); +verifyWritable(this, "Proxy"); +verifyConfigurable(this, "Proxy"); diff --git a/test/built-ins/Proxy/revocable/proxy.js b/test/built-ins/Proxy/revocable/proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..81a0bf54d9c307442aacdfbea93d5e4894f2efc2 --- /dev/null +++ b/test/built-ins/Proxy/revocable/proxy.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2.1 +description: > + The returned object has a proxy property which is the created Proxy object + built with the given target and handler given parameters. +info: > + Proxy.revocable ( target, handler ) + + 6. Perform CreateDataProperty(result, "proxy", p). +---*/ + +var target = { + attr: "foo" +}; +var r = Proxy.revocable(target, { + get: function(t, prop) { + return t[prop] + "!"; + } +}); + +assert.sameValue(r.proxy.attr, "foo!"); diff --git a/test/built-ins/Proxy/revocable/revoke-consecutive-call-returns-undefined.js b/test/built-ins/Proxy/revocable/revoke-consecutive-call-returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..2d54d9d71b766357960f731f63f0cbe77d9f3813 --- /dev/null +++ b/test/built-ins/Proxy/revocable/revoke-consecutive-call-returns-undefined.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2.1.1 +description: > + Calling the revoked function again will return undefined +info: > + Proxy Revocation Functions + + ... + 1. Let p be the value of F’s [[RevocableProxy]] internal slot. + 2. If p is null, return undefined. +---*/ + +var r = Proxy.revocable({}, {}); + +r.revoke(); + +assert.sameValue(r.revoke(), undefined); diff --git a/test/built-ins/Proxy/revocable/revoke-returns-undefined.js b/test/built-ins/Proxy/revocable/revoke-returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..746916aabc5a0298c87ce45b4e223c2eb948f72d --- /dev/null +++ b/test/built-ins/Proxy/revocable/revoke-returns-undefined.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2.1.1 +description: > + Calling the revoked function returns undefined +info: > + Proxy Revocation Functions + + ... + 7. Return undefined. +---*/ + +var r = Proxy.revocable({}, {}); + +assert.sameValue(r.revoke(), undefined); diff --git a/test/built-ins/Proxy/revocable/revoke.js b/test/built-ins/Proxy/revocable/revoke.js new file mode 100644 index 0000000000000000000000000000000000000000..a39472d2bf4c661ec0d56fa2cefe728918f0e3aa --- /dev/null +++ b/test/built-ins/Proxy/revocable/revoke.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.2.2.1 +description: > + The returned object has a `revoked` property which is a function +info: > + Proxy.revocable ( target, handler ) + + 7. Perform CreateDataProperty(result, "revoke", revoker). +---*/ + +var r = Proxy.revocable({}, {}); + +assert.sameValue(typeof r.revoke, "function"); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-boolean-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-boolean-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..0e7100cfc86a26e70132f8705b54ffde13bbbbb0 --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-boolean-return-false.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return false; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-null-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-null-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..c6ca59a13560b36a49428f3fe74808aaeda5dbd5 --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-null-return-false.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return null; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-number-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-number-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..58380a602dfd06bd4c1d851a5d1ffc6d1897a41c --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-number-return-false.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return 0; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-string-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-string-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..9d3783668e2814711e23debd8cbb7abdc3106a7c --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-string-return-false.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return ""; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-undefined-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-undefined-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..3d05404a976b6b817a742f24100ae90eed672122 --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-undefined-return-false.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return undefined; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/call-parameters.js b/test/built-ins/Proxy/set/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..812333e9242bb210f89358855a9439c7939332e9 --- /dev/null +++ b/test/built-ins/Proxy/set/call-parameters.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, + Receiver»)). + +---*/ + +var _target, _handler, _prop, _value, _receiver; +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + _handler = this; + _target = t; + _prop = prop; + _value = value; + _receiver = receiver; + return t[prop] = value; + } +}; +var p = new Proxy(target, handler); + +p.attr = "foo"; + +assert.sameValue(_handler, handler, "handler object as the trap context"); +assert.sameValue(_target, target, "first argument is the target object"); +assert.sameValue(_prop, "attr", "second argument is the property name"); +assert.sameValue(_value, "foo", "third argument is the new value"); +assert.sameValue(_receiver, p, "forth argument is the proxy object"); diff --git a/test/built-ins/Proxy/set/null-handler.js b/test/built-ins/Proxy/set/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..3b2035085840b1916f8138b6e3a01aba809651bf --- /dev/null +++ b/test/built-ins/Proxy/set/null-handler.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 3. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.attr = 1; +}); + +assert.throws(TypeError, function() { + p.proxy['attr'] = 1; +}); diff --git a/test/built-ins/Proxy/set/return-is-abrupt.js b/test/built-ins/Proxy/set/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..d4be173fb68477d3ac774d29027aa3a72aae587b --- /dev/null +++ b/test/built-ins/Proxy/set/return-is-abrupt.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + Trap returns abrupt. +info: > + [[Set]] ( P, V, Receiver) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, Receiver»)). + 10. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + set: function(t, prop, value, receiver) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.attr = "bar"; +}); + +assert.throws(Test262Error, function() { + p["attr"] = "bar"; +}); diff --git a/test/built-ins/Proxy/set/return-true-target-property-accessor-is-configurable-set-is-undefined.js b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-configurable-set-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..11f35638737664c9968e625bcc5158f25e053f0d --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-configurable-set-is-undefined.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property accessor is + configurable and set is undefined. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: true, + set: undefined +}); + +assert(Reflect.set(p, "attr", "bar")); diff --git a/test/built-ins/Proxy/set/return-true-target-property-accessor-is-not-configurable.js b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..0277b54c18a43da5f796c559906acbb2e09125ce --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-not-configurable.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property accessor is not + configurable and set is not undefined. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + set: function( value ) { + return value; + } +}); + +assert(Reflect.set(p, "attr", 1)); diff --git a/test/built-ins/Proxy/set/return-true-target-property-is-not-configurable.js b/test/built-ins/Proxy/set/return-true-target-property-is-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..0bd1f6328dc68c78cc17da191e0d860b55fcff7e --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-is-not-configurable.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property is not configurable + but writable. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: true, + value: 'foo' +}); + +assert(Reflect.set(p, "attr", 1)); diff --git a/test/built-ins/Proxy/set/return-true-target-property-is-not-writable.js b/test/built-ins/Proxy/set/return-true-target-property-is-not-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..314d164ef0827b2a0bcd3001ea5dfa529473f752 --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-is-not-writable.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property is configurable + but not writable. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: true, + writable: false, + value: "foo" +}); + +assert(Reflect.set(p, "attr", "foo")); diff --git a/test/built-ins/Proxy/set/target-property-is-accessor-not-configurable-set-is-undefined.js b/test/built-ins/Proxy/set/target-property-is-accessor-not-configurable-set-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..32075bce31c89dcf84db4a76acec6b5dca3d3e8f --- /dev/null +++ b/test/built-ins/Proxy/set/target-property-is-accessor-not-configurable-set-is-undefined.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + Throws a TypeError when target property is an accessor not configurable and + and set is undefined. +info: > + 14. If targetDesc is not undefined, then + b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] is false, then + i. If targetDesc.[[Set]] is undefined, throw a TypeError exception. + +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + set: undefined +}); + +assert.throws(TypeError, function() { + p.attr = 'bar'; +}); + +assert.throws(TypeError, function() { + p['attr'] = 'bar'; +}); diff --git a/test/built-ins/Proxy/set/target-property-is-not-configurable-not-writable-not-equal-to-v.js b/test/built-ins/Proxy/set/target-property-is-not-configurable-not-writable-not-equal-to-v.js new file mode 100644 index 0000000000000000000000000000000000000000..4b1a9f919d713af34d35ec9e9cc049fd513d298e --- /dev/null +++ b/test/built-ins/Proxy/set/target-property-is-not-configurable-not-writable-not-equal-to-v.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + Throws a TypeError when target property is not configurable neither writable + and its value is not strictly equal to V. +info: > + 14. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(V, targetDesc.[[Value]]) is false, throw a TypeError + exception. +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 'foo' +}); + +assert.throws(TypeError, function() { + p.attr = 'bar'; +}); + +assert.throws(TypeError, function() { + p['attr'] = 'bar'; +}); diff --git a/test/built-ins/Proxy/set/trap-is-not-callable.js b/test/built-ins/Proxy/set/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..fb044e5be9770d6599e8d748422af82b470dfd48 --- /dev/null +++ b/test/built-ins/Proxy/set/trap-is-not-callable.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + Trap is not callable. +info: > + [[Set]] ( P, V, Receiver) + + 6. Let trap be GetMethod(handler, "set"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, { + set: {} +}); + +assert.throws(TypeError, function() { + p.attr = 1; +}); + +assert.throws(TypeError, function() { + p["attr"] = 1; +}); diff --git a/test/built-ins/Proxy/set/trap-is-undefined-no-property.js b/test/built-ins/Proxy/set/trap-is-undefined-no-property.js new file mode 100644 index 0000000000000000000000000000000000000000..f0b29b0ff8f8418b365fc0a1f3f72d4e36b6e3b6 --- /dev/null +++ b/test/built-ins/Proxy/set/trap-is-undefined-no-property.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 8. If trap is undefined, then return target.[[Set]](P, V, Receiver). + +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +p.attr = 2; + +assert.sameValue(target.attr, 2); diff --git a/test/built-ins/Proxy/set/trap-is-undefined.js b/test/built-ins/Proxy/set/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..82399fa34328ae0e7dd064e40584e0939812bd21 --- /dev/null +++ b/test/built-ins/Proxy/set/trap-is-undefined.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.9 +description: > + [[Set]] ( P, V, Receiver) + + 8. If trap is undefined, then return target.[[Set]](P, V, Receiver). + +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: undefined +}); + +p.attr = 1; + +assert.sameValue(target.attr, 1); diff --git a/test/built-ins/Proxy/setPrototypeOf/boolean-trap-result-extensible-target.js b/test/built-ins/Proxy/setPrototypeOf/boolean-trap-result-extensible-target.js new file mode 100644 index 0000000000000000000000000000000000000000..6365345c489f29ea2f94d8e3c80ecb1092e55f6f --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/boolean-trap-result-extensible-target.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Return a boolean trap result if target is extensible. +info: > + [[SetPrototypeOf]] (V) + + ... + 13. If extensibleTarget is true, return booleanTrapResult. + ... +flags: [onlyStrict] +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return v.attr; + } +}); + +var result = Reflect.setPrototypeOf(p, { attr: 0 }); +assert.sameValue(result, false); + +result = Reflect.setPrototypeOf(p, { attr: 1 }); +assert.sameValue(result, true); diff --git a/test/built-ins/Proxy/setPrototypeOf/call-parameters.js b/test/built-ins/Proxy/setPrototypeOf/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..e62aa54869e75343e818e29ec9c2241b5e115ce9 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/call-parameters.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Trap is called with handler on its context, first parameter is target and + second parameter is the given value. +info: > + [[SetPrototypeOf]] (V) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). + ... +---*/ + +var _handler, _target, _value; +var target = {}; +var val = {foo: 1}; +var handler = { + setPrototypeOf: function(t, v) { + _handler = this; + _target = t; + _value = v; + + Object.setPrototypeOf(t, v); + + return true; + } +}; +var p = new Proxy(target, handler); + +Object.setPrototypeOf(p, val); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_value, val); diff --git a/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-not-same-target-prototype.js b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-not-same-target-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..8d015b8703a87de83ece783ae07261a90bc0c312 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-not-same-target-prototype.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Throws a TypeError exception if boolean trap result is true, target is + not extensible, and the given parameter is not the same object as the target + prototype. +info: > + [[SetPrototypeOf]] (V) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "setPrototypeOf"). + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). + 14. Let targetProto be target.[[GetPrototypeOf]](). + 15. ReturnIfAbrupt(targetProto). + 16. If booleanTrapResult is true and SameValue(V, targetProto) is false, + throw a TypeError exception. + ... + +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return true; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(p, {}); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-same-target-prototype.js b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-same-target-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..8af42c56a3f1ab025eab14e79f6c49027e9e0492 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-same-target-prototype.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Return true if boolean trap result is true, target is not extensible, and + given parameter is the same as target prototype. +features: [Reflect] +---*/ + +var target = Object.create(Array.prototype); +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return true; + } +}); + +Object.preventExtensions(target); + +assert(Reflect.setPrototypeOf(p, Array.prototype)); diff --git a/test/built-ins/Proxy/setPrototypeOf/not-extensible-trap-is-false-return-false.js b/test/built-ins/Proxy/setPrototypeOf/not-extensible-trap-is-false-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..59a26338793ec0ef9300cfe1a4337dc3e086e52c --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/not-extensible-trap-is-false-return-false.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Return false if boolean trap result is false. +features: [Reflect] +---*/ + +var target = []; +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return false; + } +}); + +Object.preventExtensions(target); + +assert.sameValue(Reflect.setPrototypeOf(p, {}), false); diff --git a/test/built-ins/Proxy/setPrototypeOf/null-handler.js b/test/built-ins/Proxy/setPrototypeOf/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..4d4a7a6b6897b0b7836cda3efdfe2ad47342b9ef --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/null-handler.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Throws a TypeError exception if handler is null +---*/ + +var p = Proxy.revocable({},{}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(p.proxy, {}); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/return-is-abrupt.js b/test/built-ins/Proxy/setPrototypeOf/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..9675507370d72781ec36785417236835f7c2ab90 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/return-is-abrupt.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Trap returns abrupt. +info: > + [[SetPrototypeOf]] (V) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). + 10. ReturnIfAbrupt(booleanTrapResult). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + setPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.setPrototypeOf(p, {value: 1}); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/trap-is-not-callable.js b/test/built-ins/Proxy/setPrototypeOf/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..a6e77ed1238e36eb341177407c6d74e4bee14019 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/trap-is-not-callable.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[SetPrototypeOf]] (V) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "setPrototypeOf"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: {} +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(p, { + value: 1 + }); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/trap-is-undefined.js b/test/built-ins/Proxy/setPrototypeOf/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..1dc0ef324f2882c110754a0976e9f2fdef5f013e --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/trap-is-undefined.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.2 +description: > + Return target.[[SetPrototypeOf]] (V) if trap is undefined. +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +Object.setPrototypeOf(p, {attr: 1}); + +assert.sameValue(target.attr, 1);