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 6134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6145 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6145 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6146 EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); | 6146 EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); |
6147 LOG_API(i_isolate, "Symbol::New()"); | 6147 LOG_API(i_isolate, "Symbol::New()"); |
6148 ENTER_V8(i_isolate); | 6148 ENTER_V8(i_isolate); |
6149 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); | 6149 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); |
6150 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); | 6150 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); |
6151 return Utils::ToLocal(result); | 6151 return Utils::ToLocal(result); |
6152 } | 6152 } |
6153 | 6153 |
6154 | 6154 |
| 6155 static i::Handle<i::Symbol> SymbolFor(i::Isolate* isolate, |
| 6156 i::Handle<i::String> name, |
| 6157 i::Handle<i::String> part) { |
| 6158 i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry(); |
| 6159 i::Handle<i::JSObject> symbols = |
| 6160 i::Handle<i::JSObject>::cast( |
| 6161 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); |
| 6162 i::Handle<i::Object> symbol = |
| 6163 i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked(); |
| 6164 if (!symbol->IsSymbol()) { |
| 6165 DCHECK(symbol->IsUndefined()); |
| 6166 symbol = isolate->factory()->NewSymbol(); |
| 6167 i::Handle<i::Symbol>::cast(symbol)->set_name(*name); |
| 6168 i::JSObject::SetProperty(symbols, name, symbol, i::STRICT).Assert(); |
| 6169 } |
| 6170 return i::Handle<i::Symbol>::cast(symbol); |
| 6171 } |
| 6172 |
| 6173 |
6155 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { | 6174 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { |
6156 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6175 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6157 i::Handle<i::String> i_name = Utils::OpenHandle(*name); | 6176 i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
6158 i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry(); | |
6159 i::Handle<i::String> part = i_isolate->factory()->for_string(); | 6177 i::Handle<i::String> part = i_isolate->factory()->for_string(); |
6160 i::Handle<i::JSObject> symbols = | 6178 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part)); |
6161 i::Handle<i::JSObject>::cast( | |
6162 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); | |
6163 i::Handle<i::Object> symbol = | |
6164 i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked(); | |
6165 if (!symbol->IsSymbol()) { | |
6166 DCHECK(symbol->IsUndefined()); | |
6167 symbol = i_isolate->factory()->NewSymbol(); | |
6168 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name); | |
6169 i::JSObject::SetProperty(symbols, i_name, symbol, i::STRICT).Assert(); | |
6170 } | |
6171 return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol)); | |
6172 } | 6179 } |
6173 | 6180 |
6174 | 6181 |
6175 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { | 6182 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { |
6176 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6183 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6177 i::Handle<i::String> i_name = Utils::OpenHandle(*name); | 6184 i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
6178 i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry(); | |
6179 i::Handle<i::String> part = i_isolate->factory()->for_api_string(); | 6185 i::Handle<i::String> part = i_isolate->factory()->for_api_string(); |
6180 i::Handle<i::JSObject> symbols = | 6186 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part)); |
6181 i::Handle<i::JSObject>::cast( | |
6182 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); | |
6183 i::Handle<i::Object> symbol = | |
6184 i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked(); | |
6185 if (!symbol->IsSymbol()) { | |
6186 DCHECK(symbol->IsUndefined()); | |
6187 symbol = i_isolate->factory()->NewSymbol(); | |
6188 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name); | |
6189 i::JSObject::SetProperty(symbols, i_name, symbol, i::STRICT).Assert(); | |
6190 } | |
6191 return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol)); | |
6192 } | 6187 } |
6193 | 6188 |
6194 | 6189 |
| 6190 static Local<Symbol> GetWellKnownSymbol(Isolate* isolate, const char* name) { |
| 6191 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6192 i::Handle<i::String> i_name = |
| 6193 Utils::OpenHandle(*String::NewFromUtf8(isolate, name)); |
| 6194 i::Handle<i::String> part = i_isolate->factory()->for_intern_string(); |
| 6195 return Utils::ToLocal(SymbolFor(i_isolate, i_name, part)); |
| 6196 } |
| 6197 |
| 6198 |
| 6199 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { |
| 6200 return GetWellKnownSymbol(isolate, "Symbol.iterator"); |
| 6201 } |
| 6202 |
| 6203 |
| 6204 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { |
| 6205 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); |
| 6206 } |
| 6207 |
| 6208 |
6195 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { | 6209 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { |
6196 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6210 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6197 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()"); | 6211 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()"); |
6198 LOG_API(i_isolate, "Private::New()"); | 6212 LOG_API(i_isolate, "Private::New()"); |
6199 ENTER_V8(i_isolate); | 6213 ENTER_V8(i_isolate); |
6200 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); | 6214 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
6201 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); | 6215 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); |
6202 Local<Symbol> result = Utils::ToLocal(symbol); | 6216 Local<Symbol> result = Utils::ToLocal(symbol); |
6203 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); | 6217 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); |
6204 } | 6218 } |
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7645 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7659 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7646 Address callback_address = | 7660 Address callback_address = |
7647 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7661 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7648 VMState<EXTERNAL> state(isolate); | 7662 VMState<EXTERNAL> state(isolate); |
7649 ExternalCallbackScope call_scope(isolate, callback_address); | 7663 ExternalCallbackScope call_scope(isolate, callback_address); |
7650 callback(info); | 7664 callback(info); |
7651 } | 7665 } |
7652 | 7666 |
7653 | 7667 |
7654 } } // namespace v8::internal | 7668 } } // namespace v8::internal |
OLD | NEW |