Commit 23fc88db authored by mjs's avatar mjs

JavaScriptCore:

        Reviewed by Mark.
        
        - avoid static construction (and global variable access) in a smarter, more portable way,
        to later enable MUTLI_THREAD mode to work on other platforms and compilers.
        
        * kjs/CommonIdentifiers.cpp: Added. New class to hold all the shared identifiers.
        (KJS::CommonIdentifiers::CommonIdentifiers):
        (KJS::CommonIdentifiers::shared):
        * kjs/CommonIdentifiers.h: Added.

        * kjs/ExecState.h:
        (KJS::ExecState::propertyNames): Hand the CommonIdentifiers instance here for easy access.
        (KJS::ExecState::ExecState):

        * API/JSObjectRef.cpp:
        (JSObjectMakeConstructor):
        * CMakeLists.txt:
        * JavaScriptCore.exp:
        * JavaScriptCore.pri:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
        * JavaScriptCore.xcodeproj/project.pbxproj:
        * JavaScriptCoreSources.bkl:
        * bindings/runtime_array.cpp:
        (RuntimeArray::getOwnPropertySlot):
        (RuntimeArray::put):
        * bindings/runtime_method.cpp:
        (RuntimeMethod::getOwnPropertySlot):
        * kjs/array_object.cpp:
        (ArrayInstance::getOwnPropertySlot):
        (ArrayInstance::put):
        (ArrayInstance::deleteProperty):
        (ArrayProtoFunc::ArrayProtoFunc):
        (ArrayProtoFunc::callAsFunction):
        (ArrayObjectImp::ArrayObjectImp):
        * kjs/bool_object.cpp:
        (BooleanPrototype::BooleanPrototype):
        (BooleanProtoFunc::BooleanProtoFunc):
        (BooleanProtoFunc::callAsFunction):
        (BooleanObjectImp::BooleanObjectImp):
        * kjs/completion.h:
        (KJS::Completion::Completion):
        * kjs/date_object.cpp:
        (KJS::DateProtoFunc::DateProtoFunc):
        (KJS::DateObjectImp::DateObjectImp):
        (KJS::DateObjectFuncImp::DateObjectFuncImp):
        * kjs/error_object.cpp:
        (ErrorPrototype::ErrorPrototype):
        (ErrorProtoFunc::ErrorProtoFunc):
        (ErrorProtoFunc::callAsFunction):
        (ErrorObjectImp::ErrorObjectImp):
        (ErrorObjectImp::construct):
        (NativeErrorPrototype::NativeErrorPrototype):
        (NativeErrorImp::NativeErrorImp):
        (NativeErrorImp::construct):
        (NativeErrorImp::callAsFunction):
        * kjs/function.cpp:
        (KJS::FunctionImp::getOwnPropertySlot):
        (KJS::FunctionImp::put):
        (KJS::FunctionImp::deleteProperty):
        (KJS::FunctionImp::getParameterName):
        (KJS::DeclaredFunctionImp::construct):
        (KJS::IndexToNameMap::unMap):
        (KJS::Arguments::Arguments):
        (KJS::ActivationImp::getOwnPropertySlot):
        (KJS::ActivationImp::deleteProperty):
        (KJS::GlobalFuncImp::GlobalFuncImp):
        * kjs/function_object.cpp:
        (FunctionPrototype::FunctionPrototype):
        (FunctionProtoFunc::FunctionProtoFunc):
        (FunctionProtoFunc::callAsFunction):
        (FunctionObjectImp::FunctionObjectImp):
        (FunctionObjectImp::construct):
        * kjs/grammar.y:
        * kjs/identifier.cpp:
        * kjs/identifier.h:
        * kjs/interpreter.cpp:
        (KJS::Interpreter::init):
        (KJS::Interpreter::initGlobalObject):
        * kjs/interpreter.h:
        * kjs/lookup.h:
        * kjs/math_object.cpp:
        (MathFuncImp::MathFuncImp):
        * kjs/nodes.cpp:
        (ArrayNode::evaluate):
        (FuncDeclNode::processFuncDecl):
        (FuncExprNode::evaluate):
        * kjs/number_object.cpp:
        (NumberPrototype::NumberPrototype):
        (NumberProtoFunc::NumberProtoFunc):
        (NumberObjectImp::NumberObjectImp):
        * kjs/object.cpp:
        (KJS::JSObject::put):
        (KJS::JSObject::defaultValue):
        (KJS::JSObject::hasInstance):
        * kjs/object.h:
        (KJS::JSObject::getOwnPropertySlot):
        * kjs/object_object.cpp:
        (ObjectPrototype::ObjectPrototype):
        (ObjectProtoFunc::ObjectProtoFunc):
        (ObjectObjectImp::ObjectObjectImp):
        * kjs/regexp_object.cpp:
        (RegExpPrototype::RegExpPrototype):
        (RegExpProtoFunc::RegExpProtoFunc):
        (RegExpObjectImp::RegExpObjectImp):
        * kjs/string_object.cpp:
        (KJS::StringInstance::getOwnPropertySlot):
        (KJS::StringInstance::put):
        (KJS::StringInstance::deleteProperty):
        (KJS::StringPrototype::StringPrototype):
        (KJS::StringProtoFunc::StringProtoFunc):
        (KJS::StringProtoFunc::callAsFunction):
        (KJS::StringObjectImp::StringObjectImp):
        (KJS::StringObjectFuncImp::StringObjectFuncImp):
        * kjs/testkjs.cpp:
        (TestFunctionImp::TestFunctionImp):

WebCore:

        Reviewed by Mark.

        - avoid static construction (and global variable access) in a smarter, more portable way,
        to later enable MUTLI_THREAD mode to work on other platforms and compilers.
        
        * bindings/js/JSCustomXPathNSResolver.cpp:
        (WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):
        * bindings/js/JSHTMLInputElementBase.cpp:
        (WebCore::JSHTMLInputElementBaseFunction::JSHTMLInputElementBaseFunction):
        * bindings/js/JSHTMLOptionElementConstructor.cpp:
        (WebCore::JSHTMLOptionElementConstructor::JSHTMLOptionElementConstructor):
        * bindings/js/JSXMLHttpRequest.cpp:
        (KJS::JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp):
        * bindings/js/JSXSLTProcessor.cpp:
        (KJS::XSLTProcessorConstructorImp::XSLTProcessorConstructorImp):
        * bindings/js/kjs_dom.cpp:
        (KJS::DOMNamedNodeMap::getOwnPropertySlot):
        (KJS::DOMNamedNodesCollection::getOwnPropertySlot):
        * bindings/js/kjs_events.cpp:
        (KJS::JSAbstractEventListener::handleEvent):
        * bindings/js/kjs_html.cpp:
        (KJS::HTMLElementFunction::HTMLElementFunction):
        (KJS::JSHTMLCollection::getOwnPropertySlot):
        * bindings/js/kjs_window.cpp:
        (KJS::ScheduledAction::execute):
        * bindings/objc/WebScriptObject.mm:
        * bindings/scripts/CodeGeneratorJS.pm:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@20310 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2e549539
......@@ -100,7 +100,7 @@ JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObje
: exec->dynamicInterpreter()->builtinObjectPrototype();
JSObject* constructor = new JSCallbackConstructor(exec, jsClass, callAsConstructor);
constructor->put(exec, prototypePropertyName, jsPrototype, DontEnum|DontDelete|ReadOnly);
constructor->put(exec, exec->propertyNames().prototype, jsPrototype, DontEnum|DontDelete|ReadOnly);
return toRef(constructor);
}
......
......@@ -92,6 +92,7 @@ set(kjs-unity_LIB_SRCS
kjs/array_object.cpp
kjs/bool_object.cpp
kjs/collector.cpp
kjs/CommonIdentifiers.cpp
kjs/Context.cpp
kjs/date_object.cpp
kjs/debugger.cpp
......
2007-03-18 Maciej Stachowiak <mjs@apple.com>
Reviewed by Mark.
- avoid static construction (and global variable access) in a smarter, more portable way,
to later enable MUTLI_THREAD mode to work on other platforms and compilers.
* kjs/CommonIdentifiers.cpp: Added. New class to hold all the shared identifiers.
(KJS::CommonIdentifiers::CommonIdentifiers):
(KJS::CommonIdentifiers::shared):
* kjs/CommonIdentifiers.h: Added.
* kjs/ExecState.h:
(KJS::ExecState::propertyNames): Hand the CommonIdentifiers instance here for easy access.
(KJS::ExecState::ExecState):
* API/JSObjectRef.cpp:
(JSObjectMakeConstructor):
* CMakeLists.txt:
* JavaScriptCore.exp:
* JavaScriptCore.pri:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* JavaScriptCoreSources.bkl:
* bindings/runtime_array.cpp:
(RuntimeArray::getOwnPropertySlot):
(RuntimeArray::put):
* bindings/runtime_method.cpp:
(RuntimeMethod::getOwnPropertySlot):
* kjs/array_object.cpp:
(ArrayInstance::getOwnPropertySlot):
(ArrayInstance::put):
(ArrayInstance::deleteProperty):
(ArrayProtoFunc::ArrayProtoFunc):
(ArrayProtoFunc::callAsFunction):
(ArrayObjectImp::ArrayObjectImp):
* kjs/bool_object.cpp:
(BooleanPrototype::BooleanPrototype):
(BooleanProtoFunc::BooleanProtoFunc):
(BooleanProtoFunc::callAsFunction):
(BooleanObjectImp::BooleanObjectImp):
* kjs/completion.h:
(KJS::Completion::Completion):
* kjs/date_object.cpp:
(KJS::DateProtoFunc::DateProtoFunc):
(KJS::DateObjectImp::DateObjectImp):
(KJS::DateObjectFuncImp::DateObjectFuncImp):
* kjs/error_object.cpp:
(ErrorPrototype::ErrorPrototype):
(ErrorProtoFunc::ErrorProtoFunc):
(ErrorProtoFunc::callAsFunction):
(ErrorObjectImp::ErrorObjectImp):
(ErrorObjectImp::construct):
(NativeErrorPrototype::NativeErrorPrototype):
(NativeErrorImp::NativeErrorImp):
(NativeErrorImp::construct):
(NativeErrorImp::callAsFunction):
* kjs/function.cpp:
(KJS::FunctionImp::getOwnPropertySlot):
(KJS::FunctionImp::put):
(KJS::FunctionImp::deleteProperty):
(KJS::FunctionImp::getParameterName):
(KJS::DeclaredFunctionImp::construct):
(KJS::IndexToNameMap::unMap):
(KJS::Arguments::Arguments):
(KJS::ActivationImp::getOwnPropertySlot):
(KJS::ActivationImp::deleteProperty):
(KJS::GlobalFuncImp::GlobalFuncImp):
* kjs/function_object.cpp:
(FunctionPrototype::FunctionPrototype):
(FunctionProtoFunc::FunctionProtoFunc):
(FunctionProtoFunc::callAsFunction):
(FunctionObjectImp::FunctionObjectImp):
(FunctionObjectImp::construct):
* kjs/grammar.y:
* kjs/identifier.cpp:
* kjs/identifier.h:
* kjs/interpreter.cpp:
(KJS::Interpreter::init):
(KJS::Interpreter::initGlobalObject):
* kjs/interpreter.h:
* kjs/lookup.h:
* kjs/math_object.cpp:
(MathFuncImp::MathFuncImp):
* kjs/nodes.cpp:
(ArrayNode::evaluate):
(FuncDeclNode::processFuncDecl):
(FuncExprNode::evaluate):
* kjs/number_object.cpp:
(NumberPrototype::NumberPrototype):
(NumberProtoFunc::NumberProtoFunc):
(NumberObjectImp::NumberObjectImp):
* kjs/object.cpp:
(KJS::JSObject::put):
(KJS::JSObject::defaultValue):
(KJS::JSObject::hasInstance):
* kjs/object.h:
(KJS::JSObject::getOwnPropertySlot):
* kjs/object_object.cpp:
(ObjectPrototype::ObjectPrototype):
(ObjectProtoFunc::ObjectProtoFunc):
(ObjectObjectImp::ObjectObjectImp):
* kjs/regexp_object.cpp:
(RegExpPrototype::RegExpPrototype):
(RegExpProtoFunc::RegExpProtoFunc):
(RegExpObjectImp::RegExpObjectImp):
* kjs/string_object.cpp:
(KJS::StringInstance::getOwnPropertySlot):
(KJS::StringInstance::put):
(KJS::StringInstance::deleteProperty):
(KJS::StringPrototype::StringPrototype):
(KJS::StringProtoFunc::StringProtoFunc):
(KJS::StringProtoFunc::callAsFunction):
(KJS::StringObjectImp::StringObjectImp):
(KJS::StringObjectFuncImp::StringObjectFuncImp):
* kjs/testkjs.cpp:
(TestFunctionImp::TestFunctionImp):
2007-03-18 Andrew Wellington <proton@wiretapped.net>
Reviewed by Mark Rowe
......
......@@ -151,11 +151,8 @@ __ZN3KJS15SavedPropertiesD1Ev
__ZN3KJS16RuntimeObjectImp4infoE
__ZN3KJS16RuntimeObjectImpC1EPNS_8Bindings8InstanceE
__ZN3KJS17PropertyNameArray3addERKNS_10IdentifierE
__ZN3KJS18lengthPropertyNameE
__ZN3KJS19InternalFunctionImp4infoE
__ZN3KJS19InternalFunctionImpC2EPNS_17FunctionPrototypeERKNS_10IdentifierE
__ZN3KJS19messagePropertyNameE
__ZN3KJS21prototypePropertyNameE
__ZN3KJS4List6appendEPNS_7JSValueE
__ZN3KJS4List7releaseEv
__ZN3KJS4ListC1Ev
......
......@@ -47,6 +47,7 @@ SOURCES += \
kjs/array_object.cpp \
kjs/bool_object.cpp \
kjs/collector.cpp \
kjs/CommonIdentifiers.cpp \
kjs/Context.cpp \
kjs/date_object.cpp \
kjs/debugger.cpp \
......
......@@ -206,6 +206,14 @@
RelativePath="..\..\kjs\completion.h"
>
</File>
<File
RelativePath="..\..\kjs\CommonIdentifiers.cpp"
>
</File>
<File
RelativePath="..\..\kjs\CommonIdentifiers.h"
>
</File>
<File
RelativePath="..\..\kjs\config.h"
>
......
......@@ -114,6 +114,8 @@
65E217C008E7EECC0023E5F6 /* FastMalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 65E217BA08E7EECC0023E5F6 /* FastMalloc.h */; settings = {ATTRIBUTES = (Private, ); }; };
65EA4C9B092AF9E20093D800 /* JSLock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65EA4C99092AF9E20093D800 /* JSLock.cpp */; };
65EA4C9C092AF9E20093D800 /* JSLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 65EA4C9A092AF9E20093D800 /* JSLock.h */; settings = {ATTRIBUTES = (Private, ); }; };
65EA73640BAE35D1001BB560 /* CommonIdentifiers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65EA73620BAE35D1001BB560 /* CommonIdentifiers.cpp */; };
65EA73650BAE35D1001BB560 /* CommonIdentifiers.h in Headers */ = {isa = PBXBuildFile; fileRef = 65EA73630BAE35D1001BB560 /* CommonIdentifiers.h */; settings = {ATTRIBUTES = (Private, ); }; };
65FB3EB309D109F000F49DEB /* lexer.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = 65FB3EB209D109F000F49DEB /* lexer.lut.h */; };
65FB3F4F09D11B2400F49DEB /* date_object.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = 65FB3F4709D11B2400F49DEB /* date_object.lut.h */; };
65FB3F5009D11B2400F49DEB /* grammar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65FB3F4809D11B2400F49DEB /* grammar.cpp */; };
......@@ -557,6 +559,8 @@
65E217BA08E7EECC0023E5F6 /* FastMalloc.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = FastMalloc.h; sourceTree = "<group>"; tabWidth = 8; };
65EA4C99092AF9E20093D800 /* JSLock.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSLock.cpp; sourceTree = "<group>"; tabWidth = 8; };
65EA4C9A092AF9E20093D800 /* JSLock.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = JSLock.h; sourceTree = "<group>"; tabWidth = 8; };
65EA73620BAE35D1001BB560 /* CommonIdentifiers.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CommonIdentifiers.cpp; sourceTree = "<group>"; };
65EA73630BAE35D1001BB560 /* CommonIdentifiers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CommonIdentifiers.h; sourceTree = "<group>"; };
65FB3EB209D109F000F49DEB /* lexer.lut.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = lexer.lut.h; sourceTree = "<group>"; };
65FB3F4709D11B2400F49DEB /* date_object.lut.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = date_object.lut.h; sourceTree = "<group>"; };
65FB3F4809D11B2400F49DEB /* grammar.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = grammar.cpp; sourceTree = "<group>"; };
......@@ -963,6 +967,8 @@
isa = PBXGroup;
children = (
65C7A1710A8EAACB00FA37EA /* JSWrapperObject.cpp */,
65EA73620BAE35D1001BB560 /* CommonIdentifiers.cpp */,
65EA73630BAE35D1001BB560 /* CommonIdentifiers.h */,
65C7A1720A8EAACB00FA37EA /* JSWrapperObject.h */,
65400C0F0A69BAF200509887 /* PropertyNameArray.cpp */,
65400C100A69BAF200509887 /* PropertyNameArray.h */,
......@@ -1264,6 +1270,7 @@
E11D51760B2E798D0056C188 /* StringExtras.h in Headers */,
146AAB2B0B66A84900E55F16 /* JSStringRefCF.h in Headers */,
657EB7460B708F540063461B /* ListHashSet.h in Headers */,
65EA73650BAE35D1001BB560 /* CommonIdentifiers.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1562,6 +1569,7 @@
D212022A0AD4310D00ED79B6 /* DateMath.cpp in Sources */,
146AAB380B66A94400E55F16 /* JSStringRefCF.cpp in Sources */,
9302043B0B790750000C6115 /* FastMallocPCRE.cpp in Sources */,
65EA73640BAE35D1001BB560 /* CommonIdentifiers.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -2,6 +2,7 @@
<makefile>
<set append="1" var="JSCORE_SOURCES_KJS">
DerivedSources/JavaScriptCore/grammar.cpp
kjs/CommonIdentifiers.cpp
kjs/Context.cpp
kjs/DateMath.cpp
kjs/ExecState.cpp
......
......@@ -54,9 +54,9 @@ JSValue *RuntimeArray::indexGetter(ExecState* exec, JSObject*, const Identifier&
return thisObj->getConcreteArray()->valueAt(exec, slot.index());
}
bool RuntimeArray::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
bool RuntimeArray::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
if (propertyName == lengthPropertyName) {
if (propertyName == exec->propertyNames().length) {
slot.setCustom(this, lengthGetter);
return true;
}
......@@ -83,9 +83,9 @@ bool RuntimeArray::getOwnPropertySlot(ExecState *exec, unsigned index, PropertyS
return ArrayInstance::getOwnPropertySlot(exec, index, slot);
}
void RuntimeArray::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)
void RuntimeArray::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
if (propertyName == lengthPropertyName) {
if (propertyName == exec->propertyNames().length) {
throwError(exec, RangeError);
return;
}
......
......@@ -56,9 +56,9 @@ JSValue *RuntimeMethod::lengthGetter(ExecState*, JSObject*, const Identifier&, c
return jsNumber(thisObj->_methodList.methodAt(0)->numParameters());
}
bool RuntimeMethod::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
bool RuntimeMethod::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
{
if (propertyName == lengthPropertyName) {
if (propertyName == exec->propertyNames().length) {
slot.setCustom(this, lengthGetter);
return true;
}
......
/*
* Copyright (C) 2003, 2007 Apple Computer, Inc
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "CommonIdentifiers.h"
namespace KJS {
const char* const nullCString = 0;
#define INITIALIZE_PROPERTY_NAME(name) , name ( #name )
CommonIdentifiers::CommonIdentifiers()
: nullIdentifier(nullCString)
, underscoreProto("__proto__")
KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PROPERTY_NAME)
{
}
CommonIdentifiers* CommonIdentifiers::shared()
{
static CommonIdentifiers* sharedInstance;
if (!sharedInstance) {
JSLock lock;
sharedInstance = new CommonIdentifiers;
}
return sharedInstance;
}
} // namespace KJS
/*
* Copyright (C) 2003,2007 Apple Computer, Inc
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef KJS_COMMON_IDENTIFIERS_H
#define KJS_COMMON_IDENTIFIERS_H
#include "identifier.h"
#include <wtf/Noncopyable.h>
// List of property names, passed to a macro so we can do set them up various
// ways without repeating the list.
#define KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
macro(arguments) \
macro(callee) \
macro(caller) \
macro(constructor) \
macro(fromCharCode) \
macro(length) \
macro(message) \
macro(name) \
macro(prototype) \
macro(toLocaleString) \
macro(toString) \
macro(toFixed) \
macro(toExponential) \
macro(toPrecision) \
macro(valueOf)
namespace KJS {
class CommonIdentifiers : Noncopyable {
private:
CommonIdentifiers();
public:
static CommonIdentifiers* shared();
const Identifier nullIdentifier;
const Identifier underscoreProto;
#define KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) const Identifier name;
KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
#undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
};
} // namespace KJS
#endif // KJS_COMMON_IDENTIFIERS_H
......@@ -26,6 +26,7 @@
#include "value.h"
#include "types.h"
#include "CommonIdentifiers.h"
namespace KJS {
class Context;
......@@ -75,16 +76,22 @@ namespace KJS {
JSValue** exceptionSlot() { return &m_exception; }
bool hadException() const { return !!m_exception; }
// This is a workaround to avoid accessing the global variables for these identifiers in
// important property lookup functions, to avoid taking PIC branches in Mach-O binaries
const CommonIdentifiers& propertyNames() const { return *m_propertyNames; }
private:
ExecState(Interpreter* interp, Context* con)
: m_interpreter(interp)
, m_context(con)
, m_exception(0)
, m_propertyNames(CommonIdentifiers::shared())
{
}
Interpreter* m_interpreter;
Context* m_context;
JSValue* m_exception;
CommonIdentifiers* m_propertyNames;
};
} // namespace KJS
......
......@@ -89,7 +89,7 @@ JSValue *ArrayInstance::lengthGetter(ExecState*, JSObject*, const Identifier&, c
bool ArrayInstance::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
if (propertyName == lengthPropertyName) {
if (propertyName == exec->propertyNames().length) {
slot.setCustom(this, lengthGetter);
return true;
}
......@@ -130,9 +130,9 @@ bool ArrayInstance::getOwnPropertySlot(ExecState *exec, unsigned index, Property
}
// Special implementation of [[Put]] - see ECMA 15.4.5.1
void ArrayInstance::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)
void ArrayInstance::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
if (propertyName == lengthPropertyName) {
if (propertyName == exec->propertyNames().length) {
unsigned int newLen = value->toUInt32(exec);
if (value->toNumber(exec) != double(newLen)) {
throwError(exec, RangeError, "Invalid array length.");
......@@ -178,9 +178,9 @@ void ArrayInstance::put(ExecState *exec, unsigned index, JSValue *value, int att
JSObject::put(exec, Identifier::from(index), value, attr);
}
bool ArrayInstance::deleteProperty(ExecState *exec, const Identifier &propertyName)
bool ArrayInstance::deleteProperty(ExecState* exec, const Identifier &propertyName)
{
if (propertyName == lengthPropertyName)
if (propertyName == exec->propertyNames().length)
return false;
bool ok;
......@@ -435,12 +435,12 @@ bool ArrayPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& prope
// ------------------------------ ArrayProtoFunc ----------------------------
ArrayProtoFunc::ArrayProtoFunc(ExecState *exec, int i, int len, const Identifier& name)
ArrayProtoFunc::ArrayProtoFunc(ExecState* exec, int i, int len, const Identifier& name)
: InternalFunctionImp(static_cast<FunctionPrototype*>
(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
, id(i)
{
put(exec,lengthPropertyName,jsNumber(len),DontDelete|ReadOnly|DontEnum);
put(exec, exec->propertyNames().length, jsNumber(len), DontDelete | ReadOnly | DontEnum);
}
static JSValue *getProperty(ExecState *exec, JSObject *obj, unsigned index)
......@@ -452,9 +452,9 @@ static JSValue *getProperty(ExecState *exec, JSObject *obj, unsigned index)
}
// ECMA 15.4.4
JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
JSValue* ArrayProtoFunc::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
unsigned length = thisObj->get(exec,lengthPropertyName)->toUInt32(exec);
unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
JSValue *result = 0; // work around gcc 4.0 bug in uninitialized variable warning
......@@ -487,7 +487,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
bool fallback = false;
if (id == ToLocaleString) {
JSObject* o = element->toObject(exec);
JSValue* conversionFunction = o->get(exec, toLocaleStringPropertyName);
JSValue* conversionFunction = o->get(exec, exec->propertyNames().toLocaleString);
if (conversionFunction->isObject() && static_cast<JSObject*>(conversionFunction)->implementsCall())
str += static_cast<JSObject*>(conversionFunction)->call(exec, o, List())->toString(exec);
else
......@@ -517,7 +517,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
unsigned int k = 0;
// Older versions tried to optimize out getting the length of thisObj
// by checking for n != 0, but that doesn't work if thisObj is an empty array.
length = curObj->get(exec,lengthPropertyName)->toUInt32(exec);
length = curObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
while (k < length) {
if (JSValue *v = getProperty(exec, curObj, k))
arr->put(exec, n, v);
......@@ -533,18 +533,18 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
curArg = *it;
curObj = static_cast<JSObject *>(it++); // may be 0
}
arr->put(exec,lengthPropertyName, jsNumber(n), DontEnum | DontDelete);
arr->put(exec, exec->propertyNames().length, jsNumber(n), DontEnum | DontDelete);
result = arr;
break;
}
case Pop:{
if (length == 0) {
thisObj->put(exec, lengthPropertyName, jsNumber(length), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(length), DontEnum | DontDelete);
result = jsUndefined();
} else {
result = thisObj->get(exec, length - 1);
thisObj->put(exec, lengthPropertyName, jsNumber(length - 1), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(length - 1), DontEnum | DontDelete);
}
break;
}
......@@ -552,7 +552,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
for (int n = 0; n < args.size(); n++)
thisObj->put(exec, length + n, args[n]);
length += args.size();
thisObj->put(exec,lengthPropertyName, jsNumber(length), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(length), DontEnum | DontDelete);
result = jsNumber(length);
break;
}
......@@ -580,7 +580,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
}
case Shift: {
if (length == 0) {
thisObj->put(exec, lengthPropertyName, jsNumber(length), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(length), DontEnum | DontDelete);
result = jsUndefined();
} else {
result = thisObj->get(exec, 0);
......@@ -591,7 +591,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
thisObj->deleteProperty(exec, k-1);
}
thisObj->deleteProperty(exec, length - 1);
thisObj->put(exec, lengthPropertyName, jsNumber(length - 1), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(length - 1), DontEnum | DontDelete);
}
break;
}
......@@ -634,7 +634,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
if (JSValue *v = getProperty(exec, thisObj, k))
resObj->put(exec, n, v);
}
resObj->put(exec, lengthPropertyName, jsNumber(n), DontEnum | DontDelete);
resObj->put(exec, exec->propertyNames().length, jsNumber(n), DontEnum | DontDelete);
break;
}
case Sort:{
......@@ -661,7 +661,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
}
if (length == 0) {
thisObj->put(exec, lengthPropertyName, jsNumber(0), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(0), DontEnum | DontDelete);
result = thisObj;
break;
}
......@@ -727,7 +727,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
if (JSValue *v = getProperty(exec, thisObj, k+begin))
resObj->put(exec, k, v);
}
resObj->put(exec, lengthPropertyName, jsNumber(deleteCount), DontEnum | DontDelete);
resObj->put(exec, exec->propertyNames().length, jsNumber(deleteCount), DontEnum | DontDelete);
unsigned int additionalArgs = maxInt( args.size() - 2, 0 );
if ( additionalArgs != deleteCount )
......@@ -759,7 +759,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
{
thisObj->put(exec, k+begin, args[k+2]);
}
thisObj->put(exec, lengthPropertyName, jsNumber(length - deleteCount + additionalArgs), DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, jsNumber(length - deleteCount + additionalArgs), DontEnum | DontDelete);
break;
}
case UnShift: { // 15.4.4.13
......@@ -774,7 +774,7 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
for ( unsigned int k = 0; k < nrArgs; ++k )
thisObj->put(exec, k, args[k]);
result = jsNumber(length + nrArgs);
thisObj->put(exec, lengthPropertyName, result, DontEnum | DontDelete);
thisObj->put(exec, exec->propertyNames().length, result, DontEnum | DontDelete);
break;
}
case Filter:
......@@ -934,10 +934,10 @@ ArrayObjectImp::ArrayObjectImp(ExecState *exec,
: InternalFunctionImp(funcProto)
{
// ECMA 15.4.3.1 Array.prototype
put(exec, prototypePropertyName, arrayProto, DontEnum|DontDelete|ReadOnly);
put(exec, exec->propertyNames().prototype, arrayProto, DontEnum|DontDelete|ReadOnly);
// no. of arguments for constructor
put(exec, lengthPropertyName, jsNumber(1), ReadOnly|DontDelete|DontEnum);
put(exec, exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
}
bool ArrayObjectImp::implementsConstruct() const
......
......@@ -46,24 +46,24 @@ BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectProto
{
// The constructor will be added later by Interpreter::Interpreter()
putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, toStringPropertyName), DontEnum);
putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, valueOfPropertyName), DontEnum);
putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, exec->propertyNames().toString), DontEnum);
putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, exec->propertyNames().valueOf), DontEnum);
setInternalValue(jsBoolean(false));
}
// ------------------------------ BooleanProtoFunc --------------------------
BooleanProtoFunc::BooleanProtoFunc(ExecState*, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
BooleanProtoFunc::BooleanProtoFunc(ExecState* exec, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
: InternalFunctionImp(funcProto, name)
, id(i)
{
putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
putDirect(exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum);
}
// ECMA 15.6.4.2 + 15.6.4.3
JSValue *BooleanProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &/*args*/)
JSValue *BooleanProtoFunc::callAsFunction(ExecState* exec, JSObject *thisObj, const List &/*args*/)
{
// no generic function. "this" has to be a Boolean object
if (!thisObj->inherits(&BooleanInstance::info))
......@@ -82,13 +82,13 @@ JSValue *BooleanProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, co
// ------------------------------ BooleanObjectImp -----------------------------
BooleanObjectImp::BooleanObjectImp(ExecState*, FunctionPrototype* funcProto, BooleanPrototype* booleanProto)
BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* funcProto, BooleanPrototype* booleanProto)
: InternalFunctionImp(funcProto)
{
putDirect(prototypePropertyName, booleanProto, DontEnum|DontDelete|ReadOnly);
putDirect(exec->propertyNames().prototype, booleanProto, DontEnum|DontDelete|ReadOnly);
// no. of arguments for constructor
putDirect(lengthPropertyName, jsNumber(1), ReadOnly|DontDelete|DontEnum);
putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
}
......
......@@ -25,7 +25,7 @@
#ifndef _KJS_COMPLETION_H_
#define _KJS_COMPLETION_H_
#include "identifier.h"