Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 9093f4dd30d1c1023468da715d84a212953cbd26..35a7e5f4382e80789d17bb6f2a002fbdfcbb8d73 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -6152,43 +6152,57 @@ Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { |
} |
-Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { |
- i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
- i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
- i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry(); |
- i::Handle<i::String> part = i_isolate->factory()->for_string(); |
+static i::Handle<i::Symbol> SymbolFor(i::Isolate* isolate, |
+ i::Handle<i::String> name, |
+ i::Handle<i::String> part) { |
+ i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry(); |
i::Handle<i::JSObject> symbols = |
i::Handle<i::JSObject>::cast( |
i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); |
i::Handle<i::Object> symbol = |
- i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked(); |
+ i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked(); |
if (!symbol->IsSymbol()) { |
DCHECK(symbol->IsUndefined()); |
- symbol = i_isolate->factory()->NewSymbol(); |
- i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name); |
- i::JSObject::SetProperty(symbols, i_name, symbol, i::STRICT).Assert(); |
+ symbol = isolate->factory()->NewSymbol(); |
+ i::Handle<i::Symbol>::cast(symbol)->set_name(*name); |
+ i::JSObject::SetProperty(symbols, name, symbol, i::STRICT).Assert(); |
} |
- return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol)); |
+ return i::Handle<i::Symbol>::cast(symbol); |
+} |
+ |
+ |
+Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { |
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
+ i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
+ i::Handle<i::String> part = i_isolate->factory()->for_string(); |
+ return Utils::ToLocal(SymbolFor(i_isolate, i_name, part)); |
} |
Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { |
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
i::Handle<i::String> i_name = Utils::OpenHandle(*name); |
- i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry(); |
i::Handle<i::String> part = i_isolate->factory()->for_api_string(); |
- i::Handle<i::JSObject> symbols = |
- i::Handle<i::JSObject>::cast( |
- i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); |
- i::Handle<i::Object> symbol = |
- i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked(); |
- if (!symbol->IsSymbol()) { |
- DCHECK(symbol->IsUndefined()); |
- symbol = i_isolate->factory()->NewSymbol(); |
- i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name); |
- i::JSObject::SetProperty(symbols, i_name, symbol, i::STRICT).Assert(); |
- } |
- return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol)); |
+ return Utils::ToLocal(SymbolFor(i_isolate, i_name, part)); |
+} |
+ |
+ |
+static Local<Symbol> GetWellKnownSymbol(Isolate* isolate, const char* name) { |
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
+ i::Handle<i::String> i_name = |
+ Utils::OpenHandle(*String::NewFromUtf8(isolate, name)); |
+ i::Handle<i::String> part = i_isolate->factory()->for_intern_string(); |
+ return Utils::ToLocal(SymbolFor(i_isolate, i_name, part)); |
+} |
+ |
+ |
+Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { |
+ return GetWellKnownSymbol(isolate, "Symbol.iterator"); |
+} |
+ |
+ |
+Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { |
+ return GetWellKnownSymbol(isolate, "Symbol.unscopables"); |
} |