Add toJS for JSC::PrivateName
https://bugs.webkit.org/show_bug.cgi?id=161522
Reviewed by Ryosuke Niwa.
Source/JavaScriptCore:
Add the export annotation.
And we perform refactoring RefPtr<SymbolImpl> => Ref<SymbolImpl> for PrivateName,
since PrivateName never holds null SymbolImpl pointer. And along with this change,
we changed SymbolImpl* to SymbolImpl& in PrivateName::uid() callers.
* runtime/Completion.cpp:
(JSC::createSymbolForEntryPointModule):
* runtime/IdentifierInlines.h:
(JSC::Identifier::fromUid):
* runtime/JSFunction.cpp:
(JSC::JSFunction::setFunctionName):
* runtime/PrivateName.h:
(JSC::PrivateName::PrivateName):
(JSC::PrivateName::uid): Ugly const_cast. But const annotation is meaningless for SymbolImpl.
StringImpl should be observed as an immutable object. (Of course, its hash members etc. are mutable.
But most of the users (One of the exceptions is the concurrent JIT compiling thread!) should not care about this.)
(JSC::PrivateName::operator==):
(JSC::PrivateName::operator!=):
* runtime/PropertyName.h:
(JSC::PropertyName::PropertyName):
* runtime/Symbol.cpp:
(JSC::Symbol::finishCreation):
* runtime/Symbol.h:
* runtime/SymbolConstructor.cpp:
(JSC::symbolConstructorKeyFor):
Source/WebCore:
JSC::PrivateName is the wrapper to create and hold the ES6 Symbol instance.
This patch adds toJS support for JSC::PrivateName.
Later, the module integration patch will use this feature to call
DeferredWrapper::{resolve,reject} with JSC::PrivateName.
* bindings/js/JSDOMBinding.h:
(WebCore::toJS):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@205335 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/Completion.cpp b/Source/JavaScriptCore/runtime/Completion.cpp
index 4a30d45..e94239f 100644
--- a/Source/JavaScriptCore/runtime/Completion.cpp
+++ b/Source/JavaScriptCore/runtime/Completion.cpp
@@ -142,7 +142,7 @@
{
// Generate the unique key for the source-provided module.
PrivateName privateName(PrivateName::Description, "EntryPointModule");
- return Symbol::create(vm, *privateName.uid());
+ return Symbol::create(vm, privateName.uid());
}
static JSInternalPromise* rejectPromise(ExecState* exec, JSGlobalObject* globalObject)
diff --git a/Source/JavaScriptCore/runtime/IdentifierInlines.h b/Source/JavaScriptCore/runtime/IdentifierInlines.h
index 52c11df..507c1d7 100644
--- a/Source/JavaScriptCore/runtime/IdentifierInlines.h
+++ b/Source/JavaScriptCore/runtime/IdentifierInlines.h
@@ -85,7 +85,7 @@
inline Identifier Identifier::fromUid(const PrivateName& name)
{
- return *name.uid();
+ return name.uid();
}
template<unsigned charactersCount>
diff --git a/Source/JavaScriptCore/runtime/JSFunction.cpp b/Source/JavaScriptCore/runtime/JSFunction.cpp
index 32e772f..be1ac0b 100644
--- a/Source/JavaScriptCore/runtime/JSFunction.cpp
+++ b/Source/JavaScriptCore/runtime/JSFunction.cpp
@@ -599,11 +599,11 @@
ASSERT(jsExecutable()->ecmaName().isNull());
String name;
if (value.isSymbol()) {
- SymbolImpl* uid = asSymbol(value)->privateName().uid();
- if (uid->isNullSymbol())
+ SymbolImpl& uid = asSymbol(value)->privateName().uid();
+ if (uid.isNullSymbol())
name = emptyString();
else
- name = makeString('[', String(uid), ']');
+ name = makeString('[', String(&uid), ']');
} else {
VM& vm = exec->vm();
JSString* jsStr = value.toString(exec);
diff --git a/Source/JavaScriptCore/runtime/PrivateName.h b/Source/JavaScriptCore/runtime/PrivateName.h
index f0bc60d..847545c 100644
--- a/Source/JavaScriptCore/runtime/PrivateName.h
+++ b/Source/JavaScriptCore/runtime/PrivateName.h
@@ -38,7 +38,7 @@
}
explicit PrivateName(SymbolImpl& uid)
- : m_uid(&uid)
+ : m_uid(uid)
{
}
@@ -48,13 +48,13 @@
{
}
- SymbolImpl* uid() const { return m_uid.get(); }
+ SymbolImpl& uid() const { return const_cast<SymbolImpl&>(m_uid.get()); }
- bool operator==(const PrivateName& other) const { return uid() == other.uid(); }
- bool operator!=(const PrivateName& other) const { return uid() != other.uid(); }
+ bool operator==(const PrivateName& other) const { return &uid() == &other.uid(); }
+ bool operator!=(const PrivateName& other) const { return &uid() != &other.uid(); }
private:
- RefPtr<SymbolImpl> m_uid;
+ Ref<SymbolImpl> m_uid;
};
}
diff --git a/Source/JavaScriptCore/runtime/PropertyName.h b/Source/JavaScriptCore/runtime/PropertyName.h
index 9d3cc2b..634ce38 100644
--- a/Source/JavaScriptCore/runtime/PropertyName.h
+++ b/Source/JavaScriptCore/runtime/PropertyName.h
@@ -45,7 +45,7 @@
}
PropertyName(const PrivateName& propertyName)
- : m_impl(propertyName.uid())
+ : m_impl(&propertyName.uid())
{
ASSERT(m_impl);
ASSERT(m_impl->isSymbol());
diff --git a/Source/JavaScriptCore/runtime/Symbol.cpp b/Source/JavaScriptCore/runtime/Symbol.cpp
index 666fc1c..5c35b81 100644
--- a/Source/JavaScriptCore/runtime/Symbol.cpp
+++ b/Source/JavaScriptCore/runtime/Symbol.cpp
@@ -58,7 +58,7 @@
Base::finishCreation(vm);
ASSERT(inherits(info()));
- vm.symbolImplToSymbolMap.set(m_privateName.uid(), this);
+ vm.symbolImplToSymbolMap.set(&m_privateName.uid(), this);
}
inline SymbolObject* SymbolObject::create(VM& vm, JSGlobalObject* globalObject, Symbol* symbol)
diff --git a/Source/JavaScriptCore/runtime/Symbol.h b/Source/JavaScriptCore/runtime/Symbol.h
index 933a2e5..8c70306 100644
--- a/Source/JavaScriptCore/runtime/Symbol.h
+++ b/Source/JavaScriptCore/runtime/Symbol.h
@@ -49,7 +49,7 @@
static Symbol* create(VM&);
static Symbol* create(ExecState*, JSString* description);
- static Symbol* create(VM&, SymbolImpl& uid);
+ JS_EXPORT_PRIVATE static Symbol* create(VM&, SymbolImpl& uid);
const PrivateName& privateName() const { return m_privateName; }
String descriptiveString() const;
diff --git a/Source/JavaScriptCore/runtime/SymbolConstructor.cpp b/Source/JavaScriptCore/runtime/SymbolConstructor.cpp
index df10562..ba2dfb0 100644
--- a/Source/JavaScriptCore/runtime/SymbolConstructor.cpp
+++ b/Source/JavaScriptCore/runtime/SymbolConstructor.cpp
@@ -117,12 +117,12 @@
if (!symbolValue.isSymbol())
return JSValue::encode(throwTypeError(exec, scope, SymbolKeyForTypeError));
- SymbolImpl* uid = asSymbol(symbolValue)->privateName().uid();
- if (!uid->symbolRegistry())
+ SymbolImpl& uid = asSymbol(symbolValue)->privateName().uid();
+ if (!uid.symbolRegistry())
return JSValue::encode(jsUndefined());
- ASSERT(uid->symbolRegistry() == &vm.symbolRegistry());
- return JSValue::encode(jsString(exec, vm.symbolRegistry().keyForSymbol(*uid)));
+ ASSERT(uid.symbolRegistry() == &vm.symbolRegistry());
+ return JSValue::encode(jsString(exec, vm.symbolRegistry().keyForSymbol(uid)));
}
} // namespace JSC