- Revision
- 154434
- Author
- [email protected]
- Date
- 2013-08-21 18:04:37 -0700 (Wed, 21 Aug 2013)
Log Message
Clarify var/const/function declaration
https://bugs.webkit.org/show_bug.cgi?id=120144
Reviewed by Sam Weinig.
Add methods to JSGlobalObject to declare vars, consts, and functions.
* runtime/Executable.cpp:
(JSC::ProgramExecutable::initializeGlobalProperties):
* runtime/Executable.h:
- Moved declaration code to JSGlobalObject
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::addGlobalVar):
- internal implementation of addVar, addConst, addFunction
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::addVar):
(JSC::JSGlobalObject::addConst):
(JSC::JSGlobalObject::addFunction):
- Added methods to declare vars, consts, and functions
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (154433 => 154434)
--- trunk/Source/_javascript_Core/ChangeLog 2013-08-22 01:00:06 UTC (rev 154433)
+++ trunk/Source/_javascript_Core/ChangeLog 2013-08-22 01:04:37 UTC (rev 154434)
@@ -1,3 +1,25 @@
+2013-08-21 Gavin Barraclough <[email protected]>
+
+ Clarify var/const/function declaration
+ https://bugs.webkit.org/show_bug.cgi?id=120144
+
+ Reviewed by Sam Weinig.
+
+ Add methods to JSGlobalObject to declare vars, consts, and functions.
+
+ * runtime/Executable.cpp:
+ (JSC::ProgramExecutable::initializeGlobalProperties):
+ * runtime/Executable.h:
+ - Moved declaration code to JSGlobalObject
+ * runtime/JSGlobalObject.cpp:
+ (JSC::JSGlobalObject::addGlobalVar):
+ - internal implementation of addVar, addConst, addFunction
+ * runtime/JSGlobalObject.h:
+ (JSC::JSGlobalObject::addVar):
+ (JSC::JSGlobalObject::addConst):
+ (JSC::JSGlobalObject::addFunction):
+ - Added methods to declare vars, consts, and functions
+
2013-08-21 Yi Shen <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=119900
Modified: trunk/Source/_javascript_Core/runtime/Executable.cpp (154433 => 154434)
--- trunk/Source/_javascript_Core/runtime/Executable.cpp 2013-08-22 01:00:06 UTC (rev 154433)
+++ trunk/Source/_javascript_Core/runtime/Executable.cpp 2013-08-22 01:04:37 UTC (rev 154434)
@@ -371,24 +371,6 @@
#endif
}
-int ProgramExecutable::addGlobalVar(JSGlobalObject* globalObject, const Identifier& ident, ConstantMode constantMode, FunctionMode functionMode)
-{
- // Try to share the symbolTable if possible
- SharedSymbolTable* symbolTable = globalObject->symbolTable();
- UNUSED_PARAM(functionMode);
- ConcurrentJITLocker locker(symbolTable->m_lock);
- int index = symbolTable->size(locker);
- SymbolTableEntry newEntry(index, (constantMode == IsConstant) ? ReadOnly : 0);
- if (functionMode == IsFunctionToSpecialize)
- newEntry.attemptToWatch();
- SymbolTable::Map::AddResult result = symbolTable->add(locker, ident.impl(), newEntry);
- if (!result.isNewEntry) {
- result.iterator->value.notifyWrite();
- index = result.iterator->value.getIndex();
- }
- return index;
-}
-
JSObject* ProgramExecutable::initializeGlobalProperties(VM& vm, CallFrame* callFrame, JSScope* scope)
{
RELEASE_ASSERT(scope);
@@ -415,20 +397,16 @@
CallFrame* globalExec = globalObject->globalExec();
for (size_t i = 0; i < functionDeclarations.size(); ++i) {
- bool propertyDidExist = globalObject->removeDirect(vm, functionDeclarations[i].first); // Newly declared functions overwrite existing properties.
UnlinkedFunctionExecutable* unlinkedFunctionExecutable = functionDeclarations[i].second.get();
JSValue value = JSFunction::create(globalExec, unlinkedFunctionExecutable->link(vm, m_source, lineNo(), 0), scope);
- int index = addGlobalVar(globalObject, functionDeclarations[i].first, IsVariable,
- !propertyDidExist ? IsFunctionToSpecialize : NotFunctionOrNotSpecializable);
- globalObject->registerAt(index).set(vm, globalObject, value);
+ globalObject->addFunction(callFrame, functionDeclarations[i].first, value);
}
for (size_t i = 0; i < variableDeclarations.size(); ++i) {
- if (globalObject->hasProperty(globalExec, variableDeclarations[i].first))
- continue;
- addGlobalVar(globalObject, variableDeclarations[i].first,
- (variableDeclarations[i].second & DeclarationStacks::IsConstant) ? IsConstant : IsVariable,
- NotFunctionOrNotSpecializable);
+ if (variableDeclarations[i].second & DeclarationStacks::IsConstant)
+ globalObject->addConst(callFrame, variableDeclarations[i].first);
+ else
+ globalObject->addVar(callFrame, variableDeclarations[i].first);
}
return 0;
}
Modified: trunk/Source/_javascript_Core/runtime/Executable.h (154433 => 154434)
--- trunk/Source/_javascript_Core/runtime/Executable.h 2013-08-22 01:00:06 UTC (rev 154433)
+++ trunk/Source/_javascript_Core/runtime/Executable.h 2013-08-22 01:04:37 UTC (rev 154434)
@@ -561,10 +561,6 @@
ProgramExecutable(ExecState*, const SourceCode&);
- enum ConstantMode { IsConstant, IsVariable };
- enum FunctionMode { IsFunctionToSpecialize, NotFunctionOrNotSpecializable };
- int addGlobalVar(JSGlobalObject*, const Identifier&, ConstantMode, FunctionMode);
-
JSObject* compileInternal(ExecState*, JSScope*, JITCode::JITType, CompilationResult* = 0, unsigned bytecodeIndex = UINT_MAX);
static void visitChildren(JSCell*, SlotVisitor&);
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (154433 => 154434)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2013-08-22 01:00:06 UTC (rev 154433)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2013-08-22 01:04:37 UTC (rev 154434)
@@ -196,6 +196,20 @@
return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
}
+int JSGlobalObject::addGlobalVar(const Identifier& ident, ConstantMode constantMode, FunctionMode functionMode)
+{
+ ConcurrentJITLocker locker(symbolTable()->m_lock);
+ int index = symbolTable()->size(locker);
+ SymbolTableEntry newEntry(index, (constantMode == IsConstant) ? ReadOnly : 0);
+ if (functionMode == IsFunctionToSpecialize)
+ newEntry.attemptToWatch();
+ SymbolTable::Map::AddResult result = symbolTable()->add(locker, ident.impl(), newEntry);
+ if (!result.isNewEntry) {
+ result.iterator->value.notifyWrite();
+ index = result.iterator->value.getIndex();
+ }
+ return index;
+}
static inline JSObject* lastInPrototypeChain(JSObject* object)
{
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (154433 => 154434)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h 2013-08-22 01:00:06 UTC (rev 154433)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h 2013-08-22 01:04:37 UTC (rev 154434)
@@ -239,6 +239,10 @@
init(thisValue);
}
+ enum ConstantMode { IsConstant, IsVariable };
+ enum FunctionMode { IsFunctionToSpecialize, NotFunctionOrNotSpecializable };
+ int addGlobalVar(const Identifier&, ConstantMode, FunctionMode);
+
public:
JS_EXPORT_PRIVATE ~JSGlobalObject();
JS_EXPORT_PRIVATE static void destroy(JSCell*);
@@ -261,6 +265,23 @@
// lookups prior to initializing the properties
bool symbolTableHasProperty(PropertyName);
+ void addVar(ExecState* exec, const Identifier& propertyName)
+ {
+ if (!hasProperty(exec, propertyName))
+ addGlobalVar(propertyName, IsVariable, NotFunctionOrNotSpecializable);
+ }
+ void addConst(ExecState* exec, const Identifier& propertyName)
+ {
+ if (!hasProperty(exec, propertyName))
+ addGlobalVar(propertyName, IsConstant, NotFunctionOrNotSpecializable);
+ }
+ void addFunction(ExecState* exec, const Identifier& propertyName, JSValue value)
+ {
+ bool propertyDidExist = removeDirect(exec->vm(), propertyName); // Newly declared functions overwrite existing properties.
+ int index = addGlobalVar(propertyName, IsVariable, !propertyDidExist ? IsFunctionToSpecialize : NotFunctionOrNotSpecializable);
+ registerAt(index).set(exec->vm(), this, value);
+ }
+
// The following accessors return pristine values, even if a script
// replaces the global object's associated property.