Skip to content

Commit

Permalink
Add more tests for deleted bindings in object environments
Browse files Browse the repository at this point in the history
  • Loading branch information
anba authored and Ms2ger committed Aug 27, 2024
1 parent b9ed8c9 commit 18c8c85
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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: >
Binding deleted when retrieving unscopables.
info: |
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.
...
flags: [noStrict]
features: [Symbol.unscopables]
---*/

var unscopablesCalled = 0;

var env = {
binding: 0,
get [Symbol.unscopables]() {
unscopablesCalled++;
delete env.binding;
return null;
}
};

var result = null;
with (env) {
assert.throws(ReferenceError, function() {
"use strict";
result = binding;
});
}

assert.sameValue(unscopablesCalled, 1, "get [Symbol.unscopables] called once");

assert.sameValue(result, null, "result not modified");
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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: >
Binding deleted when retrieving unscopables.
info: |
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.
...
flags: [noStrict]
features: [Symbol.unscopables]
---*/

var unscopablesCalled = 0;

var env = {
binding: 0,
get [Symbol.unscopables]() {
unscopablesCalled++;
delete env.binding;
return null;
}
};

var result = null;
with (env) {
result = binding;
}

assert.sameValue(unscopablesCalled, 1, "get [Symbol.unscopables] called once");

assert.sameValue(result, undefined, "result set to undefined");
Original file line number Diff line number Diff line change
@@ -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-setmutablebinding-n-v-s
description: >
Binding deleted when retrieving unscopables.
info: |
9.1.1.2.5 SetMutableBinding ( N, V, S )
1. Let bindingObject be envRec.[[BindingObject]].
2. Let stillExists be ? HasProperty(bindingObject, N).
3. If stillExists is false and S is true, throw a ReferenceError exception.
...
flags: [noStrict]
features: [Symbol.unscopables]
---*/

var unscopablesCalled = 0;

var env = {
binding: 0,
get [Symbol.unscopables]() {
unscopablesCalled++;
delete env.binding;
return null;
}
};

with (env) {
assert.throws(ReferenceError, function() {
"use strict";
binding = 123;
});
}

assert.sameValue(unscopablesCalled, 1, "get [Symbol.unscopables] called once");

assert.sameValue(Object.getOwnPropertyDescriptor(env, "binding"), undefined, "binding deleted");
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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: >
Binding deleted when retrieving unscopables.
info: |
9.1.1.2.5 SetMutableBinding ( N, V, S )
1. Let bindingObject be envRec.[[BindingObject]].
2. Let stillExists be ? HasProperty(bindingObject, N).
3. If stillExists is false and S is true, throw a ReferenceError exception.
4. Perform ? Set(bindingObject, N, V, S).
...
flags: [noStrict]
features: [Symbol.unscopables]
includes: [propertyHelper.js]
---*/

var unscopablesCalled = 0;

var env = {
binding: 0,
get [Symbol.unscopables]() {
unscopablesCalled++;
delete env.binding;
return null;
}
};

with (env) {
binding = 123;
}

assert.sameValue(unscopablesCalled, 1, "get [Symbol.unscopables] called once");

verifyProperty(env, "binding", {
value: 123,
writable: true,
enumerable: true,
configurable: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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: >
Typed Array index binding deleted from object.
info: |
9.1.1.2.5 SetMutableBinding ( N, V, S )
1. Let bindingObject be envRec.[[BindingObject]].
2. Let stillExists be ? HasProperty(bindingObject, N).
3. If stillExists is false and S is true, throw a ReferenceError exception.
...
flags: [noStrict]
features: [TypedArray]
---*/

var typedArray = new Int32Array(10);

var env = Object.create(typedArray);

Object.defineProperty(env, "NaN", {
configurable: true,
value: 100,
});

with (env) {
assert.throws(ReferenceError, function() {
"use strict";
NaN = (delete env.NaN, 0);
});
}

assert.sameValue(Object.getOwnPropertyDescriptor(env, "NaN"), undefined);
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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: >
Typed Array index binding deleted from object.
info: |
9.1.1.2.5 SetMutableBinding ( N, V, S )
1. Let bindingObject be envRec.[[BindingObject]].
2. Let stillExists be ? HasProperty(bindingObject, N).
3. If stillExists is false and S is true, throw a ReferenceError exception.
4. Perform ? Set(bindingObject, N, V, S).
flags: [noStrict]
features: [TypedArray]
---*/

var typedArray = new Int32Array(10);

var env = Object.create(typedArray);

Object.defineProperty(env, "NaN", {
configurable: true,
value: 100,
});

with (env) {
NaN = (delete env.NaN, 0);
}

assert.sameValue(Object.getOwnPropertyDescriptor(env, "NaN"), undefined);

0 comments on commit 18c8c85

Please sign in to comment.