From 867ca540d6cc991a82b41a3b7f9ccb9e93efe803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 10 Sep 2024 15:35:30 +0200 Subject: [PATCH] Add test coverage for correct binding object MOP executions in with-environment --- .../get-binding-value-call-with-proxy-env.js | 66 +++++++++++ .../get-binding-value-idref-with-proxy-env.js | 66 +++++++++++ .../with/has-binding-call-with-proxy-env.js | 40 +++++++ .../with/has-binding-idref-with-proxy-env.js | 40 +++++++ ...ng-idref-compound-assign-with-proxy-env.js | 105 ++++++++++++++++++ ...et-mutable-binding-idref-with-proxy-env.js | 91 +++++++++++++++ 6 files changed, 408 insertions(+) create mode 100644 test/language/statements/with/get-binding-value-call-with-proxy-env.js create mode 100644 test/language/statements/with/get-binding-value-idref-with-proxy-env.js create mode 100644 test/language/statements/with/has-binding-call-with-proxy-env.js create mode 100644 test/language/statements/with/has-binding-idref-with-proxy-env.js create mode 100644 test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js create mode 100644 test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js diff --git a/test/language/statements/with/get-binding-value-call-with-proxy-env.js b/test/language/statements/with/get-binding-value-call-with-proxy-env.js new file mode 100644 index 0000000000..a8fa7663b1 --- /dev/null +++ b/test/language/statements/with/get-binding-value-call-with-proxy-env.js @@ -0,0 +1,66 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-getbindingvalue-n-s +description: > + Lookups in proxy binding object for call expression. +info: | + 9.1.1.2.1 HasBinding ( N ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let foundBinding be ? HasProperty(bindingObject, N). + 3. If foundBinding is false, return false. + ... + 5. Let unscopables be ? Get(bindingObject, %Symbol.unscopables%). + ... + 7. Return true. + + 9.1.1.2.6 GetBindingValue ( N, S ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let value be ? HasProperty(bindingObject, N). + 3. If value is false, then + a. If S is false, return undefined; otherwise throw a ReferenceError exception. + 4. Return ? Get(bindingObject, N). + +features: [Proxy, Reflect] +flags: [noStrict] +includes: [compareArray.js, proxyTrapsHelper.js] +---*/ + +var log = []; + +// Environment contains referenced binding. +var env = { + Object, +}; + +var proxy = new Proxy(env, allowProxyTraps({ + has(t, pk) { + log.push("has:" + String(pk)); + return Reflect.has(t, pk); + }, + get(t, pk, r) { + log.push("get:" + String(pk)); + return Reflect.get(t, pk, r); + }, +})); + +with (proxy) { + Object(); +} + +assert.compareArray(log, [ + // HasBinding, step 2. + "has:Object", + + // HasBinding, step 5. + "get:Symbol(Symbol.unscopables)", + + // GetBindingValue, step 2. + "has:Object", + + // GetBindingValue, step 4. + "get:Object", +]); diff --git a/test/language/statements/with/get-binding-value-idref-with-proxy-env.js b/test/language/statements/with/get-binding-value-idref-with-proxy-env.js new file mode 100644 index 0000000000..ab642634db --- /dev/null +++ b/test/language/statements/with/get-binding-value-idref-with-proxy-env.js @@ -0,0 +1,66 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-getbindingvalue-n-s +description: > + Lookups in proxy binding object for identifier reference. +info: | + 9.1.1.2.1 HasBinding ( N ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let foundBinding be ? HasProperty(bindingObject, N). + 3. If foundBinding is false, return false. + ... + 5. Let unscopables be ? Get(bindingObject, %Symbol.unscopables%). + ... + 7. Return true. + + 9.1.1.2.6 GetBindingValue ( N, S ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let value be ? HasProperty(bindingObject, N). + 3. If value is false, then + a. If S is false, return undefined; otherwise throw a ReferenceError exception. + 4. Return ? Get(bindingObject, N). + +features: [Proxy, Reflect] +flags: [noStrict] +includes: [compareArray.js, proxyTrapsHelper.js] +---*/ + +var log = []; + +// Environment contains referenced binding. +var env = { + Object, +}; + +var proxy = new Proxy(env, allowProxyTraps({ + has(t, pk) { + log.push("has:" + String(pk)); + return Reflect.has(t, pk); + }, + get(t, pk, r) { + log.push("get:" + String(pk)); + return Reflect.get(t, pk, r); + }, +})); + +with (proxy) { + Object; +} + +assert.compareArray(log, [ + // HasBinding, step 2. + "has:Object", + + // HasBinding, step 5. + "get:Symbol(Symbol.unscopables)", + + // GetBindingValue, step 2. + "has:Object", + + // GetBindingValue, step 4. + "get:Object", +]); diff --git a/test/language/statements/with/has-binding-call-with-proxy-env.js b/test/language/statements/with/has-binding-call-with-proxy-env.js new file mode 100644 index 0000000000..045fecb8ff --- /dev/null +++ b/test/language/statements/with/has-binding-call-with-proxy-env.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-hasbinding-n +description: > + Lookups in proxy binding object for call expression. +info: | + 9.1.1.2.1 HasBinding ( N ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let foundBinding be ? HasProperty(bindingObject, N). + 3. If foundBinding is false, return false. + ... + +features: [Proxy, Reflect] +flags: [noStrict] +includes: [compareArray.js, proxyTrapsHelper.js] +---*/ + +var log = []; + +// Empty environment. +var env = {}; + +var proxy = new Proxy(env, allowProxyTraps({ + has(t, pk) { + log.push("has:" + String(pk)); + return Reflect.has(t, pk); + }, +})); + +with (proxy) { + Object(); +} + +assert.compareArray(log, [ + // HasBinding, step 2. + "has:Object", +]); diff --git a/test/language/statements/with/has-binding-idref-with-proxy-env.js b/test/language/statements/with/has-binding-idref-with-proxy-env.js new file mode 100644 index 0000000000..26a3931a2a --- /dev/null +++ b/test/language/statements/with/has-binding-idref-with-proxy-env.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-hasbinding-n +description: > + Lookups in proxy binding object for identifier reference. +info: | + 9.1.1.2.1 HasBinding ( N ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let foundBinding be ? HasProperty(bindingObject, N). + 3. If foundBinding is false, return false. + ... + +features: [Proxy, Reflect] +flags: [noStrict] +includes: [compareArray.js, proxyTrapsHelper.js] +---*/ + +var log = []; + +// Empty environment. +var env = {}; + +var proxy = new Proxy(env, allowProxyTraps({ + has(t, pk) { + log.push("has:" + String(pk)); + return Reflect.has(t, pk); + }, +})); + +with (proxy) { + Object; +} + +assert.compareArray(log, [ + // HasBinding, step 2. + "has:Object", +]); diff --git a/test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js b/test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js new file mode 100644 index 0000000000..166803d752 --- /dev/null +++ b/test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js @@ -0,0 +1,105 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-setmutablebinding-n-v-s +description: > + Lookups in proxy binding object for identifier reference. +info: | + 9.1.1.2.1 HasBinding ( N ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let foundBinding be ? HasProperty(bindingObject, N). + 3. If foundBinding is false, return false. + ... + 5. Let unscopables be ? Get(bindingObject, %Symbol.unscopables%). + ... + 7. Return true. + + 9.1.1.2.6 GetBindingValue ( N, S ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let value be ? HasProperty(bindingObject, N). + 3. If value is false, then + a. If S is false, return undefined; otherwise throw a ReferenceError exception. + 4. Return ? Get(bindingObject, N). + + 9.1.1.2.5 SetMutableBinding ( N, V, S ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let stillExists be ? HasProperty(bindingObject, N). + ... + 4. Perform ? Set(bindingObject, N, V, S). + ... + + 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + ... + 2. If IsDataDescriptor(ownDesc) is true, then + ... + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + ... + iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). + ... + +features: [Proxy, Reflect] +flags: [noStrict] +includes: [compareArray.js, proxyTrapsHelper.js] +---*/ + +var log = []; + +// Environment contains referenced binding. +var env = { + p: 0, +}; + +var proxy = new Proxy(env, allowProxyTraps({ + has(t, pk) { + log.push("has:" + String(pk)); + return Reflect.has(t, pk); + }, + get(t, pk, r) { + log.push("get:" + String(pk)); + return Reflect.get(t, pk, r); + }, + set(t, pk, v, r) { + log.push("set:" + String(pk)); + return Reflect.set(t, pk, v, r); + }, + getOwnPropertyDescriptor(t, pk) { + log.push("getOwnPropertyDescriptor:" + String(pk)); + return Reflect.getOwnPropertyDescriptor(t, pk); + }, + defineProperty(t, pk, d) { + log.push("defineProperty:" + String(pk)); + return Reflect.defineProperty(t, pk, d); + }, +})); + +with (proxy) { + p += 1; +} + +assert.compareArray(log, [ + // HasBinding, step 2. + "has:p", + + // HasBinding, step 5. + "get:Symbol(Symbol.unscopables)", + + // GetBindingValue, step 2. + "has:p", + + // GetBindingValue, step 4. + "get:p", + + // SetMutableBinding, step 2. + "has:p", + + // SetMutableBinding, step 4. + "set:p", + "getOwnPropertyDescriptor:p", + "defineProperty:p", +]); diff --git a/test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js b/test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js new file mode 100644 index 0000000000..e5f202eb50 --- /dev/null +++ b/test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js @@ -0,0 +1,91 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-setmutablebinding-n-v-s +description: > + Lookups in proxy binding object for identifier reference. +info: | + 9.1.1.2.1 HasBinding ( N ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let foundBinding be ? HasProperty(bindingObject, N). + 3. If foundBinding is false, return false. + ... + 5. Let unscopables be ? Get(bindingObject, %Symbol.unscopables%). + ... + 7. Return true. + + 9.1.1.2.5 SetMutableBinding ( N, V, S ) + + 1. Let bindingObject be envRec.[[BindingObject]]. + 2. Let stillExists be ? HasProperty(bindingObject, N). + ... + 4. Perform ? Set(bindingObject, N, V, S). + ... + + 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + ... + 2. If IsDataDescriptor(ownDesc) is true, then + ... + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + ... + iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). + ... + +features: [Proxy, Reflect] +flags: [noStrict] +includes: [compareArray.js, proxyTrapsHelper.js] +---*/ + +var log = []; + +// Environment contains referenced binding. +var env = { + p: 0, +}; + +var proxy = new Proxy(env, allowProxyTraps({ + has(t, pk) { + log.push("has:" + String(pk)); + return Reflect.has(t, pk); + }, + get(t, pk, r) { + log.push("get:" + String(pk)); + return Reflect.get(t, pk, r); + }, + set(t, pk, v, r) { + log.push("set:" + String(pk)); + return Reflect.set(t, pk, v, r); + }, + getOwnPropertyDescriptor(t, pk) { + log.push("getOwnPropertyDescriptor:" + String(pk)); + return Reflect.getOwnPropertyDescriptor(t, pk); + }, + defineProperty(t, pk, d) { + log.push("defineProperty:" + String(pk)); + return Reflect.defineProperty(t, pk, d); + }, +})); + +with (proxy) { + p = 1; +} + +assert.compareArray(log, [ + // HasBinding, step 2. + "has:p", + + // HasBinding, step 5. + "get:Symbol(Symbol.unscopables)", + + // SetMutableBinding, step 2. + "has:p", + + // SetMutableBinding, step 4. + "set:p", + "getOwnPropertyDescriptor:p", + "defineProperty:p", +]);