Port ProxyRevoke to Torque

This is a part of effort to port Proxy-related builtins to Torque.

Spec: https://tc39.github.io/ecma262/#sec-proxy-revocation-functions
Bug: v8:6664
Change-Id: I283a4d8109a31c7e91f1cea8eb7a6e819e60b1cc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1521921
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60311}
This commit is contained in:
Z Duong Nguyen-Huu 2019-03-18 11:10:18 -07:00 committed by Commit Bot
parent 1cb05f1ff4
commit f78963de06
8 changed files with 77 additions and 36 deletions

View File

@ -930,8 +930,9 @@ torque_files = [
"src/builtins/collections.tq",
"src/builtins/data-view.tq",
"src/builtins/extras-utils.tq",
"src/builtins/object-fromentries.tq",
"src/builtins/iterator.tq",
"src/builtins/object-fromentries.tq",
"src/builtins/proxy-revoke.tq",
"src/builtins/string-endswith.tq",
"src/builtins/string-html.tq",
"src/builtins/string-repeat.tq",
@ -976,6 +977,7 @@ torque_namespaces = [
"growable-fixed-array",
"iterator",
"object",
"proxy",
"string",
"string-html",
"string-repeat",

View File

@ -346,6 +346,13 @@ extern operator '[]' macro LoadContextElement(
extern operator '[]=' macro StoreContextElement(
NativeContext, NativeContextSlot, Object): void;
type ContextSlot generates 'TNode<IntPtrT>' constexpr 'int32_t';
const PROXY_SLOT: constexpr ContextSlot
generates 'Context::MIN_CONTEXT_SLOTS';
extern operator '[]' macro LoadContextElement(Context, ContextSlot): Object;
extern operator '[]=' macro StoreContextElement(
Context, ContextSlot, Object): void;
extern operator '[]' macro LoadContextElement(Context, intptr): Object;
extern operator '[]' macro LoadContextElement(Context, Smi): Object;
@ -1115,6 +1122,8 @@ extern macro IsValidPositiveSmi(intptr): bool;
extern macro HeapObjectToJSDataView(HeapObject): JSDataView
labels CastError;
extern macro HeapObjectToJSProxy(HeapObject): JSProxy
labels CastError;
extern macro HeapObjectToJSArrayBuffer(HeapObject): JSArrayBuffer
labels CastError;
extern macro TaggedToHeapObject(Object): HeapObject
@ -1194,6 +1203,11 @@ Cast<JSDataView>(o: HeapObject): JSDataView
return HeapObjectToJSDataView(o) otherwise CastError;
}
Cast<JSProxy>(o: HeapObject): JSProxy
labels CastError {
return HeapObjectToJSProxy(o) otherwise CastError;
}
Cast<JSTypedArray>(o: HeapObject): JSTypedArray
labels CastError {
if (IsJSTypedArray(o)) return %RawDownCast<JSTypedArray>(o);
@ -1391,6 +1405,7 @@ extern macro StringConstant(constexpr string): String;
extern macro LanguageModeConstant(constexpr LanguageMode): LanguageMode;
extern macro Int32Constant(constexpr ElementsKind): ElementsKind;
extern macro IntPtrConstant(constexpr NativeContextSlot): NativeContextSlot;
extern macro IntPtrConstant(constexpr ContextSlot): ContextSlot;
extern macro IntPtrConstant(constexpr intptr): intptr;
extern macro BitcastWordToTaggedSigned(intptr): Smi;
@ -1480,6 +1495,10 @@ FromConstexpr<NativeContextSlot, constexpr NativeContextSlot>(
c: constexpr NativeContextSlot): NativeContextSlot {
return IntPtrConstant(c);
}
FromConstexpr<ContextSlot, constexpr ContextSlot>(c: constexpr ContextSlot):
ContextSlot {
return IntPtrConstant(c);
}
macro Convert<To: type, From: type>(i: From): To {
return i;
@ -1975,6 +1994,7 @@ extern macro TransitionElementsKind(
extern macro IsCallable(HeapObject): bool;
extern macro IsConstructor(HeapObject): bool;
extern macro IsJSArray(HeapObject): bool;
extern macro IsJSProxy(HeapObject): bool;
extern macro IsMap(HeapObject): bool;
extern macro IsJSFunction(HeapObject): bool;
extern macro IsJSObject(HeapObject): bool;

View File

@ -867,7 +867,6 @@ namespace internal {
/* Proxy */ \
TFJ(ProxyConstructor, 2, kReceiver, kTarget, kHandler) \
TFJ(ProxyRevocable, 2, kReceiver, kTarget, kHandler) \
TFJ(ProxyRevoke, 0, kReceiver) \
TFS(ProxyGetProperty, kProxy, kName, kReceiverValue, kOnNonExistent) \
TFS(ProxyHasProperty, kProxy, kName) \
TFS(ProxySetProperty, kProxy, kName, kValue, kReceiverValue) \

View File

@ -246,40 +246,6 @@ TF_BUILTIN(ProxyRevocable, ProxiesCodeStubAssembler) {
ThrowTypeError(context, MessageTemplate::kProxyHandlerOrTargetRevoked);
}
// Proxy Revocation Functions
// https://tc39.github.io/ecma262/#sec-proxy-revocation-functions
TF_BUILTIN(ProxyRevoke, ProxiesCodeStubAssembler) {
Node* const context = Parameter(Descriptor::kContext);
// 1. Let p be F.[[RevocableProxy]].
Node* const proxy_slot = IntPtrConstant(kProxySlot);
Node* const proxy = LoadContextElement(context, proxy_slot);
Label revoke_called(this);
// 2. If p is null, ...
GotoIf(IsNull(proxy), &revoke_called);
// 3. Set F.[[RevocableProxy]] to null.
StoreContextElement(context, proxy_slot, NullConstant());
// 4. Assert: p is a Proxy object.
CSA_ASSERT(this, IsJSProxy(proxy));
// 5. Set p.[[ProxyTarget]] to null.
StoreObjectField(proxy, JSProxy::kTargetOffset, NullConstant());
// 6. Set p.[[ProxyHandler]] to null.
StoreObjectField(proxy, JSProxy::kHandlerOffset, NullConstant());
// 7. Return undefined.
Return(UndefinedConstant());
BIND(&revoke_called);
// 2. ... return undefined.
Return(UndefinedConstant());
}
TF_BUILTIN(CallProxy, ProxiesCodeStubAssembler) {
Node* argc = Parameter(Descriptor::kActualArgumentsCount);
Node* argc_ptr = ChangeInt32ToIntPtr(argc);

View File

@ -0,0 +1,46 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include 'src/builtins/builtins-proxy-gen.h'
namespace proxy {
macro ValidateProxy(context: Context, o: Object, method: String): JSProxy {
try {
return Cast<JSProxy>(o) otherwise CastError;
}
label CastError {
ThrowTypeError(kIncompatibleMethodReceiver, method);
}
}
// Proxy Revocation Functions
// https://tc39.github.io/ecma262/#sec-proxy-revocation-functions
// TODO(v8:9007) remove receiver in argument since we don't use it
transitioning javascript builtin
ProxyRevoke(context: Context, receiver: Object): Undefined {
// 1. Let p be F.[[RevocableProxy]].
const proxyObject: Object = context[PROXY_SLOT];
// 2. If p is null, return undefined
if (proxyObject == Null) {
return Undefined;
}
// 3. Set F.[[RevocableProxy]] to null.
context[PROXY_SLOT] = Null;
// 4. Assert: p is a Proxy object.
const proxy: JSProxy = UnsafeCast<JSProxy>(proxyObject);
// 5. Set p.[[ProxyTarget]] to null.
proxy.target = Null;
// 6. Set p.[[ProxyHandler]] to null.
proxy.handler = Null;
// 7. Return undefined.
return Undefined;
}
}

View File

@ -359,6 +359,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
return CAST(heap_object);
}
TNode<JSProxy> HeapObjectToJSProxy(TNode<HeapObject> heap_object,
Label* fail) {
GotoIfNot(IsJSProxy(heap_object), fail);
return CAST(heap_object);
}
TNode<JSReceiver> HeapObjectToCallable(TNode<HeapObject> heap_object,
Label* fail) {
GotoIfNot(IsCallable(heap_object), fail);

View File

@ -23,6 +23,7 @@
#include "src/objects/heap-number.h"
#include "src/objects/js-array-buffer.h"
#include "src/objects/js-collection.h"
#include "src/objects/js-proxy.h"
#include "src/objects/map.h"
#include "src/objects/maybe-object.h"
#include "src/objects/oddball.h"

View File

@ -6,6 +6,7 @@
#define V8_OBJECTS_JS_PROXY_H_
#include "src/objects/js-objects.h"
#include "torque-generated/builtin-definitions-from-dsl.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"