Allow Proxy constructor to take revoked Proxies as targets and handlers

Normative spec change: https://github.com/tc39/ecma262/pull/1814

Bug: v8:10382
Change-Id: Ib17ece9f0c8f75702c828b5336e75cab5d173e5e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2163876
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67376}
This commit is contained in:
Shu-yu Guo 2020-04-24 11:21:45 -07:00 committed by Commit Bot
parent 1a38573f9d
commit ce43feb566
18 changed files with 39 additions and 114 deletions

View File

@ -293,7 +293,6 @@ extern enum MessageTemplate {
kCalledOnNonObject,
kRegExpGlobalInvokedOnNonGlobal,
kProxyNonObject,
kProxyHandlerOrTargetRevoked,
kProxyRevoked,
kProxyTrapReturnedFalsishFor,
kProxyPrivate,

View File

@ -21,22 +21,11 @@ namespace proxy {
// 2. Return ? ProxyCreate(target, handler).
// https://tc39.github.io/ecma262/#sec-proxycreate
// 1. If Type(target) is not Object, throw a TypeError exception.
// 2. If target is a Proxy exotic object and target.[[ProxyHandler]] is
// null, throw a TypeError exception.
// 3. If Type(handler) is not Object, throw a TypeError exception.
// 4. If handler is a Proxy exotic object and handler.[[ProxyHandler]]
// is null, throw a TypeError exception.
// 2. If Type(handler) is not Object, throw a TypeError exception.
const targetJSReceiver =
Cast<JSReceiver>(target) otherwise ThrowProxyNonObject;
if (IsRevokedProxy(targetJSReceiver)) {
goto ThrowProxyHandlerOrTargetRevoked;
}
const handlerJSReceiver =
Cast<JSReceiver>(handler) otherwise ThrowProxyNonObject;
if (IsRevokedProxy(handlerJSReceiver)) {
goto ThrowProxyHandlerOrTargetRevoked;
}
// 5. Let P be a newly created object.
// 6. Set P's essential internal methods (except for [[Call]] and
@ -53,8 +42,5 @@ namespace proxy {
label ThrowProxyNonObject deferred {
ThrowTypeError(MessageTemplate::kProxyNonObject);
}
label ThrowProxyHandlerOrTargetRevoked deferred {
ThrowTypeError(MessageTemplate::kProxyHandlerOrTargetRevoked);
}
}
}

View File

@ -15,19 +15,11 @@ namespace proxy {
ProxyRevocable(js-implicit context: NativeContext)(
target: JSAny, handler: JSAny): JSProxyRevocableResult {
try {
// 1. Let p be ? ProxyCreate(target, handler).
const targetJSReceiver =
Cast<JSReceiver>(target) otherwise ThrowProxyNonObject;
if (IsRevokedProxy(targetJSReceiver)) {
goto ThrowProxyHandlerOrTargetRevoked;
}
const handlerJSReceiver =
Cast<JSReceiver>(handler) otherwise ThrowProxyNonObject;
if (IsRevokedProxy(handlerJSReceiver)) {
goto ThrowProxyHandlerOrTargetRevoked;
}
// 1. Let p be ? ProxyCreate(target, handler).
const proxy: JSProxy = AllocateProxy(targetJSReceiver, handlerJSReceiver);
// 2. Let steps be the algorithm steps defined in Proxy Revocation
@ -45,9 +37,5 @@ namespace proxy {
label ThrowProxyNonObject deferred {
ThrowTypeError(MessageTemplate::kProxyNonObject, 'Proxy.revocable');
}
label ThrowProxyHandlerOrTargetRevoked deferred {
ThrowTypeError(
MessageTemplate::kProxyHandlerOrTargetRevoked, 'Proxy.revocable');
}
}
}

View File

@ -9,12 +9,6 @@ namespace proxy {
extern macro ProxiesCodeStubAssembler::AllocateProxy(
implicit context: Context)(JSReceiver, JSReceiver): JSProxy;
macro IsRevokedProxy(implicit context: Context)(o: JSReceiver): bool {
const proxy: JSProxy = Cast<JSProxy>(o) otherwise return false;
Cast<JSReceiver>(proxy.handler) otherwise return true;
return false;
}
extern transitioning macro ProxiesCodeStubAssembler::CheckGetSetTrapResult(
implicit context:
Context)(JSReceiver, JSProxy, Name, Object, constexpr int31);

View File

@ -223,8 +223,6 @@ namespace internal {
T(ProxyGetPrototypeOfNonExtensible, \
"'getPrototypeOf' on proxy: proxy target is non-extensible but the " \
"trap did not return its actual prototype") \
T(ProxyHandlerOrTargetRevoked, \
"Cannot create proxy with a revoked proxy as target or handler") \
T(ProxyHasNonConfigurable, \
"'has' on proxy: trap returned falsish for property '%' which exists in " \
"the proxy target as non-configurable") \

View File

@ -3106,20 +3106,10 @@ MaybeHandle<JSProxy> JSProxy::New(Isolate* isolate, Handle<Object> target,
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kProxyNonObject),
JSProxy);
}
if (target->IsJSProxy() && JSProxy::cast(*target).IsRevoked()) {
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kProxyHandlerOrTargetRevoked),
JSProxy);
}
if (!handler->IsJSReceiver()) {
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kProxyNonObject),
JSProxy);
}
if (handler->IsJSProxy() && JSProxy::cast(*handler).IsRevoked()) {
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kProxyHandlerOrTargetRevoked),
JSProxy);
}
return isolate->factory()->NewJSProxy(Handle<JSReceiver>::cast(target),
Handle<JSReceiver>::cast(handler));
}

View File

@ -292,7 +292,7 @@ bytecodes: [
B(Mov), R(context), R(16),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(17),
B(LdaConstant), U8(11),
B(Star), R(18),

View File

@ -62,7 +62,7 @@ bytecodes: [
B(Mov), R(context), R(11),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(12),
B(LdaConstant), U8(5),
B(Star), R(13),
@ -193,7 +193,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(5),
B(Star), R(14),
@ -311,7 +311,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(6),
B(Star), R(15),

View File

@ -91,7 +91,7 @@ bytecodes: [
B(Mov), R(context), R(15),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
@ -256,7 +256,7 @@ bytecodes: [
B(Mov), R(context), R(15),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
@ -437,7 +437,7 @@ bytecodes: [
B(Mov), R(context), R(15),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
@ -584,7 +584,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(7),
B(Star), R(14),

View File

@ -58,7 +58,7 @@ bytecodes: [
B(Mov), R(context), R(10),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(11),
B(LdaConstant), U8(5),
B(Star), R(12),
@ -154,7 +154,7 @@ bytecodes: [
B(Mov), R(context), R(11),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(12),
B(LdaConstant), U8(5),
B(Star), R(13),
@ -261,7 +261,7 @@ bytecodes: [
B(Mov), R(context), R(10),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(11),
B(LdaConstant), U8(5),
B(Star), R(12),
@ -361,7 +361,7 @@ bytecodes: [
B(Mov), R(context), R(10),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(11),
B(LdaConstant), U8(7),
B(Star), R(12),

View File

@ -61,7 +61,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(4),
B(Star), R(14),
@ -192,7 +192,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(9),
B(Star), R(15),
@ -300,7 +300,7 @@ bytecodes: [
B(Mov), R(context), R(11),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(12),
B(LdaConstant), U8(6),
B(Star), R(13),
@ -400,7 +400,7 @@ bytecodes: [
B(Mov), R(context), R(14),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(15),
B(LdaConstant), U8(6),
B(Star), R(16),
@ -510,7 +510,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(7),
B(Star), R(15),
@ -635,7 +635,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(10),
B(Star), R(14),
@ -744,7 +744,7 @@ bytecodes: [
B(Mov), R(context), R(14),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(15),
B(LdaConstant), U8(4),
B(Star), R(16),
@ -877,7 +877,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(5),
B(Star), R(15),

View File

@ -174,7 +174,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(11),
B(Star), R(14),

View File

@ -84,7 +84,7 @@ bytecodes: [
B(Mov), R(this), R(0),
B(Mov), R(context), R(2),
/* 48 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
/* 53 S> */ B(Wide), B(LdaSmi), I16(266),
/* 53 S> */ B(Wide), B(LdaSmi), I16(265),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Star), R(4),
@ -115,7 +115,7 @@ bytecodes: [
B(Mov), R(this), R(0),
B(Mov), R(context), R(2),
/* 41 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
/* 46 S> */ B(Wide), B(LdaSmi), I16(265),
/* 46 S> */ B(Wide), B(LdaSmi), I16(264),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Star), R(4),
@ -146,7 +146,7 @@ bytecodes: [
B(Mov), R(this), R(0),
B(Mov), R(context), R(2),
/* 48 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
/* 53 S> */ B(Wide), B(LdaSmi), I16(266),
/* 53 S> */ B(Wide), B(LdaSmi), I16(265),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Star), R(4),
@ -177,7 +177,7 @@ bytecodes: [
B(Mov), R(this), R(0),
B(Mov), R(context), R(2),
/* 41 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
/* 46 S> */ B(Wide), B(LdaSmi), I16(265),
/* 46 S> */ B(Wide), B(LdaSmi), I16(264),
B(Star), R(4),
B(LdaConstant), U8(0),
B(Star), R(5),

View File

@ -57,7 +57,7 @@ bytecodes: [
B(Mov), R(this), R(0),
B(Mov), R(context), R(2),
/* 44 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
/* 49 S> */ B(Wide), B(LdaSmi), I16(264),
/* 49 S> */ B(Wide), B(LdaSmi), I16(263),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Star), R(4),
@ -89,7 +89,7 @@ bytecodes: [
B(Mov), R(this), R(0),
B(Mov), R(context), R(2),
/* 44 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
/* 49 S> */ B(Wide), B(LdaSmi), I16(264),
/* 49 S> */ B(Wide), B(LdaSmi), I16(263),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Star), R(4),

View File

@ -25,7 +25,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(1),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(262),
B(Wide), B(LdaSmi), I16(261),
B(Star), R(2),
B(LdaConstant), U8(0),
B(Star), R(3),
@ -56,7 +56,7 @@ frame size: 2
parameter count: 1
bytecode array length: 16
bytecodes: [
/* 56 S> */ B(Wide), B(LdaSmi), I16(264),
/* 56 S> */ B(Wide), B(LdaSmi), I16(263),
B(Star), R(0),
B(LdaConstant), U8(0),
B(Star), R(1),
@ -83,7 +83,7 @@ frame size: 2
parameter count: 1
bytecode array length: 16
bytecodes: [
/* 56 S> */ B(Wide), B(LdaSmi), I16(264),
/* 56 S> */ B(Wide), B(LdaSmi), I16(263),
B(Star), R(0),
B(LdaConstant), U8(0),
B(Star), R(1),
@ -122,7 +122,7 @@ bytecodes: [
/* 94 E> */ B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(262),
B(Wide), B(LdaSmi), I16(261),
B(Star), R(2),
B(LdaConstant), U8(0),
B(Star), R(3),
@ -144,7 +144,7 @@ bytecodes: [
/* 109 E> */ B(TestReferenceEqual), R(this),
B(Mov), R(this), R(1),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(263),
B(Wide), B(LdaSmi), I16(262),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Star), R(4),
@ -159,7 +159,7 @@ bytecodes: [
/* 133 E> */ B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(262),
B(Wide), B(LdaSmi), I16(261),
B(Star), R(2),
B(LdaConstant), U8(0),
B(Star), R(3),
@ -189,7 +189,7 @@ frame size: 2
parameter count: 1
bytecode array length: 16
bytecodes: [
/* 60 S> */ B(Wide), B(LdaSmi), I16(266),
/* 60 S> */ B(Wide), B(LdaSmi), I16(265),
B(Star), R(0),
B(LdaConstant), U8(0),
B(Star), R(1),
@ -215,7 +215,7 @@ frame size: 2
parameter count: 1
bytecode array length: 16
bytecodes: [
/* 53 S> */ B(Wide), B(LdaSmi), I16(265),
/* 53 S> */ B(Wide), B(LdaSmi), I16(264),
B(Star), R(0),
B(LdaConstant), U8(0),
B(Star), R(1),
@ -241,7 +241,7 @@ frame size: 2
parameter count: 1
bytecode array length: 16
bytecodes: [
/* 60 S> */ B(Wide), B(LdaSmi), I16(266),
/* 60 S> */ B(Wide), B(LdaSmi), I16(265),
B(Star), R(0),
B(LdaConstant), U8(0),
B(Star), R(1),
@ -267,7 +267,7 @@ frame size: 3
parameter count: 1
bytecode array length: 16
bytecodes: [
/* 46 S> */ B(Wide), B(LdaSmi), I16(265),
/* 46 S> */ B(Wide), B(LdaSmi), I16(264),
B(Star), R(1),
B(LdaConstant), U8(0),
B(Star), R(2),

View File

@ -22,14 +22,6 @@
})();
(function testRevokedTarget() {
var revocable = Proxy.revocable({}, {});
revocable.revoke();
assertThrows(function(){ new Proxy(revocable.proxy, {}); }, TypeError);
})();
(function testNonObjectHandlerTypes() {
assertThrows(function(){ new Proxy({}, undefined); }, TypeError);
@ -45,14 +37,6 @@
})();
(function testRevokedHandler() {
var revocable = Proxy.revocable({}, {});
revocable.revoke();
assertThrows(function(){ new Proxy({}, revocable.proxy); }, TypeError);
})();
(function testConstructionWithoutArguments() {
assertThrows(function(){ new Proxy(); }, TypeError);

View File

@ -21,9 +21,3 @@ assertEquals(undefined, revoke());
for (var trap of traps) {
assertThrows(() => Reflect[trap](proxy), TypeError);
}
// Throw TypeError if target or handler is revoked proxy
var revocable = Proxy.revocable({}, {});
revocable.revoke();
assertThrows(function(){ Proxy.revocable(revocable.proxy, {}); }, TypeError);
assertThrows(function(){ Proxy.revocable({}, revocable.proxy); }, TypeError);

View File

@ -675,14 +675,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=10381
'built-ins/Array/prototype/concat/arg-length-near-integer-limit': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=10382
'built-ins/Proxy/create-handler-is-revoked-proxy': [FAIL],
'built-ins/Proxy/create-target-is-revoked-function-proxy': [FAIL],
'built-ins/Proxy/create-target-is-revoked-proxy': [FAIL],
'built-ins/Proxy/revocable/handler-is-revoked-proxy': [FAIL],
'built-ins/Proxy/revocable/target-is-revoked-function-proxy': [FAIL],
'built-ins/Proxy/revocable/target-is-revoked-proxy': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=10383
'built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args-empty-result': [FAIL],