Reviewers: arv,
Description:
Add v8::Symbol::ForInternal.
Add v8::Symbol::ForInternal to access internal symbols such as
Symbol.iterator.
BUG=341423
Please review this at https://codereview.chromium.org/483173002/
SVN Base: git://github.com/v8/v8.git@master
Affected files (+35, -0 lines):
M include/v8.h
M src/api.cc
M src/heap/heap.h
M test/cctest/test-api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
ac3c6173ecc96f2383cedc65fa2ae1a92c8b3a8c..a7084273fbdc6500769b4cd95b86ee17d97f5235
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1960,7 +1960,13 @@ class V8_EXPORT Symbol : public Primitive {
// registry that is not accessible by (and cannot clash with) JavaScript
code.
static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
+ // Retrieve a global symbol. Similar to |For|, but using a separate
+ // registry for internal use. Well-known symbols such as Symbol.iterator
+ // are stored in this registry.
+ static Local<Symbol> ForInternal(Isolate* isolate, Local<String> name);
+
V8_INLINE static Symbol* Cast(v8::Value* obj);
+
private:
Symbol();
static void CheckCast(v8::Value* obj);
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
9093f4dd30d1c1023468da715d84a212953cbd26..ef0e4f2d28654c4a4c5fe331c028b0be6608fe49
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6192,6 +6192,25 @@ Local<Symbol> v8::Symbol::ForApi(Isolate* isolate,
Local<String> name) {
}
+Local<Symbol> v8::Symbol::ForInternal(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_intern_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));
+}
+
+
Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
EnsureInitializedForIsolate(i_isolate, "v8::Private::New()");
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index
d9d9d1a1945dac466b3f220fe37c4bdeba08a06b..093660a768604efae771441afdba25d9de210a63
100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -294,6 +294,7 @@ namespace internal {
V(Symbol_string, "Symbol") \
V(for_string, "for") \
V(for_api_string, "for_api") \
+ V(for_intern_string, "for_intern") \
V(private_api_string, "private_api") \
V(private_intern_string, "private_intern") \
V(Date_string, "Date") \
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
f61400706b35bb7bfadb72aaa8b0b6d4663eade5..b503332369e29ed6d0785c1c458efb888be9e21d
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -2914,6 +2914,10 @@ THREADED_TEST(GlobalSymbols) {
CHECK(glob_api2->SameValue(glob_api));
CHECK(!glob_api->SameValue(glob));
+ v8::Local<String> iterator_name = v8_str("Symbol.iterator");
+ v8::Local<v8::Symbol> iterator =
+ v8::Symbol::ForInternal(isolate, iterator_name);
+
v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name);
CHECK(!sym->SameValue(glob));
@@ -2921,6 +2925,11 @@ THREADED_TEST(GlobalSymbols) {
v8::Local<Value> sym2 = env->Global()->Get(v8_str("sym2"));
CHECK(sym2->SameValue(glob));
CHECK(!sym2->SameValue(glob_api));
+
+ CompileRun("var sym3 = Symbol.iterator");
+ v8::Local<Value> sym3 = env->Global()->Get(v8_str("sym3"));
+ CHECK(!sym3.IsEmpty());
+ CHECK(sym3->SameValue(iterator));
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.