X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/14957cd040308e3eeec43d26bae5d76da13fcd85..6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174:/runtime/JSFunction.cpp diff --git a/runtime/JSFunction.cpp b/runtime/JSFunction.cpp index e33d5d2..243946b 100644 --- a/runtime/JSFunction.cpp +++ b/runtime/JSFunction.cpp @@ -30,6 +30,8 @@ #include "CallFrame.h" #include "ExceptionHelpers.h" #include "FunctionPrototype.h" +#include "GetterSetter.h" +#include "JSArray.h" #include "JSGlobalObject.h" #include "JSNotAnObject.h" #include "Interpreter.h" @@ -48,64 +50,66 @@ EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState* exec) } ASSERT_CLASS_FITS_IN_CELL(JSFunction); +ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSFunction); -const ClassInfo JSFunction::s_info = { "Function", &Base::s_info, 0, 0 }; +const ClassInfo JSFunction::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSFunction) }; bool JSFunction::isHostFunctionNonInline() const { return isHostFunction(); } -JSFunction::JSFunction(VPtrStealingHackType) - : Base(VPtrStealingHack) +JSFunction* JSFunction::create(ExecState* exec, JSGlobalObject* globalObject, int length, const Identifier& name, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor) { + NativeExecutable* executable; +#if !ENABLE(JIT) + UNUSED_PARAM(intrinsic); +#else + if (intrinsic != NoIntrinsic && exec->globalData().canUseJIT()) { + ASSERT(nativeConstructor == callHostFunctionAsConstructor); + executable = exec->globalData().getHostFunction(nativeFunction, intrinsic); + } else +#endif + executable = exec->globalData().getHostFunction(nativeFunction, nativeConstructor); + + JSFunction* function = new (NotNull, allocateCell(*exec->heap())) JSFunction(exec, globalObject, globalObject->functionStructure()); + // Can't do this during initialization because getHostFunction might do a GC allocation. + function->finishCreation(exec, executable, length, name); + return function; } -JSFunction::JSFunction(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, int length, const Identifier& name, NativeExecutable* thunk) - : Base(globalObject, structure) - , m_executable(exec->globalData(), this, thunk) - , m_scopeChain(exec->globalData(), this, globalObject->globalScopeChain()) -{ - ASSERT(inherits(&s_info)); - putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum); - putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum); -} - -JSFunction::JSFunction(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, int length, const Identifier& name, NativeFunction func) - : Base(globalObject, structure) +JSFunction::JSFunction(ExecState* exec, JSGlobalObject* globalObject, Structure* structure) + : Base(exec->globalData(), structure) + , m_executable() , m_scopeChain(exec->globalData(), this, globalObject->globalScopeChain()) { - ASSERT(inherits(&s_info)); - - // Can't do this during initialization because getHostFunction might do a GC allocation. - m_executable.set(exec->globalData(), this, exec->globalData().getHostFunction(func)); - - putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum); - putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum); } JSFunction::JSFunction(ExecState* exec, FunctionExecutable* executable, ScopeChainNode* scopeChainNode) - : Base(scopeChainNode->globalObject.get(), scopeChainNode->globalObject->functionStructure()) + : Base(exec->globalData(), scopeChainNode->globalObject->functionStructure()) , m_executable(exec->globalData(), this, executable) , m_scopeChain(exec->globalData(), this, scopeChainNode) { - ASSERT(inherits(&s_info)); - const Identifier& name = static_cast(m_executable.get())->name(); - putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum); } -JSFunction::~JSFunction() +void JSFunction::finishCreation(ExecState* exec, NativeExecutable* executable, int length, const Identifier& name) { - ASSERT(vptr() == JSGlobalData::jsFunctionVPtr); + Base::finishCreation(exec->globalData()); + ASSERT(inherits(&s_info)); + m_executable.set(exec->globalData(), this, executable); + putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum); + putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum); } -static const char* StrictModeCallerAccessError = "Cannot access caller property of a strict mode function"; -static const char* StrictModeArgumentsAccessError = "Cannot access arguments property of a strict mode function"; - -static void createDescriptorForThrowingProperty(ExecState* exec, PropertyDescriptor& descriptor, const char* message) +void JSFunction::finishCreation(ExecState* exec, FunctionExecutable* executable, ScopeChainNode* scopeChainNode) { - JSValue thrower = createTypeErrorFunction(exec, message); - descriptor.setAccessorDescriptor(thrower, thrower, DontEnum | DontDelete | Getter | Setter); + Base::finishCreation(exec->globalData()); + ASSERT(inherits(&s_info)); + + // Switching the structure here is only safe if we currently have the function structure! + ASSERT(structure() == scopeChainNode->globalObject->functionStructure()); + setStructure(exec->globalData(), scopeChainNode->globalObject->namedFunctionStructure()); + putDirectOffset(exec->globalData(), scopeChainNode->globalObject->functionNameOffset(), executable->nameValue()); } const UString& JSFunction::name(ExecState* exec) @@ -117,7 +121,7 @@ const UString JSFunction::displayName(ExecState* exec) { JSValue displayName = getDirect(exec->globalData(), exec->globalData().propertyNames->displayName); - if (displayName && isJSString(&exec->globalData(), displayName)) + if (displayName && isJSString(displayName)) return asString(displayName)->tryGetValue(); return UString(); @@ -130,210 +134,316 @@ const UString JSFunction::calculatedDisplayName(ExecState* exec) if (!explicitName.isEmpty()) return explicitName; - return name(exec); + const UString actualName = name(exec); + if (!actualName.isEmpty() || isHostFunction()) + return actualName; + + return jsExecutable()->inferredName().ustring(); +} + +const SourceCode* JSFunction::sourceCode() const +{ + if (isHostFunction()) + return 0; + return &jsExecutable()->source(); } -void JSFunction::visitChildren(SlotVisitor& visitor) +void JSFunction::visitChildren(JSCell* cell, SlotVisitor& visitor) { - ASSERT_GC_OBJECT_INHERITS(this, &s_info); + JSFunction* thisObject = jsCast(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); - ASSERT(structure()->typeInfo().overridesVisitChildren()); - Base::visitChildren(visitor); + ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); + Base::visitChildren(thisObject, visitor); - visitor.append(&m_scopeChain); - if (m_executable) - visitor.append(&m_executable); + visitor.append(&thisObject->m_scopeChain); + if (thisObject->m_executable) + visitor.append(&thisObject->m_executable); } -CallType JSFunction::getCallData(CallData& callData) +CallType JSFunction::getCallData(JSCell* cell, CallData& callData) { - if (isHostFunction()) { - callData.native.function = nativeFunction(); + JSFunction* thisObject = jsCast(cell); + if (thisObject->isHostFunction()) { + callData.native.function = thisObject->nativeFunction(); return CallTypeHost; } - callData.js.functionExecutable = jsExecutable(); - callData.js.scopeChain = scope(); + callData.js.functionExecutable = thisObject->jsExecutable(); + callData.js.scopeChain = thisObject->scope(); return CallTypeJS; } JSValue JSFunction::argumentsGetter(ExecState* exec, JSValue slotBase, const Identifier&) { - JSFunction* thisObj = asFunction(slotBase); + JSFunction* thisObj = jsCast(slotBase); ASSERT(!thisObj->isHostFunction()); - return exec->interpreter()->retrieveArguments(exec, thisObj); + return exec->interpreter()->retrieveArgumentsFromVMCode(exec, thisObj); } JSValue JSFunction::callerGetter(ExecState* exec, JSValue slotBase, const Identifier&) { - JSFunction* thisObj = asFunction(slotBase); + JSFunction* thisObj = jsCast(slotBase); ASSERT(!thisObj->isHostFunction()); - return exec->interpreter()->retrieveCaller(exec, thisObj); + JSValue caller = exec->interpreter()->retrieveCallerFromVMCode(exec, thisObj); + + // See ES5.1 15.3.5.4 - Function.caller may not be used to retrieve a strict caller. + if (!caller.isObject() || !asObject(caller)->inherits(&JSFunction::s_info)) + return caller; + JSFunction* function = jsCast(caller); + if (function->isHostFunction() || !function->jsExecutable()->isStrictMode()) + return caller; + return throwTypeError(exec, "Function.caller used to retrieve strict caller"); } JSValue JSFunction::lengthGetter(ExecState*, JSValue slotBase, const Identifier&) { - JSFunction* thisObj = asFunction(slotBase); + JSFunction* thisObj = jsCast(slotBase); ASSERT(!thisObj->isHostFunction()); return jsNumber(thisObj->jsExecutable()->parameterCount()); } -static inline WriteBarrierBase* createPrototypeProperty(JSGlobalData& globalData, JSGlobalObject* globalObject, JSFunction* function) +bool JSFunction::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot) { - ASSERT(!function->isHostFunction()); - - ExecState* exec = globalObject->globalExec(); - if (WriteBarrierBase* location = function->getDirectLocation(globalData, exec->propertyNames().prototype)) - return location; - JSObject* prototype = constructEmptyObject(exec, globalObject->emptyObjectStructure()); - prototype->putDirect(globalData, exec->propertyNames().constructor, function, DontEnum); - function->putDirect(globalData, exec->propertyNames().prototype, prototype, DontDelete | DontEnum); - return function->getDirectLocation(exec->globalData(), exec->propertyNames().prototype); -} - -void JSFunction::preventExtensions(JSGlobalData& globalData) -{ - if (!isHostFunction()) - createPrototypeProperty(globalData, scope()->globalObject.get(), this); - JSObject::preventExtensions(globalData); -} - -bool JSFunction::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) -{ - if (isHostFunction()) - return Base::getOwnPropertySlot(exec, propertyName, slot); + JSFunction* thisObject = jsCast(cell); + if (thisObject->isHostFunction()) + return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); if (propertyName == exec->propertyNames().prototype) { - WriteBarrierBase* location = getDirectLocation(exec->globalData(), propertyName); + WriteBarrierBase* location = thisObject->getDirectLocation(exec->globalData(), propertyName); - if (!location) - location = createPrototypeProperty(exec->globalData(), scope()->globalObject.get(), this); + if (!location) { + JSObject* prototype = constructEmptyObject(exec, thisObject->globalObject()->emptyObjectStructure()); + prototype->putDirect(exec->globalData(), exec->propertyNames().constructor, thisObject, DontEnum); + thisObject->putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | DontEnum); + location = thisObject->getDirectLocation(exec->globalData(), exec->propertyNames().prototype); + } - slot.setValue(this, location->get(), offsetForLocation(location)); + slot.setValue(thisObject, location->get(), thisObject->offsetForLocation(location)); } if (propertyName == exec->propertyNames().arguments) { - if (jsExecutable()->isStrictMode()) { - throwTypeError(exec, "Can't access arguments object of a strict mode function"); - slot.setValue(jsNull()); - return true; + if (thisObject->jsExecutable()->isStrictMode()) { + bool result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); + if (!result) { + thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor); + result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); + ASSERT(result); + } + return result; } - - slot.setCacheableCustom(this, argumentsGetter); + slot.setCacheableCustom(thisObject, argumentsGetter); return true; } if (propertyName == exec->propertyNames().length) { - slot.setCacheableCustom(this, lengthGetter); + slot.setCacheableCustom(thisObject, lengthGetter); return true; } if (propertyName == exec->propertyNames().caller) { - if (jsExecutable()->isStrictMode()) { - throwTypeError(exec, StrictModeCallerAccessError); - slot.setValue(jsNull()); - return true; + if (thisObject->jsExecutable()->isStrictMode()) { + bool result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); + if (!result) { + thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor); + result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); + ASSERT(result); + } + return result; } - slot.setCacheableCustom(this, callerGetter); + slot.setCacheableCustom(thisObject, callerGetter); return true; } - return Base::getOwnPropertySlot(exec, propertyName, slot); + return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); } -bool JSFunction::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +bool JSFunction::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) { - if (isHostFunction()) - return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor); + JSFunction* thisObject = jsCast(object); + if (thisObject->isHostFunction()) + return Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); if (propertyName == exec->propertyNames().prototype) { PropertySlot slot; - getOwnPropertySlot(exec, propertyName, slot); - return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor); + thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, propertyName, slot); + return Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); } if (propertyName == exec->propertyNames().arguments) { - if (jsExecutable()->isStrictMode()) - createDescriptorForThrowingProperty(exec, descriptor, StrictModeArgumentsAccessError); - else - descriptor.setDescriptor(exec->interpreter()->retrieveArguments(exec, this), ReadOnly | DontEnum | DontDelete); + if (thisObject->jsExecutable()->isStrictMode()) { + bool result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); + if (!result) { + thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor); + result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); + ASSERT(result); + } + return result; + } + descriptor.setDescriptor(exec->interpreter()->retrieveArgumentsFromVMCode(exec, thisObject), ReadOnly | DontEnum | DontDelete); return true; } if (propertyName == exec->propertyNames().length) { - descriptor.setDescriptor(jsNumber(jsExecutable()->parameterCount()), ReadOnly | DontEnum | DontDelete); + descriptor.setDescriptor(jsNumber(thisObject->jsExecutable()->parameterCount()), ReadOnly | DontEnum | DontDelete); return true; } if (propertyName == exec->propertyNames().caller) { - if (jsExecutable()->isStrictMode()) - createDescriptorForThrowingProperty(exec, descriptor, StrictModeCallerAccessError); - else - descriptor.setDescriptor(exec->interpreter()->retrieveCaller(exec, this), ReadOnly | DontEnum | DontDelete); + if (thisObject->jsExecutable()->isStrictMode()) { + bool result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); + if (!result) { + thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor); + result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); + ASSERT(result); + } + return result; + } + descriptor.setDescriptor(exec->interpreter()->retrieveCallerFromVMCode(exec, thisObject), ReadOnly | DontEnum | DontDelete); return true; } - return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor); + return Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); } -void JSFunction::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +void JSFunction::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { - if (!isHostFunction() && (mode == IncludeDontEnumProperties)) { + JSFunction* thisObject = jsCast(object); + if (!thisObject->isHostFunction() && (mode == IncludeDontEnumProperties)) { // Make sure prototype has been reified. PropertySlot slot; - getOwnPropertySlot(exec, exec->propertyNames().prototype, slot); + thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, exec->propertyNames().prototype, slot); propertyNames.add(exec->propertyNames().arguments); - propertyNames.add(exec->propertyNames().callee); propertyNames.add(exec->propertyNames().caller); propertyNames.add(exec->propertyNames().length); } - Base::getOwnPropertyNames(exec, propertyNames, mode); + Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode); } -void JSFunction::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +void JSFunction::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) { - if (isHostFunction()) { - Base::put(exec, propertyName, value, slot); + JSFunction* thisObject = jsCast(cell); + if (thisObject->isHostFunction()) { + Base::put(thisObject, exec, propertyName, value, slot); return; } if (propertyName == exec->propertyNames().prototype) { // Make sure prototype has been reified, such that it can only be overwritten // following the rules set out in ECMA-262 8.12.9. PropertySlot slot; - getOwnPropertySlot(exec, propertyName, slot); + thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, propertyName, slot); } - if (jsExecutable()->isStrictMode()) { - if (propertyName == exec->propertyNames().arguments) { - throwTypeError(exec, StrictModeArgumentsAccessError); - return; - } - if (propertyName == exec->propertyNames().caller) { - throwTypeError(exec, StrictModeCallerAccessError); - return; - } + if (thisObject->jsExecutable()->isStrictMode() && (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().caller)) { + // This will trigger the property to be reified, if this is not already the case! + bool okay = thisObject->hasProperty(exec, propertyName); + ASSERT_UNUSED(okay, okay); + Base::put(thisObject, exec, propertyName, value, slot); + return; } - if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length) + if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length || propertyName == exec->propertyNames().caller) { + if (slot.isStrictMode()) + throwTypeError(exec, StrictModeReadonlyPropertyWriteError); return; - Base::put(exec, propertyName, value, slot); + } + Base::put(thisObject, exec, propertyName, value, slot); } -bool JSFunction::deleteProperty(ExecState* exec, const Identifier& propertyName) +bool JSFunction::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName) { - if (isHostFunction()) - return Base::deleteProperty(exec, propertyName); - if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length) + JSFunction* thisObject = jsCast(cell); + // For non-host functions, don't let these properties by deleted - except by DefineOwnProperty. + if (!thisObject->isHostFunction() && !exec->globalData().isInDefineOwnProperty() + && (propertyName == exec->propertyNames().arguments + || propertyName == exec->propertyNames().length + || propertyName == exec->propertyNames().prototype + || propertyName == exec->propertyNames().caller)) + return false; + return Base::deleteProperty(thisObject, exec, propertyName); +} + +bool JSFunction::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool throwException) +{ + JSFunction* thisObject = jsCast(object); + if (thisObject->isHostFunction()) + return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); + + if (propertyName == exec->propertyNames().prototype) { + // Make sure prototype has been reified, such that it can only be overwritten + // following the rules set out in ECMA-262 8.12.9. + PropertySlot slot; + thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, propertyName, slot); + return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); + } + + bool valueCheck; + if (propertyName == exec->propertyNames().arguments) { + if (thisObject->jsExecutable()->isStrictMode()) { + if (!Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor)) + thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor); + return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); + } + valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), exec->interpreter()->retrieveArgumentsFromVMCode(exec, thisObject)); + } else if (propertyName == exec->propertyNames().caller) { + if (thisObject->jsExecutable()->isStrictMode()) { + if (!Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor)) + thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor); + return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); + } + valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), exec->interpreter()->retrieveCallerFromVMCode(exec, thisObject)); + } else if (propertyName == exec->propertyNames().length) + valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), jsNumber(thisObject->jsExecutable()->parameterCount())); + else + return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); + + if (descriptor.configurablePresent() && descriptor.configurable()) { + if (throwException) + throwError(exec, createTypeError(exec, "Attempting to configurable attribute of unconfigurable property.")); + return false; + } + if (descriptor.enumerablePresent() && descriptor.enumerable()) { + if (throwException) + throwError(exec, createTypeError(exec, "Attempting to change enumerable attribute of unconfigurable property.")); + return false; + } + if (descriptor.isAccessorDescriptor()) { + if (throwException) + throwError(exec, createTypeError(exec, "Attempting to change access mechanism for an unconfigurable property.")); + return false; + } + if (descriptor.writablePresent() && descriptor.writable()) { + if (throwException) + throwError(exec, createTypeError(exec, "Attempting to change writable attribute of unconfigurable property.")); return false; - return Base::deleteProperty(exec, propertyName); + } + if (!valueCheck) { + if (throwException) + throwError(exec, createTypeError(exec, "Attempting to change value of a readonly property.")); + return false; + } + return true; } // ECMA 13.2.2 [[Construct]] -ConstructType JSFunction::getConstructData(ConstructData& constructData) +ConstructType JSFunction::getConstructData(JSCell* cell, ConstructData& constructData) { - if (isHostFunction()) - return ConstructTypeNone; - constructData.js.functionExecutable = jsExecutable(); - constructData.js.scopeChain = scope(); + JSFunction* thisObject = jsCast(cell); + if (thisObject->isHostFunction()) { + constructData.native.function = thisObject->nativeConstructor(); + return ConstructTypeHost; + } + constructData.js.functionExecutable = thisObject->jsExecutable(); + constructData.js.scopeChain = thisObject->scope(); return ConstructTypeJS; } + + +UString getCalculatedDisplayName(CallFrame* callFrame, JSObject* object) +{ + if (JSFunction* function = jsDynamicCast(object)) + return function->calculatedDisplayName(callFrame); + if (InternalFunction* function = jsDynamicCast(object)) + return function->calculatedDisplayName(callFrame); + return callFrame->globalData().propertyNames->emptyIdentifier.ustring(); +} } // namespace JSC