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

Side by Side Diff: src/api.cc

Issue 2698683003: Make FunctionTemplate::HasInstance checks work with remote contexts. (Closed)
Patch Set: Break dependency on CreationContext patch Created 3 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/unittests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 4454 matching lines...) Expand 10 before | Expand all | Expand 10 after
4465 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 4465 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
4466 return Just(true); 4466 return Just(true);
4467 } 4467 }
4468 4468
4469 4469
4470 bool v8::Object::SetPrototype(Local<Value> value) { 4470 bool v8::Object::SetPrototype(Local<Value> value) {
4471 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4471 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4472 return SetPrototype(context, value).FromMaybe(false); 4472 return SetPrototype(context, value).FromMaybe(false);
4473 } 4473 }
4474 4474
4475 static bool HasInstanceInGlobalProxy(i::JSGlobalProxy* global_proxy,
4476 i::FunctionTemplateInfo* target_template) {
4477 auto* constructor_object = global_proxy->map()->GetConstructor();
4478 if (!constructor_object->IsJSFunction()) return false;
4479
4480 auto* constructor = i::JSFunction::cast(constructor_object);
4481 if (!constructor->shared()->function_data()->IsFunctionTemplateInfo())
4482 return false;
4483
4484 auto* proxy_constructor_template =
4485 i::FunctionTemplateInfo::cast(constructor->shared()->function_data());
4486 if (!proxy_constructor_template->prototype_template()->IsObjectTemplateInfo())
4487 return false;
4488
4489 auto* global_template = i::ObjectTemplateInfo::cast(
4490 proxy_constructor_template->prototype_template());
4491 // Iterate through the chain of inheriting function templates to
4492 // see if the required one occurs.
4493 for (i::Object* type = global_template->constructor();
4494 type->IsFunctionTemplateInfo();
4495 type = i::FunctionTemplateInfo::cast(type)->parent_template()) {
4496 if (type == target_template) return true;
4497 }
4498 // Didn't find the required type in the inheritance chain.
4499 return false;
4500 }
4475 4501
4476 Local<Object> v8::Object::FindInstanceInPrototypeChain( 4502 Local<Object> v8::Object::FindInstanceInPrototypeChain(
4477 v8::Local<FunctionTemplate> tmpl) { 4503 v8::Local<FunctionTemplate> tmpl) {
4478 auto isolate = Utils::OpenHandle(this)->GetIsolate(); 4504 auto self = Utils::OpenHandle(this);
4479 i::PrototypeIterator iter(isolate, *Utils::OpenHandle(this), 4505 auto isolate = self->GetIsolate();
4480 i::kStartAtReceiver); 4506 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver);
4481 auto tmpl_info = *Utils::OpenHandle(*tmpl); 4507 auto tmpl_info = *Utils::OpenHandle(*tmpl);
4482 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) { 4508 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) {
4483 iter.Advance(); 4509 iter.Advance();
4484 if (iter.IsAtEnd()) return Local<Object>(); 4510 if (iter.IsAtEnd()) {
4511 // Normally, a standard prototype walk is sufficient; however, global
4512 // proxies aren't directly constructed with the supplied template.
4513 // Normally, this is not a problem, because the prototype chain includes
4514 // the global object; however, a remote context has no global object.
4515 if (self->IsJSGlobalProxy() &&
4516 HasInstanceInGlobalProxy(i::JSGlobalProxy::cast(*self), tmpl_info))
4517 return Utils::ToLocal(self);
4518 return Local<Object>();
4519 }
4485 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>(); 4520 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>();
4486 } 4521 }
4487 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here. 4522 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here.
4488 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate)); 4523 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate));
4489 } 4524 }
4490 4525
4491 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) { 4526 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) {
4492 return GetPropertyNames( 4527 return GetPropertyNames(
4493 context, v8::KeyCollectionMode::kIncludePrototypes, 4528 context, v8::KeyCollectionMode::kIncludePrototypes,
4494 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS), 4529 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS),
(...skipping 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after
6542 return Utils::ToLocal(scope.CloseAndEscape(object)); 6577 return Utils::ToLocal(scope.CloseAndEscape(object));
6543 } 6578 }
6544 6579
6545 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { 6580 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
6546 auto self = Utils::OpenHandle(this); 6581 auto self = Utils::OpenHandle(this);
6547 auto obj = Utils::OpenHandle(*value); 6582 auto obj = Utils::OpenHandle(*value);
6548 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { 6583 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) {
6549 return true; 6584 return true;
6550 } 6585 }
6551 if (obj->IsJSGlobalProxy()) { 6586 if (obj->IsJSGlobalProxy()) {
6552 // If it's a global proxy object, then test with the global object. 6587 auto* global_proxy = i::JSGlobalProxy::cast(*obj);
6553 i::PrototypeIterator iter(i::JSObject::cast(*obj)->map()); 6588 // For global proxies, check the constructor's prototype instead. Remote
6554 if (iter.IsAtEnd()) return false; 6589 // global proxies have no global object to perform instance checks on, but
6555 return self->IsTemplateFor(iter.GetCurrent<i::JSGlobalObject>()); 6590 // the constructor's prototype's constructor corresponds to the original
6591 // template used to create the context.
6592 return HasInstanceInGlobalProxy(global_proxy, *self);
6556 } 6593 }
6557 return false; 6594 return false;
6558 } 6595 }
6559 6596
6560 6597
6561 Local<External> v8::External::New(Isolate* isolate, void* value) { 6598 Local<External> v8::External::New(Isolate* isolate, void* value) {
6562 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); 6599 STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
6563 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6600 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6564 LOG_API(i_isolate, External, New); 6601 LOG_API(i_isolate, External, New);
6565 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); 6602 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
(...skipping 3603 matching lines...) Expand 10 before | Expand all | Expand 10 after
10169 Address callback_address = 10206 Address callback_address =
10170 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10207 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10171 VMState<EXTERNAL> state(isolate); 10208 VMState<EXTERNAL> state(isolate);
10172 ExternalCallbackScope call_scope(isolate, callback_address); 10209 ExternalCallbackScope call_scope(isolate, callback_address);
10173 callback(info); 10210 callback(info);
10174 } 10211 }
10175 10212
10176 10213
10177 } // namespace internal 10214 } // namespace internal
10178 } // namespace v8 10215 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/unittests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698