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

Side by Side Diff: src/api.cc

Issue 2551763003: v8::Private::ForApi should be context-independent. (Closed)
Patch Set: Created 4 years 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 | « BUILD.gn ('k') | src/bootstrapper.cc » ('j') | src/heap/heap.h » ('J')
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 7624 matching lines...) Expand 10 before | Expand all | Expand 10 after
7635 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { 7635 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
7636 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7636 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7637 LOG_API(i_isolate, Symbol, New); 7637 LOG_API(i_isolate, Symbol, New);
7638 ENTER_V8(i_isolate); 7638 ENTER_V8(i_isolate);
7639 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); 7639 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
7640 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); 7640 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
7641 return Utils::ToLocal(result); 7641 return Utils::ToLocal(result);
7642 } 7642 }
7643 7643
7644 7644
7645 static i::Handle<i::Symbol> SymbolFor(i::Isolate* isolate,
7646 i::Handle<i::String> name,
7647 i::Handle<i::String> part,
7648 bool private_symbol) {
7649 i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry();
7650 i::Handle<i::JSObject> symbols =
7651 i::Handle<i::JSObject>::cast(
7652 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
7653 i::Handle<i::Object> symbol =
7654 i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked();
7655 if (!symbol->IsSymbol()) {
7656 DCHECK(symbol->IsUndefined(isolate));
7657 if (private_symbol)
7658 symbol = isolate->factory()->NewPrivateSymbol();
7659 else
7660 symbol = isolate->factory()->NewSymbol();
7661 i::Handle<i::Symbol>::cast(symbol)->set_name(*name);
7662 i::Object::SetPropertyOrElement(symbols, name, symbol, i::STRICT).Assert();
7663 }
7664 return i::Handle<i::Symbol>::cast(symbol);
7665 }
7666
7667
7668 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { 7645 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) {
7669 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7646 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7670 i::Handle<i::String> i_name = Utils::OpenHandle(*name); 7647 i::Handle<i::String> i_name = Utils::OpenHandle(*name);
7671 i::Handle<i::String> part = i_isolate->factory()->for_string(); 7648 return Utils::ToLocal(i_isolate->SymbolFor(
7672 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part, false)); 7649 i::Heap::kPublicSymbolTableRootIndex, i_name, false));
7673 } 7650 }
7674 7651
7675 7652
7676 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { 7653 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) {
7677 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7654 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7678 i::Handle<i::String> i_name = Utils::OpenHandle(*name); 7655 i::Handle<i::String> i_name = Utils::OpenHandle(*name);
7679 i::Handle<i::String> part = i_isolate->factory()->for_api_string(); 7656 return Utils::ToLocal(
7680 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part, false)); 7657 i_isolate->SymbolFor(i::Heap::kApiSymbolTableRootIndex, i_name, false));
7681 } 7658 }
7682 7659
7683 7660
7684 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { 7661 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) {
7685 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7662 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7686 return Utils::ToLocal(i_isolate->factory()->iterator_symbol()); 7663 return Utils::ToLocal(i_isolate->factory()->iterator_symbol());
7687 } 7664 }
7688 7665
7689 7666
7690 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { 7667 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) {
(...skipping 21 matching lines...) Expand all
7712 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); 7689 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
7713 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); 7690 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
7714 Local<Symbol> result = Utils::ToLocal(symbol); 7691 Local<Symbol> result = Utils::ToLocal(symbol);
7715 return v8::Local<Private>(reinterpret_cast<Private*>(*result)); 7692 return v8::Local<Private>(reinterpret_cast<Private*>(*result));
7716 } 7693 }
7717 7694
7718 7695
7719 Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) { 7696 Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) {
7720 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7697 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7721 i::Handle<i::String> i_name = Utils::OpenHandle(*name); 7698 i::Handle<i::String> i_name = Utils::OpenHandle(*name);
7722 i::Handle<i::String> part = i_isolate->factory()->private_api_string(); 7699 Local<Symbol> result = Utils::ToLocal(i_isolate->SymbolFor(
7723 Local<Symbol> result = 7700 i::Heap::kApiPrivateSymbolTableRootIndex, i_name, true));
7724 Utils::ToLocal(SymbolFor(i_isolate, i_name, part, true));
7725 return v8::Local<Private>(reinterpret_cast<Private*>(*result)); 7701 return v8::Local<Private>(reinterpret_cast<Private*>(*result));
7726 } 7702 }
7727 7703
7728 7704
7729 Local<Number> v8::Number::New(Isolate* isolate, double value) { 7705 Local<Number> v8::Number::New(Isolate* isolate, double value) {
7730 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 7706 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
7731 if (std::isnan(value)) { 7707 if (std::isnan(value)) {
7732 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 7708 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
7733 value = std::numeric_limits<double>::quiet_NaN(); 7709 value = std::numeric_limits<double>::quiet_NaN();
7734 } 7710 }
(...skipping 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after
9864 Address callback_address = 9840 Address callback_address =
9865 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9841 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9866 VMState<EXTERNAL> state(isolate); 9842 VMState<EXTERNAL> state(isolate);
9867 ExternalCallbackScope call_scope(isolate, callback_address); 9843 ExternalCallbackScope call_scope(isolate, callback_address);
9868 callback(info); 9844 callback(info);
9869 } 9845 }
9870 9846
9871 9847
9872 } // namespace internal 9848 } // namespace internal
9873 } // namespace v8 9849 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/bootstrapper.cc » ('j') | src/heap/heap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698