Commit 2639bfe9 authored by arv's avatar arv Committed by Commit bot

ES6: Update unscopables to match spec

The spec ended up using Get(unscopables, propertyName) and
comparing the result to undefined instead of using Has.

BUG=v8:3632
LOG=Y
R=adamk, dslomov@chromium.org

Review URL: https://codereview.chromium.org/807893002

Cr-Commit-Position: refs/heads/master@{#25854}
parent 5f22fdd5
......@@ -134,13 +134,14 @@ static Maybe<PropertyAttributes> UnscopableLookup(LookupIterator* it) {
return Maybe<PropertyAttributes>();
}
if (!unscopables->IsSpecObject()) return attrs;
Maybe<bool> blacklist = JSReceiver::HasProperty(
Handle<JSReceiver>::cast(unscopables), it->name());
if (!blacklist.has_value) {
Handle<Object> blacklist;
MaybeHandle<Object> maybe_blacklist =
Object::GetProperty(unscopables, it->name());
if (!maybe_blacklist.ToHandle(&blacklist)) {
DCHECK(isolate->has_pending_exception());
return Maybe<PropertyAttributes>();
}
if (blacklist.value) return maybe(ABSENT);
if (!blacklist->IsUndefined()) return maybe(ABSENT);
return attrs;
}
......
......@@ -143,6 +143,13 @@ function TestBasics(object) {
assertEquals(2, y);
assertEquals(3, z);
}
object[Symbol.unscopables] = {x: 0, y: undefined};
with (object) {
assertEquals(1, x);
assertEquals(5, y);
assertEquals(3, z);
}
}
runTest(TestBasics);
......@@ -161,6 +168,13 @@ function TestUnscopableChain(object) {
with (object) {
assertEquals(1, x);
}
object[Symbol.unscopables] = {
__proto__: {x: undefined}
};
with (object) {
assertEquals(2, x);
}
}
runTest(TestUnscopableChain);
......@@ -222,6 +236,14 @@ function TestOnProto(object, proto) {
assertEquals(5, y);
assertEquals(3, z);
}
proto[Symbol.unscopables] = {y: true};
object[Symbol.unscopables] = {x: true, y: undefined};
with (object) {
assertEquals(1, x);
assertEquals(5, y);
assertEquals(3, z);
}
}
runTest(TestOnProto);
......@@ -341,6 +363,20 @@ function TestChangeDuringWithWithPossibleOptimization4(object) {
TestChangeDuringWithWithPossibleOptimization4({});
function TestChangeDuringWithWithPossibleOptimization4(object) {
var x = 1;
object.x = 2;
object[Symbol.unscopables] = {x: true};
with (object) {
for (var i = 0; i < 1000; i++) {
if (i === 500) object[Symbol.unscopables].x = undefined;
assertEquals(i < 500 ? 1 : 2, x);
}
}
}
TestChangeDuringWithWithPossibleOptimization4({});
function TestAccessorReceiver(object, proto) {
var x = 'local';
......@@ -532,9 +568,11 @@ function TestAccessorOnUnscopables(object) {
var x = 1;
object.x = 2;
var calls = 0;
var unscopables = {
get x() {
assertUnreachable();
calls++;
return calls === 1 ? true : undefined;
}
};
......@@ -542,7 +580,9 @@ function TestAccessorOnUnscopables(object) {
assertEquals(2, x);
object[Symbol.unscopables] = unscopables;
assertEquals(1, x);
assertEquals(2, x);
}
assertEquals(2, calls);
}
runTest(TestAccessorOnUnscopables);
......@@ -659,3 +699,25 @@ function TestGetUnscopablesGetterThrows() {
}, CustomError);
}
TestGetUnscopablesGetterThrows();
function TestGetUnscopablesGetterThrows2() {
var object = {
get x() {
assertUnreachable();
}
};
function CustomError() {}
object[Symbol.unscopables] = {
get x() {
throw new CustomError();
}
};
assertThrows(function() {
with (object) {
x;
}
}, CustomError);
}
TestGetUnscopablesGetterThrows();
......@@ -74,12 +74,17 @@ function TestUseProxyAsUnscopables() {
var calls = 0;
var proxy = Proxy.create({
has: function(key) {
calls++;
assertEquals('x', key);
return calls === 2;
assertUnreachable();
},
getPropertyDescriptor: function(key) {
assertUnreachable();
calls++;
assertEquals('x', key);
return {
value: calls === 2 ? true : undefined,
configurable: true,
enumerable: true,
writable: true,
};
}
});
......@@ -107,12 +112,12 @@ function TestThrowInHasUnscopables() {
var calls = 0;
var proxy = Proxy.create({
has: function(key) {
if (calls++ === 0) {
throw new CustomError();
}
assertUnreachable();
},
getPropertyDescriptor: function(key) {
if (calls++ === 0) {
throw new CustomError();
}
assertUnreachable();
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment