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

Unified Diff: src/objects.cc

Issue 1481613003: [Proxies] Support constructable proxy as new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index d60bf8b56aa95cadb824b13ffc4ce02aa6c72921..58daac5402f1ad7badd729c69c1de2cbecefd531 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);
@@ -12195,6 +12240,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698