OLD | NEW |
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 7623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7634 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { | 7634 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { |
7635 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7635 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7636 LOG_API(i_isolate, Symbol, New); | 7636 LOG_API(i_isolate, Symbol, New); |
7637 ENTER_V8(i_isolate); | 7637 ENTER_V8(i_isolate); |
7638 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); | 7638 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); |
7639 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); | 7639 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); |
7640 return Utils::ToLocal(result); | 7640 return Utils::ToLocal(result); |
7641 } | 7641 } |
7642 | 7642 |
7643 | 7643 |
7644 static i::Handle<i::Symbol> SymbolFor(i::Isolate* isolate, | |
7645 i::Handle<i::String> name, | |
7646 i::Handle<i::String> part, | |
7647 bool private_symbol) { | |
7648 i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry(); | |
7649 i::Handle<i::JSObject> symbols = | |
7650 i::Handle<i::JSObject>::cast( | |
7651 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); | |
7652 i::Handle<i::Object> symbol = | |
7653 i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked(); | |
7654 if (!symbol->IsSymbol()) { | |
7655 DCHECK(symbol->IsUndefined(isolate)); | |
7656 if (private_symbol) | |
7657 symbol = isolate->factory()->NewPrivateSymbol(); | |
7658 else | |
7659 symbol = isolate->factory()->NewSymbol(); | |
7660 i::Handle<i::Symbol>::cast(symbol)->set_name(*name); | |
7661 i::Object::SetPropertyOrElement(symbols, name, symbol, i::STRICT).Assert(); | |
7662 } | |
7663 return i::Handle<i::Symbol>::cast(symbol); | |
7664 } | |
7665 | |
7666 | |
7667 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { | 7644 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { |
7668 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7645 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7669 i::Handle<i::String> i_name = Utils::OpenHandle(*name); | 7646 i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
7670 i::Handle<i::String> part = i_isolate->factory()->for_string(); | 7647 return Utils::ToLocal(i_isolate->SymbolFor( |
7671 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part, false)); | 7648 i::Heap::kPublicSymbolTableRootIndex, i_name, false)); |
7672 } | 7649 } |
7673 | 7650 |
7674 | 7651 |
7675 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { | 7652 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { |
7676 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7653 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7677 i::Handle<i::String> i_name = Utils::OpenHandle(*name); | 7654 i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
7678 i::Handle<i::String> part = i_isolate->factory()->for_api_string(); | 7655 return Utils::ToLocal( |
7679 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part, false)); | 7656 i_isolate->SymbolFor(i::Heap::kApiSymbolTableRootIndex, i_name, false)); |
7680 } | 7657 } |
7681 | 7658 |
7682 | 7659 |
7683 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { | 7660 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { |
7684 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7661 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7685 return Utils::ToLocal(i_isolate->factory()->iterator_symbol()); | 7662 return Utils::ToLocal(i_isolate->factory()->iterator_symbol()); |
7686 } | 7663 } |
7687 | 7664 |
7688 | 7665 |
7689 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { | 7666 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { |
(...skipping 21 matching lines...) Expand all Loading... |
7711 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); | 7688 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
7712 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); | 7689 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); |
7713 Local<Symbol> result = Utils::ToLocal(symbol); | 7690 Local<Symbol> result = Utils::ToLocal(symbol); |
7714 return v8::Local<Private>(reinterpret_cast<Private*>(*result)); | 7691 return v8::Local<Private>(reinterpret_cast<Private*>(*result)); |
7715 } | 7692 } |
7716 | 7693 |
7717 | 7694 |
7718 Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) { | 7695 Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) { |
7719 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7696 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7720 i::Handle<i::String> i_name = Utils::OpenHandle(*name); | 7697 i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
7721 i::Handle<i::String> part = i_isolate->factory()->private_api_string(); | 7698 Local<Symbol> result = Utils::ToLocal(i_isolate->SymbolFor( |
7722 Local<Symbol> result = | 7699 i::Heap::kApiPrivateSymbolTableRootIndex, i_name, true)); |
7723 Utils::ToLocal(SymbolFor(i_isolate, i_name, part, true)); | |
7724 return v8::Local<Private>(reinterpret_cast<Private*>(*result)); | 7700 return v8::Local<Private>(reinterpret_cast<Private*>(*result)); |
7725 } | 7701 } |
7726 | 7702 |
7727 | 7703 |
7728 Local<Number> v8::Number::New(Isolate* isolate, double value) { | 7704 Local<Number> v8::Number::New(Isolate* isolate, double value) { |
7729 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7705 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7730 if (std::isnan(value)) { | 7706 if (std::isnan(value)) { |
7731 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | 7707 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
7732 value = std::numeric_limits<double>::quiet_NaN(); | 7708 value = std::numeric_limits<double>::quiet_NaN(); |
7733 } | 7709 } |
(...skipping 2122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9856 Address callback_address = | 9832 Address callback_address = |
9857 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9833 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9858 VMState<EXTERNAL> state(isolate); | 9834 VMState<EXTERNAL> state(isolate); |
9859 ExternalCallbackScope call_scope(isolate, callback_address); | 9835 ExternalCallbackScope call_scope(isolate, callback_address); |
9860 callback(info); | 9836 callback(info); |
9861 } | 9837 } |
9862 | 9838 |
9863 | 9839 |
9864 } // namespace internal | 9840 } // namespace internal |
9865 } // namespace v8 | 9841 } // namespace v8 |
OLD | NEW |