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

Side by Side Diff: src/api.cc

Issue 2677653002: Fix receiver checks for v8::Function on a remote context. (Closed)
Patch Set: . 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 | src/bootstrapper.cc » ('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 4476 matching lines...) Expand 10 before | Expand all | Expand 10 after
4487 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 4487 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
4488 return Just(true); 4488 return Just(true);
4489 } 4489 }
4490 4490
4491 4491
4492 bool v8::Object::SetPrototype(Local<Value> value) { 4492 bool v8::Object::SetPrototype(Local<Value> value) {
4493 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4493 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4494 return SetPrototype(context, value).FromMaybe(false); 4494 return SetPrototype(context, value).FromMaybe(false);
4495 } 4495 }
4496 4496
4497 static bool HasInstanceInGlobalProxy(i::JSGlobalProxy* global_proxy,
4498 i::FunctionTemplateInfo* target_template) {
4499 auto* constructor_object = global_proxy->map()->GetConstructor();
4500 if (!constructor_object->IsJSFunction()) return false;
4501
4502 auto* constructor = i::JSFunction::cast(constructor_object);
4503 if (!constructor->shared()->function_data()->IsFunctionTemplateInfo())
4504 return false;
4505
4506 auto* proxy_constructor_template =
4507 i::FunctionTemplateInfo::cast(constructor->shared()->function_data());
4508 if (!proxy_constructor_template->prototype_template()->IsObjectTemplateInfo())
4509 return false;
4510
4511 auto* global_template = i::ObjectTemplateInfo::cast(
4512 proxy_constructor_template->prototype_template());
4513 // Iterate through the chain of inheriting function templates to
4514 // see if the required one occurs.
4515 for (i::Object* type = global_template->constructor();
4516 type->IsFunctionTemplateInfo();
4517 type = i::FunctionTemplateInfo::cast(type)->parent_template()) {
4518 if (type == target_template) return true;
4519 }
4520 // Didn't find the required type in the inheritance chain.
4521 return false;
4522 }
4523
4524 Local<Object> v8::Object::FindInstanceInPrototypeChain( 4497 Local<Object> v8::Object::FindInstanceInPrototypeChain(
4525 v8::Local<FunctionTemplate> tmpl) { 4498 v8::Local<FunctionTemplate> tmpl) {
4526 auto self = Utils::OpenHandle(this); 4499 auto self = Utils::OpenHandle(this);
4527 auto isolate = self->GetIsolate(); 4500 auto isolate = self->GetIsolate();
4528 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver); 4501 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver);
4529 auto tmpl_info = *Utils::OpenHandle(*tmpl); 4502 auto tmpl_info = *Utils::OpenHandle(*tmpl);
4530 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) { 4503 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) {
4531 iter.Advance(); 4504 iter.Advance();
4532 if (iter.IsAtEnd()) { 4505 if (iter.IsAtEnd()) return Local<Object>();
4533 // Normally, a standard prototype walk is sufficient; however, global
4534 // proxies aren't directly constructed with the supplied template.
4535 // Normally, this is not a problem, because the prototype chain includes
4536 // the global object; however, a remote context has no global object.
4537 if (self->IsJSGlobalProxy() &&
4538 HasInstanceInGlobalProxy(i::JSGlobalProxy::cast(*self), tmpl_info))
4539 return Utils::ToLocal(self);
4540 return Local<Object>();
4541 }
4542 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>(); 4506 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>();
4543 } 4507 }
4544 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here. 4508 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here.
4545 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate)); 4509 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate));
4546 } 4510 }
4547 4511
4548 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) { 4512 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) {
4549 return GetPropertyNames( 4513 return GetPropertyNames(
4550 context, v8::KeyCollectionMode::kIncludePrototypes, 4514 context, v8::KeyCollectionMode::kIncludePrototypes,
4551 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS), 4515 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS),
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
6598 return Utils::ToLocal(scope.CloseAndEscape(object)); 6562 return Utils::ToLocal(scope.CloseAndEscape(object));
6599 } 6563 }
6600 6564
6601 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { 6565 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
6602 auto self = Utils::OpenHandle(this); 6566 auto self = Utils::OpenHandle(this);
6603 auto obj = Utils::OpenHandle(*value); 6567 auto obj = Utils::OpenHandle(*value);
6604 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { 6568 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) {
6605 return true; 6569 return true;
6606 } 6570 }
6607 if (obj->IsJSGlobalProxy()) { 6571 if (obj->IsJSGlobalProxy()) {
6608 auto* global_proxy = i::JSGlobalProxy::cast(*obj); 6572 // If it's a global proxy, then test with the global object. Note that the
6609 // For global proxies, check the constructor's prototype instead. Remote 6573 // inner global object may not necessarily be a JSGlobalObject.
6610 // global proxies have no global object to perform instance checks on, but 6574 i::PrototypeIterator iter(i::JSObject::cast(*obj)->map());
6611 // the constructor's prototype's constructor corresponds to the original 6575 // The global proxy should always have a prototype, as it is a bug to call
6612 // template used to create the context. 6576 // this on a detached JSGlobalProxy.
6613 return HasInstanceInGlobalProxy(global_proxy, *self); 6577 DCHECK(!iter.IsAtEnd());
6578 return self->IsTemplateFor(iter.GetCurrent<i::JSObject>());
6614 } 6579 }
6615 return false; 6580 return false;
6616 } 6581 }
6617 6582
6618 6583
6619 Local<External> v8::External::New(Isolate* isolate, void* value) { 6584 Local<External> v8::External::New(Isolate* isolate, void* value) {
6620 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); 6585 STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
6621 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6586 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6622 LOG_API(i_isolate, External, New); 6587 LOG_API(i_isolate, External, New);
6623 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); 6588 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
(...skipping 3656 matching lines...) Expand 10 before | Expand all | Expand 10 after
10280 Address callback_address = 10245 Address callback_address =
10281 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10246 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10282 VMState<EXTERNAL> state(isolate); 10247 VMState<EXTERNAL> state(isolate);
10283 ExternalCallbackScope call_scope(isolate, callback_address); 10248 ExternalCallbackScope call_scope(isolate, callback_address);
10284 callback(info); 10249 callback(info);
10285 } 10250 }
10286 10251
10287 10252
10288 } // namespace internal 10253 } // namespace internal
10289 } // namespace v8 10254 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698