forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for deleted bindings in object environments
- Loading branch information
Showing
6 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...age/statements/with/get-mutable-binding-binding-deleted-in-get-unscopables-strict-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
39 changes: 39 additions & 0 deletions
39
test/language/statements/with/get-mutable-binding-binding-deleted-in-get-unscopables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
40 changes: 40 additions & 0 deletions
40
...age/statements/with/set-mutable-binding-binding-deleted-in-get-unscopables-strict-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
44 changes: 44 additions & 0 deletions
44
test/language/statements/with/set-mutable-binding-binding-deleted-in-get-unscopables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
36 changes: 36 additions & 0 deletions
36
...s/with/set-mutable-binding-binding-deleted-with-typed-array-in-proto-chain-strict-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
33 changes: 33 additions & 0 deletions
33
...ge/statements/with/set-mutable-binding-binding-deleted-with-typed-array-in-proto-chain.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |