Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: src/objects.cc

Issue 1481773003: [Proxies] Support constructable proxy as new.target (reland) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Diff with previous version Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 6ef3c604fb474a42ffbf4a0667eeafc059f759af..6f44f6fbd56bfceb21dd425457771df566b07a24 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4694,6 +4694,51 @@ Maybe<bool> JSProxy::DeletePropertyOrElement(Handle<JSProxy> proxy,
}
+// static
+MaybeHandle<Context> JSProxy::GetFunctionRealm(Handle<JSProxy> proxy) {
+ DCHECK(proxy->map()->is_constructor());
+ if (JSProxy::IsRevoked(proxy)) {
+ THROW_NEW_ERROR(proxy->GetIsolate(),
+ NewTypeError(MessageTemplate::kProxyRevoked), Context);
+ }
+
+ // TODO(verwaest): Get rid of JSFunctionProxies.
+ Object* target = proxy->IsJSFunctionProxy()
+ ? JSFunctionProxy::cast(*proxy)->construct_trap()
+ : proxy->target();
+ return JSReceiver::GetFunctionRealm(handle(JSReceiver::cast(target)));
+}
+
+
+// static
+MaybeHandle<Context> JSFunction::GetFunctionRealm(Handle<JSFunction> function) {
+ DCHECK(function->map()->is_constructor());
+ return handle(function->context()->native_context());
+}
+
+
+// static
+MaybeHandle<Context> JSObject::GetFunctionRealm(Handle<JSObject> object) {
+ DCHECK(object->map()->is_constructor());
+ DCHECK(!object->IsJSFunction());
+ return handle(object->GetCreationContext());
+}
+
+
+// static
+MaybeHandle<Context> JSReceiver::GetFunctionRealm(Handle<JSReceiver> receiver) {
+ if (receiver->IsJSProxy()) {
+ return JSProxy::GetFunctionRealm(Handle<JSProxy>::cast(receiver));
+ }
+
+ if (receiver->IsJSFunction()) {
+ return JSFunction::GetFunctionRealm(Handle<JSFunction>::cast(receiver));
+ }
+
+ return JSObject::GetFunctionRealm(Handle<JSObject>::cast(receiver));
+}
+
+
Maybe<PropertyAttributes> JSProxy::GetPropertyAttributes(LookupIterator* it) {
Isolate* isolate = it->isolate();
HandleScope scope(isolate);
@@ -12222,6 +12267,8 @@ Handle<Map> JSFunction::EnsureDerivedHasInitialMap(
DCHECK(!constructor->shared()->is_generator());
// Fetch or allocate prototype.
+ // TODO(verwaest): In case of non-instance prototype, use the
+ // intrinsicDefaultProto instead.
Handle<Object> prototype;
if (new_target->has_instance_prototype()) {
prototype = handle(new_target->instance_prototype(), isolate);
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-object.cc » ('j') | src/runtime/runtime-object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698