Commit 3b6dc575 authored by oliver@apple.com's avatar oliver@apple.com

2011-03-28 Oliver Hunt <oliver@apple.com>

        Reviewed by Geoffrey Garen.

        instanceof Array test fails when using iframes
        https://bugs.webkit.org/show_bug.cgi?id=17250

        Add test cases for correct behaviour

        * fast/js/js-constructors-use-correct-global-expected.txt: Added.
        * fast/js/js-constructors-use-correct-global.html: Added.
        * fast/js/resources/js-constructors-use-correct-global.js: Added.
2011-03-28  Oliver Hunt  <oliver@apple.com>

        Reviewed by Geoffrey Garen.

        instanceof Array test fails when using iframes
        https://bugs.webkit.org/show_bug.cgi?id=17250

        This is a problem with all built in constructors, the use of
        lexicalGlobalObject rather than the constructors own
        global object reference means that a builtin will always use
        the prototype from the lexical global object rather than that
        of the constructors origin.

        * API/JSObjectRef.cpp:
        (JSObjectMakeFunction):
        (JSObjectMakeRegExp):
        * JavaScriptCore.exp:
        * runtime/ArrayConstructor.cpp:
        (JSC::constructArrayWithSizeQuirk):
        * runtime/BooleanConstructor.cpp:
        (JSC::constructBoolean):
        (JSC::constructBooleanFromImmediateBoolean):
        * runtime/BooleanConstructor.h:
        * runtime/DateConstructor.cpp:
        (JSC::constructDate):
        * runtime/DateInstance.cpp:
        * runtime/DateInstance.h:
        * runtime/ErrorConstructor.cpp:
        (JSC::constructWithErrorConstructor):
        (JSC::callErrorConstructor):
        * runtime/FunctionConstructor.cpp:
        (JSC::constructWithFunctionConstructor):
        (JSC::callFunctionConstructor):
        (JSC::constructFunction):
        * runtime/FunctionConstructor.h:
        * runtime/JSCell.cpp:
        (JSC::JSCell::getOwnPropertySlot):
        (JSC::JSCell::put):
        (JSC::JSCell::deleteProperty):
        (JSC::JSCell::toThisObject):
        (JSC::JSCell::toObject):
        * runtime/JSCell.h:
        (JSC::JSCell::JSValue::toObject):
        * runtime/JSNotAnObject.cpp:
        (JSC::JSNotAnObject::toObject):
        * runtime/JSNotAnObject.h:
        * runtime/JSObject.cpp:
        (JSC::JSObject::toObject):
        * runtime/JSObject.h:
        * runtime/JSString.cpp:
        (JSC::StringObject::create):
        (JSC::JSString::toObject):
        (JSC::JSString::toThisObject):
        * runtime/JSString.h:
        * runtime/JSValue.cpp:
        (JSC::JSValue::toObjectSlowCase):
        (JSC::JSValue::toThisObjectSlowCase):
        (JSC::JSValue::synthesizeObject):
        * runtime/JSValue.h:
        * runtime/NumberConstructor.cpp:
        (JSC::constructWithNumberConstructor):
        * runtime/NumberObject.cpp:
        (JSC::constructNumber):
        * runtime/NumberObject.h:
        * runtime/ObjectConstructor.cpp:
        (JSC::constructObject):
        (JSC::constructWithObjectConstructor):
        (JSC::callObjectConstructor):
        * runtime/RegExpConstructor.cpp:
        (JSC::constructRegExp):
        (JSC::constructWithRegExpConstructor):
        (JSC::callRegExpConstructor):
        * runtime/RegExpConstructor.h:
        * runtime/StringConstructor.cpp:
        (JSC::constructWithStringConstructor):
        * runtime/StringObject.h:
2011-03-25  Oliver Hunt  <oliver@apple.com>

        Reviewed by Geoffrey Garen.

        instanceof Array test fails when using iframes
        https://bugs.webkit.org/show_bug.cgi?id=17250

        Up date for new toObject api

        * UserObjectImp.cpp:
        (UserObjectImp::toPrimitive):
        (UserObjectImp::toBoolean):
        (UserObjectImp::toNumber):
        (UserObjectImp::toString):
2011-03-28  Oliver Hunt  <oliver@apple.com>

        Reviewed by Geoffrey Garen.

        instanceof Array test fails when using iframes
        https://bugs.webkit.org/show_bug.cgi?id=17250

        Update for new function and date apis

        Test: fast/js/js-constructors-use-correct-global.html

        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/JSDOMBinding.cpp:
        (WebCore::jsDateOrNull):
        * bindings/js/JSLazyEventListener.cpp:
        (WebCore::JSLazyEventListener::initializeJSFunction):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@82173 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 529cc692
2011-03-28 Oliver Hunt <oliver@apple.com>
Reviewed by Geoffrey Garen.
instanceof Array test fails when using iframes
https://bugs.webkit.org/show_bug.cgi?id=17250
Add test cases for correct behaviour
* fast/js/js-constructors-use-correct-global-expected.txt: Added.
* fast/js/js-constructors-use-correct-global.html: Added.
* fast/js/resources/js-constructors-use-correct-global.js: Added.
2011-03-28 Vincent Scheib <scheib@chromium.org>
Chromium rebaseline for r82144.
......
Test to ensure that js constructors create objects with the correct constructor
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS new otherGlobal.Object() instanceof otherGlobal.Object is true
PASS otherGlobal.Object() instanceof otherGlobal.Object is true
PASS new otherGlobal.Function() instanceof otherGlobal.Function is true
PASS otherGlobal.Function() instanceof otherGlobal.Function is true
PASS new otherGlobal.Array() instanceof otherGlobal.Array is true
PASS otherGlobal.Array() instanceof otherGlobal.Array is true
PASS new otherGlobal.Number() instanceof otherGlobal.Number is true
PASS new otherGlobal.String() instanceof otherGlobal.String is true
PASS new otherGlobal.Boolean() instanceof otherGlobal.Boolean is true
PASS new otherGlobal.RegExp() instanceof otherGlobal.RegExp is true
PASS otherGlobal.RegExp() instanceof otherGlobal.RegExp is true
PASS new otherGlobal.Date() instanceof otherGlobal.Date is true
PASS new otherGlobal.Error() instanceof otherGlobal.Error is true
PASS otherGlobal.Error() instanceof otherGlobal.Error is true
PASS new otherGlobal.RangeError() instanceof otherGlobal.RangeError is true
PASS otherGlobal.RangeError() instanceof otherGlobal.RangeError is true
PASS new otherGlobal.ReferenceError() instanceof otherGlobal.ReferenceError is true
PASS otherGlobal.ReferenceError() instanceof otherGlobal.ReferenceError is true
PASS new otherGlobal.SyntaxError() instanceof otherGlobal.SyntaxError is true
PASS otherGlobal.SyntaxError() instanceof otherGlobal.SyntaxError is true
PASS new otherGlobal.TypeError() instanceof otherGlobal.TypeError is true
PASS otherGlobal.TypeError() instanceof otherGlobal.TypeError is true
PASS new otherGlobal.URIError() instanceof otherGlobal.URIError is true
PASS otherGlobal.URIError() instanceof otherGlobal.URIError is true
PASS new otherGlobal.Image() instanceof otherGlobal.Image is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="resources/js-test-style.css">
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<iframe></iframe>
<script src="resources/js-constructors-use-correct-global.js"></script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
description("Test to ensure that js constructors create objects with the correct constructor");
var otherGlobal = document.getElementsByTagName("iframe")[0].contentWindow;
var constructors = ["Object", "Function", "Array", "Number", "String", "Boolean", "RegExp", "Date", "Error", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "Image"];
for (var i = 0; i < constructors.length; i++) {
shouldBeTrue("new otherGlobal." + constructors[i] + "() instanceof otherGlobal." + constructors[i]);
try {
if ((typeof (otherGlobal[constructors[i]]())) === "object" || (typeof (otherGlobal[constructors[i]]())) === "function")
shouldBeTrue("otherGlobal." + constructors[i] + "() instanceof otherGlobal." + constructors[i]);
} catch(e) {
}
}
successfullyParsed = true;
......@@ -124,7 +124,7 @@ JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned pa
args.append(jsString(exec, parameterNames[i]->ustring()));
args.append(jsString(exec, body->ustring()));
JSObject* result = constructFunction(exec, args, nameID, sourceURL->ustring(), startingLineNumber);
JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL->ustring(), startingLineNumber);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
......@@ -207,7 +207,7 @@ JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSV
for (size_t i = 0; i < argumentCount; ++i)
argList.append(toJS(exec, arguments[i]));
JSObject* result = constructRegExp(exec, argList);
JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(), argList);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
......
2011-03-28 Oliver Hunt <oliver@apple.com>
Reviewed by Geoffrey Garen.
instanceof Array test fails when using iframes
https://bugs.webkit.org/show_bug.cgi?id=17250
This is a problem with all built in constructors, the use of
lexicalGlobalObject rather than the constructors own
global object reference means that a builtin will always use
the prototype from the lexical global object rather than that
of the constructors origin.
* API/JSObjectRef.cpp:
(JSObjectMakeFunction):
(JSObjectMakeRegExp):
* JavaScriptCore.exp:
* runtime/ArrayConstructor.cpp:
(JSC::constructArrayWithSizeQuirk):
* runtime/BooleanConstructor.cpp:
(JSC::constructBoolean):
(JSC::constructBooleanFromImmediateBoolean):
* runtime/BooleanConstructor.h:
* runtime/DateConstructor.cpp:
(JSC::constructDate):
* runtime/DateInstance.cpp:
* runtime/DateInstance.h:
* runtime/ErrorConstructor.cpp:
(JSC::constructWithErrorConstructor):
(JSC::callErrorConstructor):
* runtime/FunctionConstructor.cpp:
(JSC::constructWithFunctionConstructor):
(JSC::callFunctionConstructor):
(JSC::constructFunction):
* runtime/FunctionConstructor.h:
* runtime/JSCell.cpp:
(JSC::JSCell::getOwnPropertySlot):
(JSC::JSCell::put):
(JSC::JSCell::deleteProperty):
(JSC::JSCell::toThisObject):
(JSC::JSCell::toObject):
* runtime/JSCell.h:
(JSC::JSCell::JSValue::toObject):
* runtime/JSNotAnObject.cpp:
(JSC::JSNotAnObject::toObject):
* runtime/JSNotAnObject.h:
* runtime/JSObject.cpp:
(JSC::JSObject::toObject):
* runtime/JSObject.h:
* runtime/JSString.cpp:
(JSC::StringObject::create):
(JSC::JSString::toObject):
(JSC::JSString::toThisObject):
* runtime/JSString.h:
* runtime/JSValue.cpp:
(JSC::JSValue::toObjectSlowCase):
(JSC::JSValue::toThisObjectSlowCase):
(JSC::JSValue::synthesizeObject):
* runtime/JSValue.h:
* runtime/NumberConstructor.cpp:
(JSC::constructWithNumberConstructor):
* runtime/NumberObject.cpp:
(JSC::constructNumber):
* runtime/NumberObject.h:
* runtime/ObjectConstructor.cpp:
(JSC::constructObject):
(JSC::constructWithObjectConstructor):
(JSC::callObjectConstructor):
* runtime/RegExpConstructor.cpp:
(JSC::constructRegExp):
(JSC::constructWithRegExpConstructor):
(JSC::callRegExpConstructor):
* runtime/RegExpConstructor.h:
* runtime/StringConstructor.cpp:
(JSC::constructWithStringConstructor):
* runtime/StringObject.h:
2011-03-28 Geoffrey Garen <ggaren@apple.com>
Reviewed by Oliver Hunt.
......
......@@ -122,7 +122,6 @@ __ZN3JSC11createErrorEPNS_9ExecStateERKNS_7UStringE
__ZN3JSC11regExpFlagsERKNS_7UStringE
__ZN3JSC12DateInstance6s_infoE
__ZN3JSC12DateInstanceC1EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEEd
__ZN3JSC12DateInstanceC1EPNS_9ExecStateEd
__ZN3JSC12JSGlobalData10ClientDataD2Ev
__ZN3JSC12JSGlobalData11jsArrayVPtrE
__ZN3JSC12JSGlobalData12createLeakedENS_15ThreadStackTypeE
......@@ -182,7 +181,7 @@ __ZN3JSC16createRangeErrorEPNS_9ExecStateERKNS_7UStringE
__ZN3JSC16throwSyntaxErrorEPNS_9ExecStateE
__ZN3JSC17BytecodeGenerator21setDumpsGeneratedCodeEb
__ZN3JSC17PropertyNameArray3addEPN3WTF10StringImplE
__ZN3JSC17constructFunctionEPNS_9ExecStateERKNS_7ArgListERKNS_10IdentifierERKNS_7UStringEi
__ZN3JSC17constructFunctionEPNS_9ExecStateEPNS_14JSGlobalObjectERKNS_7ArgListERKNS_10IdentifierERKNS_7UStringEi
__ZN3JSC17createSyntaxErrorEPNS_9ExecStateERKNS_7UStringE
__ZN3JSC18DebuggerActivationC1ERNS_12JSGlobalDataEPNS_8JSObjectE
__ZN3JSC18PropertyDescriptor11setWritableEb
......@@ -535,7 +534,7 @@ __ZNK3JSC6JSCell11toPrimitiveEPNS_9ExecStateENS_22PreferredPrimitiveTypeE
__ZNK3JSC6JSCell12toThisObjectEPNS_9ExecStateE
__ZNK3JSC6JSCell14isGetterSetterEv
__ZNK3JSC6JSCell8toNumberEPNS_9ExecStateE
__ZNK3JSC6JSCell8toObjectEPNS_9ExecStateE
__ZNK3JSC6JSCell8toObjectEPNS_9ExecStateEPNS_14JSGlobalObjectE
__ZNK3JSC6JSCell8toStringEPNS_9ExecStateE
__ZNK3JSC6JSCell9getStringEPNS_9ExecStateE
__ZNK3JSC6JSCell9getStringEPNS_9ExecStateERNS_7UStringE
......@@ -543,7 +542,7 @@ __ZNK3JSC6JSCell9getUInt32ERj
__ZNK3JSC6JSCell9toBooleanEPNS_9ExecStateE
__ZNK3JSC7ArgList8getSliceEiRS0_
__ZNK3JSC7JSArray12subclassDataEv
__ZNK3JSC7JSValue16toObjectSlowCaseEPNS_9ExecStateE
__ZNK3JSC7JSValue16toObjectSlowCaseEPNS_9ExecStateEPNS_14JSGlobalObjectE
__ZNK3JSC7JSValue19synthesizePrototypeEPNS_9ExecStateE
__ZNK3JSC7JSValue20toThisObjectSlowCaseEPNS_9ExecStateE
__ZNK3JSC7JSValue9toIntegerEPNS_9ExecStateE
......@@ -556,7 +555,7 @@ __ZNK3JSC8JSObject12defaultValueEPNS_9ExecStateENS_22PreferredPrimitiveTypeE
__ZNK3JSC8JSObject12toThisObjectEPNS_9ExecStateE
__ZNK3JSC8JSObject18toStrictThisObjectEPNS_9ExecStateE
__ZNK3JSC8JSObject8toNumberEPNS_9ExecStateE
__ZNK3JSC8JSObject8toObjectEPNS_9ExecStateE
__ZNK3JSC8JSObject8toObjectEPNS_9ExecStateEPNS_14JSGlobalObjectE
__ZNK3JSC8JSObject8toStringEPNS_9ExecStateE
__ZNK3JSC8JSObject9classNameEv
__ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE
......
......@@ -3,7 +3,6 @@ EXPORTS
??0CString@WTF@@QAE@PBD@Z
??0CString@WTF@@QAE@PBDI@Z
??0Collator@WTF@@QAE@PBD@Z
??0DateInstance@JSC@@QAE@PAVExecState@1@N@Z
??0DateInstance@JSC@@QAE@PAVExecState@1@V?$NonNullPassRefPtr@VStructure@JSC@@@WTF@@N@Z
??0DefaultGCActivityCallback@JSC@@QAE@PAVHeap@1@@Z
??0DropAllLocks@JSLock@JSC@@QAE@W4JSLockBehavior@2@@Z
......@@ -94,7 +93,7 @@ EXPORTS
?constructArray@JSC@@YAPAVJSArray@1@PAVExecState@1@ABVArgList@1@@Z
?constructEmptyArray@JSC@@YAPAVJSArray@1@PAVExecState@1@@Z
?constructEmptyObject@JSC@@YAPAVJSObject@1@PAVExecState@1@@Z
?constructFunction@JSC@@YAPAVJSObject@1@PAVExecState@1@ABVArgList@1@ABVIdentifier@1@ABVUString@1@H@Z
?constructFunction@JSC@@YAPAVJSObject@1@PAVExecState@1@PAVJSGlobalObject@1@ABVArgList@1@ABVIdentifier@1@ABVUString@1@H@Z
?convertUTF16ToUTF8@Unicode@WTF@@YA?AW4ConversionResult@12@PAPB_WPB_WPAPADPAD_N@Z
?convertUTF8ToUTF16@Unicode@WTF@@YA?AW4ConversionResult@12@PAPBDPBDPAPA_WPA_W_N@Z
?create@ByteArray@WTF@@SA?AV?$PassRefPtr@VByteArray@WTF@@@2@I@Z
......@@ -336,10 +335,9 @@ EXPORTS
?toNumber@JSCell@JSC@@UBENPAVExecState@2@@Z
?toNumber@JSObject@JSC@@UBENPAVExecState@2@@Z
?toNumber@JSString@JSC@@EBENPAVExecState@2@@Z
?toObject@JSCell@JSC@@UBEPAVJSObject@2@PAVExecState@2@@Z
?toObject@JSObject@JSC@@UBEPAV12@PAVExecState@2@@Z
?toObject@JSString@JSC@@EBEPAVJSObject@2@PAVExecState@2@@Z
?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@@Z
?toObject@JSCell@JSC@@UBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
?toObject@JSObject@JSC@@UBEPAV12@PAVExecState@2@PAVJSGlobalObject@2@@Z
?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
?toPrimitive@JSCell@JSC@@UBE?AVJSValue@2@PAVExecState@2@W4PreferredPrimitiveType@2@@Z
?toPrimitive@JSString@JSC@@EBE?AVJSValue@2@PAVExecState@2@W4PreferredPrimitiveType@2@@Z
?toStrictThisObject@JSObject@JSC@@UBE?AVJSValue@2@PAVExecState@2@@Z
......
......@@ -248,7 +248,7 @@ BytecodeGenerator::BytecodeGenerator(ProgramNode* programNode, ScopeChainNode* s
SymbolTable::iterator end = symbolTable->end();
for (SymbolTable::iterator it = symbolTable->begin(); it != end; ++it)
registerFor(it->second.getIndex()).setIndex(it->second.getIndex() + m_globalVarStorageOffset);
BatchedTransitionOptimizer optimizer(*m_globalData, globalObject);
const VarStack& varStack = programNode->varStack();
......
......@@ -52,16 +52,18 @@ ArrayConstructor::ArrayConstructor(ExecState* exec, JSGlobalObject* globalObject
static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args)
{
JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
// a single numeric argument denotes the array size (!)
if (args.size() == 1 && args.at(0).isNumber()) {
uint32_t n = args.at(0).toUInt32(exec);
if (n != args.at(0).toNumber(exec))
return throwError(exec, createRangeError(exec, "Array size is not a small enough positive integer."));
return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), n, CreateInitialized);
return new (exec) JSArray(globalObject->arrayStructure(), n, CreateInitialized);
}
// otherwise the array is constructed with the arguments in it
return new (exec) JSArray(exec->globalData(), exec->lexicalGlobalObject()->arrayStructure(), args);
return new (exec) JSArray(exec->globalData(), globalObject->arrayStructure(), args);
}
static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec)
......
......@@ -40,7 +40,7 @@ BooleanConstructor::BooleanConstructor(ExecState* exec, JSGlobalObject* globalOb
// ECMA 15.6.2
JSObject* constructBoolean(ExecState* exec, const ArgList& args)
{
BooleanObject* obj = new (exec) BooleanObject(exec->globalData(), exec->lexicalGlobalObject()->booleanObjectStructure());
BooleanObject* obj = new (exec) BooleanObject(exec->globalData(), asInternalFunction(exec->callee())->globalObject()->booleanObjectStructure());
obj->setInternalValue(exec->globalData(), jsBoolean(args.at(0).toBoolean(exec)));
return obj;
}
......@@ -69,9 +69,9 @@ CallType BooleanConstructor::getCallData(CallData& callData)
return CallTypeHost;
}
JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSValue immediateBooleanValue)
JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue)
{
BooleanObject* obj = new (exec) BooleanObject(exec->globalData(), exec->lexicalGlobalObject()->booleanObjectStructure());
BooleanObject* obj = new (exec) BooleanObject(exec->globalData(), globalObject->booleanObjectStructure());
obj->setInternalValue(exec->globalData(), immediateBooleanValue);
return obj;
}
......
......@@ -36,7 +36,7 @@ namespace JSC {
virtual CallType getCallData(CallData&);
};
JSObject* constructBooleanFromImmediateBoolean(ExecState*, JSValue);
JSObject* constructBooleanFromImmediateBoolean(ExecState*, JSGlobalObject*, JSValue);
JSObject* constructBoolean(ExecState*, const ArgList&);
} // namespace JSC
......
......@@ -121,7 +121,7 @@ JSObject* constructDate(ExecState* exec, const ArgList& args)
}
}
return new (exec) DateInstance(exec, value);
return new (exec) DateInstance(exec, asInternalFunction(exec->callee())->globalObject()->dateStructure(), value);
}
static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec)
......
......@@ -48,13 +48,6 @@ DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr<Structure> structu
setInternalValue(exec->globalData(), jsNumber(timeClip(time)));
}
DateInstance::DateInstance(ExecState* exec, double time)
: JSWrapperObject(exec->lexicalGlobalObject()->dateStructure())
{
ASSERT(inherits(&s_info));
setInternalValue(exec->globalData(), jsNumber(timeClip(time)));
}
const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const
{
double milli = internalNumber();
......
......@@ -31,7 +31,6 @@ namespace JSC {
class DateInstance : public JSWrapperObject {
public:
DateInstance(ExecState*, double);
DateInstance(ExecState*, NonNullPassRefPtr<Structure>, double);
explicit DateInstance(ExecState*, NonNullPassRefPtr<Structure>);
......
......@@ -42,7 +42,7 @@ ErrorConstructor::ErrorConstructor(ExecState* exec, JSGlobalObject* globalObject
static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec)
{
JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure();
return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
}
......@@ -55,7 +55,7 @@ ConstructType ErrorConstructor::getConstructData(ConstructData& constructData)
static EncodedJSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec)
{
JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure();
return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
}
......
......@@ -49,7 +49,7 @@ FunctionConstructor::FunctionConstructor(ExecState* exec, JSGlobalObject* global
static EncodedJSValue JSC_HOST_CALL constructWithFunctionConstructor(ExecState* exec)
{
ArgList args(exec);
return JSValue::encode(constructFunction(exec, args));
return JSValue::encode(constructFunction(exec, asInternalFunction(exec->callee())->globalObject(), args));
}
ConstructType FunctionConstructor::getConstructData(ConstructData& constructData)
......@@ -61,7 +61,7 @@ ConstructType FunctionConstructor::getConstructData(ConstructData& constructData
static EncodedJSValue JSC_HOST_CALL callFunctionConstructor(ExecState* exec)
{
ArgList args(exec);
return JSValue::encode(constructFunction(exec, args));
return JSValue::encode(constructFunction(exec, asInternalFunction(exec->callee())->globalObject(), args));
}
// ECMA 15.3.1 The Function Constructor Called as a Function
......@@ -72,7 +72,7 @@ CallType FunctionConstructor::getCallData(CallData& callData)
}
// ECMA 15.3.2 The Function Constructor
JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
{
// Functions need to have a space following the opening { due to for web compatibility
// see https://bugs.webkit.org/show_bug.cgi?id=24350
......@@ -96,7 +96,6 @@ JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifi
program = builder.toUString();
}
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
JSGlobalData& globalData = globalObject->globalData();
SourceCode source = makeSource(program, sourceURL, lineNumber);
JSObject* exception = 0;
......@@ -111,9 +110,9 @@ JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifi
}
// ECMA 15.3.2 The Function Constructor
JSObject* constructFunction(ExecState* exec, const ArgList& args)
JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args)
{
return constructFunction(exec, args, Identifier(exec, "anonymous"), UString(), 1);
return constructFunction(exec, globalObject, args, Identifier(exec, "anonymous"), UString(), 1);
}
} // namespace JSC
......@@ -36,8 +36,8 @@ namespace JSC {
virtual CallType getCallData(CallData&);
};
JSObject* constructFunction(ExecState*, const ArgList&, const Identifier& functionName, const UString& sourceURL, int lineNumber);
JSObject* constructFunction(ExecState*, const ArgList&);
JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, const Identifier& functionName, const UString& sourceURL, int lineNumber);
JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&);
} // namespace JSC
......
......@@ -119,7 +119,7 @@ bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, P
// This is not a general purpose implementation of getOwnPropertySlot.
// It should only be called by JSValue::get.
// It calls getPropertySlot, not getOwnPropertySlot.
JSObject* object = toObject(exec);
JSObject* object = toObject(exec, exec->lexicalGlobalObject());
slot.setBase(object);
if (!object->getPropertySlot(exec, identifier, slot))
slot.setUndefined();
......@@ -131,7 +131,7 @@ bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySl
// This is not a general purpose implementation of getOwnPropertySlot.
// It should only be called by JSValue::get.
// It calls getPropertySlot, not getOwnPropertySlot.
JSObject* object = toObject(exec);
JSObject* object = toObject(exec, exec->lexicalGlobalObject());
slot.setBase(object);
if (!object->getPropertySlot(exec, identifier, slot))
slot.setUndefined();
......@@ -140,27 +140,27 @@ bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySl
void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
{
toObject(exec)->put(exec, identifier, value, slot);
toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value, slot);
}
void JSCell::put(ExecState* exec, unsigned identifier, JSValue value)
{
toObject(exec)->put(exec, identifier, value);
toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value);
}
bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
{
return toObject(exec)->deleteProperty(exec, identifier);
return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier);
}
bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
{
return toObject(exec)->deleteProperty(exec, identifier);
return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier);
}
JSObject* JSCell::toThisObject(ExecState* exec) const
{
return toObject(exec);
return toObject(exec, exec->lexicalGlobalObject());
}
JSValue JSCell::getJSNumber()
......@@ -203,7 +203,7 @@ UString JSCell::toString(ExecState*) const
return UString();
}
JSObject* JSCell::toObject(ExecState*) const
JSObject* JSCell::toObject(ExecState*, JSGlobalObject*) const
{
ASSERT_NOT_REACHED();
return 0;
......
......@@ -35,6 +35,8 @@
namespace JSC {
class JSGlobalObject;
#if COMPILER(MSVC)
// If WTF_MAKE_NONCOPYABLE is applied to JSCell we end up with a bunch of
// undefined references to the JSCell copy constructor and assignment operator
......@@ -106,7 +108,7 @@ namespace JSC {
virtual bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
virtual JSObject* toObject(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
// Garbage collection.
void* operator new(size_t, ExecState*);
......@@ -336,7 +338,12 @@ namespace JSC {
inline JSObject* JSValue::toObject(ExecState* exec) const
{
return isCell() ? asCell()->toObject(exec) : toObjectSlowCase(exec);
return isCell() ? asCell()->toObject(exec, exec->lexicalGlobalObject()) : toObjectSlowCase(exec, exec->lexicalGlobalObject());
}
inline JSObject* JSValue::toObject(ExecState* exec, JSGlobalObject* globalObject) const
{
return isCell() ? asCell()->toObject(exec, globalObject) : toObjectSlowCase(exec, globalObject);
}
inline JSObject* JSValue::toThisObject(ExecState* exec) const
......
......@@ -67,7 +67,7 @@ UString JSNotAnObject::toString(ExecState* exec) const
return "";
}
JSObject* JSNotAnObject::toObject(ExecState* exec) const
JSObject* JSNotAnObject::toObject(ExecState* exec, JSGlobalObject*) const
{
ASSERT_UNUSED(exec, exec->hadException());
return const_cast<JSNotAnObject*>(this);
......
......@@ -58,7 +58,7 @@ namespace JSC {
virtual bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
virtual JSObject* toObject(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
// JSObject methods
virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
......
......@@ -489,7 +489,7 @@ UString JSObject::toString(ExecState* exec) const
return primitive.toString(exec);
}
JSObject* JSObject::toObject(ExecState*) const
JSObject* JSObject::toObject(ExecState*, JSGlobalObject*) const
{
return const_cast<JSObject*>(this);
}
......
......@@ -138,7 +138,7 @@ namespace JSC {
virtual bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
virtual JSObject* toObject(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
virtual JSObject* toThisObject(ExecState*) const;
virtual JSValue toStrictThisObject(ExecState*) const;
......
......@@ -253,19 +253,19 @@ UString JSString::toString(ExecState* exec) const
return value(exec);
}
inline StringObject* StringObject::create(ExecState* exec, JSString* string)
inline StringObject* StringObject::create(ExecState* exec, JSGlobalObject* globalObject, JSString* string)
{
return new (exec) StringObject(exec->globalData(), exec->lexicalGlobalObject()->stringObjectStructure(), string);
return new (exec) StringObject(exec->globalData(), globalObject->stringObjectStructure(), string);
}
JSObject* JSString::toObject(ExecState* exec) const
JSObject* JSString::toObject(ExecState* exec, JSGlobalObject* globalObject) const
{
return StringObject::create(exec, const_cast<JSString*>(this));
return StringObject::create(exec, globalObject, const_cast<JSString*>(this));
}
JSObject* JSString::toThisObject(ExecState* exec) const
{
return StringObject::create(exec, const_cast<JSString*>(this));
return StringObject::create(exec, exec->lexicalGlobalObject(), const_cast<JSString*>(this));
}
bool JSString::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
......
......@@ -402,7 +402,7 @@ namespace JSC {
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
virtual bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual JSObject* toObject(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
virtual UString toString(ExecState*) const;