diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Proxy/defineProperty | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/defineProperty')
26 files changed, 921 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/browser.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/call-parameters.js new file mode 100644 index 0000000000..2675515d04 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/call-parameters.js @@ -0,0 +1,55 @@ +// 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»)). + ... +features: [Proxy] +---*/ + +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/desc-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/desc-realm.js new file mode 100644 index 0000000000..1e74848fd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/desc-realm.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Property descriptor object is created in the Realm of the current execution + context +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 8. Let descObj be FromPropertyDescriptor(Desc). + 9. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P, + descObj »)). + ... + + 6.2.4.4 FromPropertyDescriptor + + ... + 2. Let obj be ObjectCreate(%ObjectPrototype%). + ... + 11. Return obj. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var desc; +var p = new OProxy({}, { + defineProperty: function(_, __, _desc) { + desc = _desc; + return desc; + } +}); + +p.a = 0; + +assert.sameValue(Object.getPrototypeOf(desc), Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/null-handler-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/null-handler-realm.js new file mode 100644 index 0000000000..d3eccc12a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/null-handler-realm.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throws a TypeError exception if handler is null (honoring the realm of the + current execution context). +info: | + 1. Assert: IsPropertyKey(P) is true. + 2. Let handler be O.[[ProxyHandler]]. + 3. If handler is null, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = OProxy.revocable(Object.create(null), {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.prop = null; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/null-handler.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/null-handler.js new file mode 100644 index 0000000000..7954d60a79 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/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.6 +description: > + Throws a TypeError exception if handler is null. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.defineProperty(p.proxy, "foo", { + configurable: true, + enumerable: true + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js new file mode 100644 index 0000000000..51d25a03fa --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/return-boolean-and-define-target.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.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: [Proxy, 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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/return-is-abrupt.js new file mode 100644 index 0000000000..bec126df89 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/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.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). + ... +features: [Proxy] +---*/ + +var p = new Proxy({}, { + defineProperty: function(t, prop, desc) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.defineProperty(p, "foo", {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/shell.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable-realm.js new file mode 100644 index 0000000000..de3242c184 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable-realm.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throw a TypeError exception if Desc is not configurable and target property + descriptor is configurable and trap result is true (honoring the realm of + the current execution context). +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + b. If settingConfigFalse is true and targetDesc.[[Configurable]] is + true, throw a TypeError exception. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var target = Object.create(null); +var p = new OProxy(target, { + defineProperty: function() { + return true; + } +}); + +Object.defineProperty(target, 'prop', { + value: 1, + configurable: true +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, 'prop', { + value: 1, + configurable: false + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js new file mode 100644 index 0000000000..1e5a27273d --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.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.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. + ... +features: [Proxy] +---*/ + +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 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target-realm.js new file mode 100644 index 0000000000..7daad2f400 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target-realm.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +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. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var target = Object.create(null); +var p = new OProxy(target, { + defineProperty: function() { + return true; + } +}); + +Object.defineProperty(target, 'prop', { + value: 1, + configurable: false +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, 'prop', { + value: 1, + configurable: true + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js new file mode 100644 index 0000000000..c23e63cd9f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.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.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. + ... +features: [Proxy] +---*/ + +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 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-realm.js new file mode 100644 index 0000000000..4d88618de6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-realm.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throw a TypeError exception if Desc and target property descriptor are not + compatible and trap result is true (honoring the realm of the current + execution context). +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc , + targetDesc) is false, throw a TypeError exception. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var target = Object.create(null); +var p = new OProxy(target, { + defineProperty: function() { + return true; + } +}); + +Object.defineProperty(target, 'prop', { + value: 1 +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, 'prop', { + value: 2 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js new file mode 100644 index 0000000000..bfa5fb2d32 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.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.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. + ... +features: [Proxy] +---*/ + +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 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-configurable-writable-desc-not-writable.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-configurable-writable-desc-not-writable.js new file mode 100644 index 0000000000..902c835c04 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-configurable-writable-desc-not-writable.js @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throw a TypeError exception if trap result is true, targetDesc is not configurable + and writable, while Desc is not writable. +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 16. Else targetDesc is not undefined, + ... + c. If IsDataDescriptor(targetDesc) is true, targetDesc.[[Configurable]] is + false, and targetDesc.[[Writable]] is true, then + i. If Desc has a [[Writable]] field and Desc.[[Writable]] is + false, throw a TypeError exception. + ... +features: [Proxy, Reflect, proxy-missing-checks] +---*/ + +var trapCalls = 0; +var p = new Proxy({}, { + defineProperty: function(t, prop, desc) { + Object.defineProperty(t, prop, { + configurable: false, + writable: true, + }); + + trapCalls++; + return true; + }, +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty(p, "prop", { + writable: false, + }); +}); +assert.sameValue(trapCalls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor-realm.js new file mode 100644 index 0000000000..b0cf2b1ce4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor-realm.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throw a TypeError exception if Desc is not configurable and target property + descriptor is undefined, and trap result is true (honoring the realm of the + current execution context). +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 19. If targetDesc is undefined, then + ... + b. If settingConfigFalse is true, throw a TypeError exception. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var target = Object.create(null); +var p = new OProxy(target, { + defineProperty: function() { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, 'prop', { + configurable: false + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js new file mode 100644 index 0000000000..a5a1806052 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.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.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. + ... +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + configurable: false + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible-realm.js new file mode 100644 index 0000000000..65851dc799 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible-realm.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throw a TypeError exception if Desc is not configurable and target is not + extensible, and trap result is true (honoring the realm of the current + execution context). +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 19. If targetDesc is undefined, then + a. If extensibleTarget is false, throw a TypeError exception. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var target = Object.create(null); +var p = new OProxy(target, { + defineProperty: function() { + return true; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + p.prop = null; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js new file mode 100644 index 0000000000..dedafb6ba6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.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.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. + ... +features: [Proxy] +---*/ + +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", {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..0731dd58bb --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-missing-target-is-proxy.js @@ -0,0 +1,50 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[DefineOwnProperty]] (P, Desc) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "defineProperty"). + 7. If trap is undefined, then + a. Return ? target.[[DefineOwnProperty]](P, Desc). +features: [Proxy, Reflect] +---*/ + +var string = new String("str"); +var stringTarget = new Proxy(string, {}); +var stringProxy = new Proxy(stringTarget, {}); + +assert(Reflect.defineProperty(stringProxy, "4", {value: 4})); +assert.sameValue(string[4], 4); + +assert.throws(TypeError, function() { + Object.defineProperty(stringProxy, "0", { + value: "x", + }); +}); + +Object.preventExtensions(string); +assert(!Reflect.defineProperty(stringProxy, "foo", {value: 5})); + + +var func = function() {}; +var funcTarget = new Proxy(func, {}); +var funcProxy = new Proxy(funcTarget, {}); + +Object.defineProperty(funcProxy, "name", {value: "foo"}); +assert.sameValue(func.name, "foo"); + +assert.throws(TypeError, function() { + Object.defineProperty(funcProxy, "prototype", { + set: function(_value) {}, + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..2f8adb54c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-not-callable-realm.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +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. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = new OProxy({}, { + defineProperty: {} +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-not-callable.js new file mode 100644 index 0000000000..96effe4ca6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/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.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. + ... +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: {} +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..0beb8e52a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-null-target-is-proxy.js @@ -0,0 +1,59 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[DefineOwnProperty]] (P, Desc) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "defineProperty"). + 7. If trap is undefined, then + a. Return ? target.[[DefineOwnProperty]](P, Desc). +features: [Proxy, Reflect] +includes: [propertyHelper.js] +---*/ + +var plainObject = Object.create(null); +Object.defineProperty(plainObject, "foo", { + configurable: false, +}); + +var plainObjectTarget = new Proxy(plainObject, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + defineProperty: null, +}); + +assert.throws(TypeError, function() { + Object.defineProperty(plainObjectProxy, "foo", { + configurable: true, + }); +}); + +Object.defineProperty(plainObjectProxy, "bar", { + get: function() { + return 2; + }, +}); +assert.sameValue(plainObject.bar, 2); + + +var regExp = /(?:)/g; +var regExpTarget = new Proxy(regExp, {}); +var regExpProxy = new Proxy(regExpTarget, { + defineProperty: null, +}); + +assert( + Reflect.defineProperty(regExpProxy, "lastIndex", { + writable: false, + }) +); + +verifyNotWritable(regExp, "lastIndex"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..26934ca15f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,57 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[DefineOwnProperty]] (P, Desc) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "defineProperty"). + 7. If trap is undefined, then + a. Return ? target.[[DefineOwnProperty]](P, Desc). +features: [Proxy, Reflect] +includes: [compareArray.js] +---*/ + +var array = []; +var arrayTarget = new Proxy(array, {}); +var arrayProxy = new Proxy(arrayTarget, { + defineProperty: undefined, +}); + +Object.defineProperty(arrayProxy, "0", {value: 1}); +assert.compareArray(array, [1]); + +assert.throws(TypeError, function() { + Object.defineProperty(arrayProxy, "length", { + get: function() {}, + }); +}); + + +var trapCalls = 0; +var target = new Proxy({}, { + defineProperty: function(_target, key) { + trapCalls++; + return key === "foo"; + }, +}); + +var proxy = new Proxy(target, { + defineProperty: undefined, +}); + +assert(Reflect.defineProperty(proxy, "foo", {})); +assert.sameValue(trapCalls, 1); + +assert.throws(TypeError, function() { + Object.defineProperty(proxy, "bar", {}); +}); +assert.sameValue(trapCalls, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-undefined.js new file mode 100644 index 0000000000..5a45b34631 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-undefined.js @@ -0,0 +1,45 @@ +// 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] +features: [Proxy] +---*/ + +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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-return-is-false.js b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-return-is-false.js new file mode 100644 index 0000000000..e34046be1a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/defineProperty/trap-return-is-false.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: > + Trap returns a boolean. Checking on false values. +info: | + [[DefineOwnProperty]] (P, Desc) + + ... + 12. If booleanTrapResult is false, return false. + ... +features: [Proxy, 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 +); + +reportCompare(0, 0); |