Commit 81aa89f0 authored by barraclough@apple.com's avatar barraclough@apple.com

Remove JSObject defineGetter/defineSetter lookupGetter/lookupSetter

https://bugs.webkit.org/show_bug.cgi?id=77451

Reviewed by Sam Weinig.

These can now all be implemented in terms of defineOwnProperty & getPropertyDescriptor.
Also remove initializeGetterSetterProperty, since this is equivalent to putDirectAccessor.

Source/JavaScriptCore: 

* JavaScriptCore.exp:
* debugger/DebuggerActivation.cpp:
(JSC::DebuggerActivation::defineOwnProperty):
* debugger/DebuggerActivation.h:
(DebuggerActivation):
* runtime/ClassInfo.h:
(MethodTable):
(JSC):
* runtime/JSBoundFunction.cpp:
(JSC::JSBoundFunction::finishCreation):
* runtime/JSCell.cpp:
(JSC):
* runtime/JSCell.h:
(JSCell):
* runtime/JSFunction.cpp:
(JSC::JSFunction::getOwnPropertySlot):
(JSC::JSFunction::getOwnPropertyDescriptor):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::defineOwnProperty):
(JSC):
* runtime/JSGlobalObject.h:
(JSGlobalObject):
* runtime/JSObject.cpp:
(JSC):
* runtime/JSObject.h:
(JSObject):
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncDefineGetter):
(JSC::objectProtoFuncDefineSetter):
(JSC::objectProtoFuncLookupGetter):
(JSC::objectProtoFuncLookupSetter):

Source/WebCore: 

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore):
(WebCore::JSDOMWindow::defineOwnProperty):
* bindings/js/JSDOMWindowShell.cpp:
(WebCore):
* bindings/js/JSDOMWindowShell.h:
(JSDOMWindowShell):
* bindings/js/JSLocationCustom.cpp:
(WebCore::JSLocation::defineOwnProperty):
(WebCore::JSLocationPrototype::defineOwnProperty):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateHeader):
* page/DOMWindow.idl:
* page/Location.idl:

Source/WebKit/qt: 

* Api/qwebframe.cpp:
(QWebFramePrivate::addQtSenderToGlobalObject):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106783 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7c08fda1
2012-02-05 Gavin Barraclough <barraclough@apple.com>
Remove JSObject defineGetter/defineSetter lookupGetter/lookupSetter
https://bugs.webkit.org/show_bug.cgi?id=77451
Reviewed by Sam Weinig.
These can now all be implemented in terms of defineOwnProperty & getPropertyDescriptor.
Also remove initializeGetterSetterProperty, since this is equivalent to putDirectAccessor.
* JavaScriptCore.exp:
* debugger/DebuggerActivation.cpp:
(JSC::DebuggerActivation::defineOwnProperty):
* debugger/DebuggerActivation.h:
(DebuggerActivation):
* runtime/ClassInfo.h:
(MethodTable):
(JSC):
* runtime/JSBoundFunction.cpp:
(JSC::JSBoundFunction::finishCreation):
* runtime/JSCell.cpp:
(JSC):
* runtime/JSCell.h:
(JSCell):
* runtime/JSFunction.cpp:
(JSC::JSFunction::getOwnPropertySlot):
(JSC::JSFunction::getOwnPropertyDescriptor):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::defineOwnProperty):
(JSC):
* runtime/JSGlobalObject.h:
(JSGlobalObject):
* runtime/JSObject.cpp:
(JSC):
* runtime/JSObject.h:
(JSObject):
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncDefineGetter):
(JSC::objectProtoFuncDefineSetter):
(JSC::objectProtoFuncLookupGetter):
(JSC::objectProtoFuncLookupSetter):
2012-02-06 Carlos Garcia Campos <cgarcia@igalia.com>
Unreviewed. Fix make distcheck.
......@@ -135,11 +135,8 @@ EXPORTS
?decrement@RefCountedLeakCounter@WTF@@QAEXXZ
?defaultAttributes@PropertyDescriptor@JSC@@0IA
?defaultValue@JSObject@JSC@@SA?AVJSValue@2@PBV12@PAVExecState@2@W4PreferredPrimitiveType@2@@Z
?defineGetter@JSGlobalObject@JSC@@SAXPAVJSObject@2@PAVExecState@2@ABVIdentifier@2@0I@Z
?defineGetter@JSObject@JSC@@SAXPAV12@PAVExecState@2@ABVIdentifier@2@0I@Z
?defineOwnProperty@JSGlobalObject@JSC@@SA_NPAVJSObject@2@PAVExecState@2@ABVIdentifier@2@AAVPropertyDescriptor@2@_N@Z
?defineOwnProperty@JSObject@JSC@@SA_NPAV12@PAVExecState@2@ABVIdentifier@2@AAVPropertyDescriptor@2@_N@Z
?defineSetter@JSGlobalObject@JSC@@SAXPAVJSObject@2@PAVExecState@2@ABVIdentifier@2@0I@Z
?defineSetter@JSObject@JSC@@SAXPAV12@PAVExecState@2@ABVIdentifier@2@0I@Z
?deleteOwnedPtr@WTF@@YAXPAUHBITMAP__@@@Z
?deleteOwnedPtr@WTF@@YAXPAUHBRUSH__@@@Z
?deleteOwnedPtr@WTF@@YAXPAUHDC__@@@Z
......@@ -178,7 +175,7 @@ EXPORTS
?fastRealloc@WTF@@YAPAXPAXI@Z
?fastStrDup@WTF@@YAPADPBD@Z
?fastZeroedMalloc@WTF@@YAPAXI@Z
?fillGetterPropertySlot@JSObject@JSC@@QAEXAAVPropertySlot@2@PAV?$WriteBarrierBase@W4Unknown@JSC@@@2@@Z
?fillGetterPropertySlot@JSObject@JSC@@AAEXAAVPropertySlot@2@PAV?$WriteBarrierBase@W4Unknown@JSC@@@2@@Z
?finalize@WeakHandleOwner@JSC@@UAEXV?$Handle@W4Unknown@JSC@@@2@PAX@Z
?finishCreation@DateInstance@JSC@@IAEXAAVJSGlobalData@2@N@Z
?finishCreation@InternalFunction@JSC@@IAEXAAVJSGlobalData@2@ABVIdentifier@2@@Z
......
......@@ -101,16 +101,10 @@ bool DebuggerActivation::getOwnPropertyDescriptor(JSObject* object, ExecState* e
return thisObject->m_activation->methodTable()->getOwnPropertyDescriptor(thisObject->m_activation.get(), exec, propertyName, descriptor);
}
void DebuggerActivation::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
bool DebuggerActivation::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
{
DebuggerActivation* thisObject = jsCast<DebuggerActivation*>(object);
thisObject->m_activation->methodTable()->defineGetter(thisObject->m_activation.get(), exec, propertyName, getterFunction, attributes);
}
void DebuggerActivation::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes)
{
DebuggerActivation* thisObject = jsCast<DebuggerActivation*>(object);
thisObject->m_activation->methodTable()->defineSetter(thisObject->m_activation.get(), exec, propertyName, setterFunction, attributes);
return thisObject->m_activation->methodTable()->defineOwnProperty(thisObject->m_activation.get(), exec, propertyName, descriptor, shouldThrow);
}
} // namespace JSC
......@@ -49,8 +49,7 @@ namespace JSC {
static bool deleteProperty(JSCell*, ExecState*, const Identifier& propertyName);
static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);
static void defineGetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes);
static void defineSetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes);
static bool defineOwnProperty(JSObject*, ExecState*, const Identifier& propertyName, PropertyDescriptor&, bool shouldThrow);
JS_EXPORTDATA static const ClassInfo s_info;
......
......@@ -66,12 +66,6 @@ namespace JSC {
typedef JSObject* (*ToThisObjectFunctionPtr)(JSCell*, ExecState*);
ToThisObjectFunctionPtr toThisObject;
typedef void (*DefineGetterFunctionPtr)(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned);
DefineGetterFunctionPtr defineGetter;
typedef void (*DefineSetterFunctionPtr)(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned);
DefineSetterFunctionPtr defineSetter;
typedef JSValue (*DefaultValueFunctionPtr)(const JSObject*, ExecState*, PreferredPrimitiveType);
DefaultValueFunctionPtr defaultValue;
......@@ -128,8 +122,6 @@ struct MemberCheck##member { \
&ClassName::getOwnPropertySlot, \
&ClassName::getOwnPropertySlotByIndex, \
&ClassName::toThisObject, \
&ClassName::defineGetter, \
&ClassName::defineSetter, \
&ClassName::defaultValue, \
&ClassName::getOwnPropertyNames, \
&ClassName::getPropertyNames, \
......
......@@ -26,6 +26,7 @@
#include "config.h"
#include "JSBoundFunction.h"
#include "GetterSetter.h"
#include "JSGlobalObject.h"
namespace JSC {
......@@ -111,8 +112,8 @@ void JSBoundFunction::finishCreation(ExecState* exec, NativeExecutable* executab
Base::finishCreation(exec, executable, length, name);
ASSERT(inherits(&s_info));
initializeGetterSetterProperty(exec, exec->propertyNames().arguments, globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
initializeGetterSetterProperty(exec, exec->propertyNames().caller, globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
putDirectAccessor(exec->globalData(), exec->propertyNames().arguments, globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
putDirectAccessor(exec->globalData(), exec->propertyNames().caller, globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
}
void JSBoundFunction::visitChildren(JSCell* cell, SlotVisitor& visitor)
......
......@@ -158,16 +158,6 @@ void slowValidateCell(JSCell* cell)
ASSERT_GC_OBJECT_LOOKS_VALID(cell);
}
void JSCell::defineGetter(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned)
{
ASSERT_NOT_REACHED();
}
void JSCell::defineSetter(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned)
{
ASSERT_NOT_REACHED();
}
JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
{
ASSERT_NOT_REACHED();
......
......@@ -152,8 +152,6 @@ namespace JSC {
static bool getOwnPropertySlotByIndex(JSCell*, ExecState*, unsigned propertyName, PropertySlot&);
// Dummy implementations of override-able static functions for classes to put in their MethodTable
static NO_RETURN_DUE_TO_ASSERT void defineGetter(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned);
static NO_RETURN_DUE_TO_ASSERT void defineSetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes = 0);
static JSValue defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType);
static NO_RETURN_DUE_TO_ASSERT void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
static NO_RETURN_DUE_TO_ASSERT void getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
......
......@@ -30,6 +30,7 @@
#include "CallFrame.h"
#include "ExceptionHelpers.h"
#include "FunctionPrototype.h"
#include "GetterSetter.h"
#include "JSArray.h"
#include "JSGlobalObject.h"
#include "JSNotAnObject.h"
......@@ -219,7 +220,7 @@ bool JSFunction::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identif
if (thisObject->jsExecutable()->isStrictMode()) {
bool result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
if (!result) {
thisObject->initializeGetterSetterProperty(exec, propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
ASSERT(result);
}
......@@ -238,7 +239,7 @@ bool JSFunction::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identif
if (thisObject->jsExecutable()->isStrictMode()) {
bool result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
if (!result) {
thisObject->initializeGetterSetterProperty(exec, propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
result = Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
ASSERT(result);
}
......@@ -267,7 +268,7 @@ bool JSFunction::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, con
if (thisObject->jsExecutable()->isStrictMode()) {
bool result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
if (!result) {
thisObject->initializeGetterSetterProperty(exec, propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
ASSERT(result);
}
......@@ -286,7 +287,7 @@ bool JSFunction::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, con
if (thisObject->jsExecutable()->isStrictMode()) {
bool result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
if (!result) {
thisObject->initializeGetterSetterProperty(exec, propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
thisObject->putDirectAccessor(exec->globalData(), propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
result = Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
ASSERT(result);
}
......
......@@ -171,21 +171,16 @@ void JSGlobalObject::putDirectVirtual(JSObject* object, ExecState* exec, const I
}
}
void JSGlobalObject::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes)
bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
{
JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
PropertySlot slot;
if (!thisObject->symbolTableGet(propertyName, slot))
JSVariableObject::defineGetter(thisObject, exec, propertyName, getterFunc, attributes);
// silently ignore attempts to add accessors aliasing vars.
if (descriptor.isAccessorDescriptor() && thisObject->symbolTableGet(propertyName, slot))
return false;
return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
}
void JSGlobalObject::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes)
{
JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
PropertySlot slot;
if (!thisObject->symbolTableGet(propertyName, slot))
JSVariableObject::defineSetter(thisObject, exec, propertyName, setterFunc, attributes);
}
static inline JSObject* lastInPrototypeChain(JSObject* object)
{
......
......@@ -206,6 +206,7 @@ namespace JSC {
JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes);
JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes);
JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, const Identifier& propertyName, PropertyDescriptor&, bool shouldThrow);
// We use this in the code generator as we perform symbol table
// lookups prior to initializing the properties
......
......@@ -361,106 +361,6 @@ const HashEntry* JSObject::findPropertyHashEntry(ExecState* exec, const Identifi
return 0;
}
void JSObject::defineGetter(JSObject* thisObject, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
{
if (propertyName == exec->propertyNames().underscoreProto) {
// Defining a getter for __proto__ is silently ignored.
return;
}
JSValue object = thisObject->getDirect(exec->globalData(), propertyName);
if (object && object.isGetterSetter()) {
ASSERT(thisObject->structure()->hasGetterSetterProperties());
asGetterSetter(object)->setGetter(exec->globalData(), getterFunction);
return;
}
JSGlobalData& globalData = exec->globalData();
PutPropertySlot slot;
GetterSetter* getterSetter = GetterSetter::create(exec);
thisObject->putDirectInternal<PutModeDefineOwnProperty>(globalData, propertyName, getterSetter, attributes | Accessor, slot, 0);
// putDirect will change our Structure if we add a new property. For
// getters and setters, though, we also need to change our Structure
// if we override an existing non-getter or non-setter.
if (slot.type() != PutPropertySlot::NewProperty)
thisObject->setStructure(exec->globalData(), Structure::attributeChangeTransition(globalData, thisObject->structure(), propertyName, attributes | Accessor));
thisObject->structure()->setHasGetterSetterProperties(true);
getterSetter->setGetter(globalData, getterFunction);
}
void JSObject::initializeGetterSetterProperty(ExecState* exec, const Identifier& propertyName, GetterSetter* getterSetter, unsigned attributes)
{
// Set an inital property on an object; the property must not already exist & the attribute flags must be set correctly.
ASSERT(structure()->get(exec->globalData(), propertyName) == WTF::notFound);
ASSERT(static_cast<bool>(attributes & Accessor));
JSGlobalData& globalData = exec->globalData();
PutPropertySlot slot;
putDirectInternal<PutModeDefineOwnProperty>(globalData, propertyName, getterSetter, attributes, slot, 0);
// putDirect will change our Structure if we add a new property. For
// getters and setters, though, we also need to change our Structure
// if we override an existing non-getter or non-setter.
if (slot.type() != PutPropertySlot::NewProperty)
setStructure(exec->globalData(), Structure::attributeChangeTransition(globalData, structure(), propertyName, attributes));
structure()->setHasGetterSetterProperties(true);
}
void JSObject::defineSetter(JSObject* thisObject, ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes)
{
if (propertyName == exec->propertyNames().underscoreProto) {
// Defining a setter for __proto__ is silently ignored.
return;
}
JSValue object = thisObject->getDirect(exec->globalData(), propertyName);
if (object && object.isGetterSetter()) {
ASSERT(thisObject->structure()->hasGetterSetterProperties());
asGetterSetter(object)->setSetter(exec->globalData(), setterFunction);
return;
}
PutPropertySlot slot;
GetterSetter* getterSetter = GetterSetter::create(exec);
thisObject->putDirectInternal<PutModeDefineOwnProperty>(exec->globalData(), propertyName, getterSetter, attributes | Accessor, slot, 0);
// putDirect will change our Structure if we add a new property. For
// getters and setters, though, we also need to change our Structure
// if we override an existing non-getter or non-setter.
if (slot.type() != PutPropertySlot::NewProperty)
thisObject->setStructure(exec->globalData(), Structure::attributeChangeTransition(exec->globalData(), thisObject->structure(), propertyName, attributes | Accessor));
thisObject->structure()->setHasGetterSetterProperties(true);
getterSetter->setSetter(exec->globalData(), setterFunction);
}
JSValue JSObject::lookupGetter(ExecState* exec, const Identifier& propertyName)
{
PropertyDescriptor descriptor;
if (!getPropertyDescriptor(exec, propertyName, descriptor))
return jsUndefined();
if (!descriptor.getterPresent())
return jsUndefined();
return descriptor.getter();
}
JSValue JSObject::lookupSetter(ExecState* exec, const Identifier& propertyName)
{
PropertyDescriptor descriptor;
if (!getPropertyDescriptor(exec, propertyName, descriptor))
return jsUndefined();
if (!descriptor.setterPresent())
return jsUndefined();
return descriptor.setter();
}
bool JSObject::hasInstance(JSObject*, ExecState* exec, JSValue value, JSValue proto)
{
if (!value.isObject())
......
......@@ -192,13 +192,6 @@ namespace JSC {
void putDirectOffset(JSGlobalData& globalData, size_t offset, JSValue value) { propertyStorage()[offset].set(globalData, this, value); }
void putUndefinedAtDirectOffset(size_t offset) { propertyStorage()[offset].setUndefined(); }
JS_EXPORT_PRIVATE void fillGetterPropertySlot(PropertySlot&, WriteBarrierBase<Unknown>* location);
void initializeGetterSetterProperty(ExecState*, const Identifier&, GetterSetter*, unsigned attributes);
JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes = 0);
JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes = 0);
JS_EXPORT_PRIVATE JSValue lookupGetter(ExecState*, const Identifier& propertyName);
JS_EXPORT_PRIVATE JSValue lookupSetter(ExecState*, const Identifier& propertyName);
JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, const Identifier& propertyName, PropertyDescriptor&, bool shouldThrow);
bool isGlobalObject() const;
......@@ -296,6 +289,7 @@ namespace JSC {
bool putDirectInternal(JSGlobalData&, const Identifier& propertyName, JSValue, unsigned attr, PutPropertySlot&, JSCell*);
bool inlineGetOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
JS_EXPORT_PRIVATE void fillGetterPropertySlot(PropertySlot&, WriteBarrierBase<Unknown>* location);
const HashEntry* findPropertyHashEntry(ExecState*, const Identifier& propertyName) const;
Structure* createInheritorID(JSGlobalData&);
......
......@@ -146,10 +146,17 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState* exec)
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSValue get = exec->argument(1);
CallData callData;
if (getCallData(exec->argument(1), callData) == CallTypeNone)
if (getCallData(get, callData) == CallTypeNone)
return throwVMError(exec, createSyntaxError(exec, "invalid getter usage"));
thisObject->methodTable()->defineGetter(thisObject, exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), asObject(exec->argument(1)), 0);
PropertyDescriptor descriptor;
descriptor.setGetter(get);
descriptor.setEnumerable(true);
descriptor.setConfigurable(true);
thisObject->methodTable()->defineOwnProperty(thisObject, exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), descriptor, false);
return JSValue::encode(jsUndefined());
}
......@@ -159,10 +166,17 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec)
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSValue set = exec->argument(1);
CallData callData;
if (getCallData(exec->argument(1), callData) == CallTypeNone)
if (getCallData(set, callData) == CallTypeNone)
return throwVMError(exec, createSyntaxError(exec, "invalid setter usage"));
thisObject->methodTable()->defineSetter(thisObject, exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), asObject(exec->argument(1)), 0);
PropertyDescriptor descriptor;
descriptor.setSetter(set);
descriptor.setEnumerable(true);
descriptor.setConfigurable(true);
thisObject->methodTable()->defineOwnProperty(thisObject, exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), descriptor, false);
return JSValue::encode(jsUndefined());
}
......@@ -172,7 +186,12 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupGetter(ExecState* exec)
if (exec->hadException())
return JSValue::encode(jsUndefined());
return JSValue::encode(thisObject->lookupGetter(exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec))));
PropertyDescriptor descriptor;
if (thisObject->getPropertyDescriptor(exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), descriptor)
&& descriptor.getterPresent())
return JSValue::encode(descriptor.getter());
return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState* exec)
......@@ -181,7 +200,12 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState* exec)
if (exec->hadException())
return JSValue::encode(jsUndefined());
return JSValue::encode(thisObject->lookupSetter(exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec))));
PropertyDescriptor descriptor;
if (thisObject->getPropertyDescriptor(exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), descriptor)
&& descriptor.setterPresent())
return JSValue::encode(descriptor.setter());
return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL objectProtoFuncPropertyIsEnumerable(ExecState* exec)
......
2012-02-05 Gavin Barraclough <barraclough@apple.com>
Remove JSObject defineGetter/defineSetter lookupGetter/lookupSetter
https://bugs.webkit.org/show_bug.cgi?id=77451
Reviewed by Sam Weinig.
These can now all be implemented in terms of defineOwnProperty & getPropertyDescriptor.
Also remove initializeGetterSetterProperty, since this is equivalent to putDirectAccessor.
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore):
(WebCore::JSDOMWindow::defineOwnProperty):
* bindings/js/JSDOMWindowShell.cpp:
(WebCore):
* bindings/js/JSDOMWindowShell.h:
(JSDOMWindowShell):
* bindings/js/JSLocationCustom.cpp:
(WebCore::JSLocation::defineOwnProperty):
(WebCore::JSLocationPrototype::defineOwnProperty):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateHeader):
* page/DOMWindow.idl:
* page/Location.idl:
2012-02-06 Carlos Garcia Campos <cgarcia@igalia.com>
Unreviewed. Fix make distrcheck.
......@@ -388,35 +388,17 @@ void JSDOMWindow::getOwnPropertyNames(JSObject* object, ExecState* exec, Propert
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
void JSDOMWindow::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
{
JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
// Only allow defining getters by frames in the same origin.
if (!thisObject->allowsAccessFrom(exec))
return;
// Don't allow shadowing location using defineGetter.
if (propertyName == "location")
return;
Base::defineGetter(thisObject, exec, propertyName, getterFunction, attributes);
}
void JSDOMWindow::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes)
{
JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
// Only allow defining setters by frames in the same origin.
if (!thisObject->allowsAccessFrom(exec))
return;
Base::defineSetter(thisObject, exec, propertyName, setterFunction, attributes);
}
bool JSDOMWindow::defineOwnProperty(JSC::JSObject* object, JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor, bool shouldThrow)
{
JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
// Only allow defining properties in this way by frames in the same origin, as it allows setters to be introduced.
if (!thisObject->allowsAccessFrom(exec))
return false;
// Don't allow shadowing location using accessor properties.
if (descriptor.isAccessorDescriptor() && propertyName == "location")
return false;
return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
}
......
......@@ -139,18 +139,6 @@ void JSDOMWindowShell::getOwnPropertyNames(JSObject* object, ExecState* exec, Pr
thisObject->window()->methodTable()->getOwnPropertyNames(thisObject->window(), exec, propertyNames, mode);
}
void JSDOMWindowShell::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
{
JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
thisObject->window()->methodTable()->defineGetter(thisObject->window(), exec, propertyName, getterFunction, attributes);
}
void JSDOMWindowShell::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes)
{
JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
thisObject->window()->methodTable()->defineSetter(thisObject->window(), exec, propertyName, setterFunction, attributes);
}
// ----
// JSDOMWindow methods
......
......@@ -86,8 +86,6 @@ namespace WebCore {
static bool deleteProperty(JSC::JSCell*, JSC::ExecState*, const JSC::Identifier& propertyName);
static void getOwnPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode);
static void getPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode);
static void defineGetter(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes);
static void defineSetter(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes);
static bool defineOwnProperty(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&, bool shouldThrow);
RefPtr<DOMWrapperWorld> m_world;
......
......@@ -170,11 +170,11 @@ void JSLocation::getOwnPropertyNames(JSObject* object, ExecState* exec, Property
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
void JSLocation::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
bool JSLocation::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool throwException)
{
if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf)
return;
Base::defineGetter(object, exec, propertyName, getterFunction, attributes);
if (descriptor.isAccessorDescriptor() && (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf))
return false;
return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
void JSLocation::setHref(ExecState* exec, JSValue value)
......@@ -281,11 +281,11 @@ bool JSLocationPrototype::putDelegate(ExecState* exec, const Identifier& propert
return (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf);
}
void JSLocationPrototype::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
bool JSLocationPrototype::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool throwException)
{
if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf)
return;
Base::defineGetter(object, exec, propertyName, getterFunction, attributes);
if (descriptor.isAccessorDescriptor() && (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf))
return false;
return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
} // namespace WebCore
......@@ -827,20 +827,14 @@ sub GenerateHeader
$structureFlags{"JSC::OverridesGetPropertyNames"} = 1;
}
# Custom defineProperty function exists on DOMWindow
push(@headerContent, " static bool defineOwnProperty(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&, bool shouldThrow);\n") if $interfaceName eq "DOMWindow";
# Custom getOwnPropertyNames function
if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"} || $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
push(@headerContent, " static void getOwnPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);\n");
$structureFlags{"JSC::OverridesGetPropertyNames"} = 1;
}
# Custom defineGetter function
push(@headerContent, " static void defineGetter(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes);\n") if $dataNode->extendedAttributes->{"CustomDefineGetter"};
# Custom defineSetter function
push(@headerContent, " static void defineSetter(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes);\n") if $dataNode->extendedAttributes->{"CustomDefineSetter"};
# Custom defineOwnProperty function
push(@headerContent, " static bool defineOwnProperty(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&, bool shouldThrow);\n") if $dataNode->extendedAttributes->{"CustomDefineOwnProperty"};
# Override toBoolean to return false for objects that want to 'MasqueradesAsUndefined'.
if ($dataNode->extendedAttributes->{"MasqueradesAsUndefined"}) {
......@@ -1060,8 +1054,8 @@ sub GenerateHeader
push(@headerContent, " bool putDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, JSC::PutPropertySlot&);\n");
}
# Custom defineGetter function
push(@headerContent, " static void defineGetter(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes);\n") if $dataNode->extendedAttributes->{"CustomPrototypeDefineGetter"};
# Custom defineOwnProperty function
push(@headerContent, " static bool defineOwnProperty(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&, bool shouldThrow);\n") if $dataNode->extendedAttributes->{"CustomPrototypeDefineOwnProperty"};
push(@headerContent, "\nprivate:\n");
push(@headerContent, " ${className}Prototype(JSC::JSGlobalData& globalData, JSC::JSGlobalObject*, JSC::Structure* structure) : JSC::JSNonFinalObject(globalData, structure) { }\n");
......
......@@ -28,8 +28,7 @@ module window {
interface [
CheckDomainSecurity,
CustomDefineGetter,
CustomDefineSetter,
CustomDefineOwnProperty,
CustomDeleteProperty,
CustomGetOwnPropertySlot,