#include "config.h"
#include "JSObjectRef.h"
+#include "JSObjectRefPrivate.h"
#include "APICast.h"
+#include "CodeBlock.h"
#include "DateConstructor.h"
#include "ErrorConstructor.h"
#include "FunctionConstructor.h"
#include "ObjectPrototype.h"
#include "PropertyNameArray.h"
#include "RegExpConstructor.h"
-#include <wtf/Platform.h>
using namespace JSC;
? OpaqueJSClass::createNoAutomaticPrototype(definition)
: OpaqueJSClass::create(definition);
- return jsClass.release().releaseRef();
+ return jsClass.release().leakRef();
}
JSClassRef JSClassRetain(JSClassRef jsClass)
JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
if (!jsClass)
- return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure())); // slightly more efficient
+ return toRef(constructEmptyObject(exec));
- JSCallbackObject<JSObject>* object = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
+ JSCallbackObject<JSNonFinalObject>* object = JSCallbackObject<JSNonFinalObject>::create(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
if (JSObject* prototype = jsClass->prototype(exec))
- object->setPrototype(prototype);
+ object->setPrototype(exec->globalData(), prototype);
return toRef(object);
}
JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
- return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID));
+ return toRef(JSCallbackFunction::create(exec, exec->lexicalGlobalObject(), callAsFunction, nameID));
}
JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSValue jsPrototype = jsClass ? jsClass->prototype(exec) : 0;
if (!jsPrototype)
jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
- JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);
- constructor->putDirect(exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);
+ JSCallbackConstructor* constructor = JSCallbackConstructor::create(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);
+ constructor->putDirect(exec->globalData(), exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);
return toRef(constructor);
}
JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
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(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* result;
if (argumentCount) {
JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
MarkedArgumentBuffer argList;
for (size_t i = 0; i < argumentCount; ++i)
argList.append(toJS(exec, arguments[i]));
- JSObject* result = constructDate(exec, argList);
+ JSObject* result = constructDate(exec, exec->lexicalGlobalObject(), argList);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
- MarkedArgumentBuffer argList;
- for (size_t i = 0; i < argumentCount; ++i)
- argList.append(toJS(exec, arguments[i]));
+ JSValue message = argumentCount ? toJS(exec, arguments[0]) : jsUndefined();
+ Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
+ JSObject* result = ErrorInstance::create(exec, errorStructure, message);
- JSObject* result = constructError(exec, argList);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
MarkedArgumentBuffer argList;
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());
JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
return toRef(exec, jsObject->prototype());
void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
JSValue jsValue = toJS(exec, value);
- jsObject->setPrototype(jsValue.isObject() ? jsValue : jsNull());
+ jsObject->setPrototypeWithCycleCheck(exec->globalData(), jsValue.isObject() ? jsValue : jsNull());
}
bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
Identifier name(propertyName->identifier(&exec->globalData()));
JSValue jsValue = toJS(exec, value);
if (attributes && !jsObject->hasProperty(exec, name))
- jsObject->putWithAttributes(exec, name, jsValue, attributes);
+ jsObject->methodTable()->putDirectVirtual(jsObject, exec, name, jsValue, attributes);
else {
PutPropertySlot slot;
- jsObject->put(exec, name, jsValue, slot);
+ jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot);
}
if (exec->hadException()) {
JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
JSValue jsValue = toJS(exec, value);
- jsObject->put(exec, propertyIndex, jsValue);
+ jsObject->methodTable()->putByIndex(jsObject, exec, propertyIndex, jsValue, false);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
- bool result = jsObject->deleteProperty(exec, propertyName->identifier(&exec->globalData()));
+ bool result = jsObject->methodTable()->deleteProperty(jsObject, exec, propertyName->identifier(&exec->globalData()));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());
{
JSObject* jsObject = toJS(object);
- if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info))
- return static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivate();
- else if (jsObject->inherits(&JSCallbackObject<JSObject>::info))
- return static_cast<JSCallbackObject<JSObject>*>(jsObject)->getPrivate();
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info))
+ return jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivate();
+ if (jsObject->inherits(&JSCallbackObject<JSNonFinalObject>::s_info))
+ return jsCast<JSCallbackObject<JSNonFinalObject>*>(jsObject)->getPrivate();
return 0;
}
{
JSObject* jsObject = toJS(object);
- if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
- static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivate(data);
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) {
+ jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivate(data);
return true;
- } else if (jsObject->inherits(&JSCallbackObject<JSObject>::info)) {
- static_cast<JSCallbackObject<JSObject>*>(jsObject)->setPrivate(data);
+ }
+ if (jsObject->inherits(&JSCallbackObject<JSNonFinalObject>::s_info)) {
+ jsCast<JSCallbackObject<JSNonFinalObject>*>(jsObject)->setPrivate(data);
return true;
}
return false;
}
+JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* jsObject = toJS(object);
+ JSValue result;
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info))
+ result = jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivateProperty(name);
+ else if (jsObject->inherits(&JSCallbackObject<JSNonFinalObject>::s_info))
+ result = jsCast<JSCallbackObject<JSNonFinalObject>*>(jsObject)->getPrivateProperty(name);
+ return toRef(exec, result);
+}
+
+bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* jsObject = toJS(object);
+ JSValue jsValue = value ? toJS(exec, value) : JSValue();
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) {
+ jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivateProperty(exec->globalData(), name, jsValue);
+ return true;
+ }
+ if (jsObject->inherits(&JSCallbackObject<JSNonFinalObject>::s_info)) {
+ jsCast<JSCallbackObject<JSNonFinalObject>*>(jsObject)->setPrivateProperty(exec->globalData(), name, jsValue);
+ return true;
+ }
+ return false;
+}
+
+bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* jsObject = toJS(object);
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) {
+ jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->deletePrivateProperty(name);
+ return true;
+ }
+ if (jsObject->inherits(&JSCallbackObject<JSNonFinalObject>::s_info)) {
+ jsCast<JSCallbackObject<JSNonFinalObject>*>(jsObject)->deletePrivateProperty(name);
+ return true;
+ }
+ return false;
+}
+
bool JSObjectIsFunction(JSContextRef, JSObjectRef object)
{
CallData callData;
- return toJS(object)->getCallData(callData) != CallTypeNone;
+ JSCell* cell = toJS(object);
+ return cell->methodTable()->getCallData(cell, callData) != CallTypeNone;
}
JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
JSObject* jsThisObject = toJS(thisObject);
argList.append(toJS(exec, arguments[i]));
CallData callData;
- CallType callType = jsObject->getCallData(callData);
+ CallType callType = jsObject->methodTable()->getCallData(jsObject, callData);
if (callType == CallTypeNone)
return 0;
{
JSObject* jsObject = toJS(object);
ConstructData constructData;
- return jsObject->getConstructData(constructData) != ConstructTypeNone;
+ return jsObject->methodTable()->getConstructData(jsObject, constructData) != ConstructTypeNone;
}
JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSObject* jsObject = toJS(object);
ConstructData constructData;
- ConstructType constructType = jsObject->getConstructData(constructData);
+ ConstructType constructType = jsObject->methodTable()->getConstructData(jsObject, constructData);
if (constructType == ConstructTypeNone)
return 0;
}
struct OpaqueJSPropertyNameArray {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
OpaqueJSPropertyNameArray(JSGlobalData* globalData)
: refCount(0)
, globalData(globalData)
{
JSObject* jsObject = toJS(object);
ExecState* exec = toJS(ctx);
- exec->globalData().heap.registerThread();
- JSLock lock(exec);
+ APIEntryShim entryShim(exec);
JSGlobalData* globalData = &exec->globalData();
JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(globalData);
PropertyNameArray array(globalData);
- jsObject->getPropertyNames(exec, array);
+ jsObject->methodTable()->getPropertyNames(jsObject, exec, array, ExcludeDontEnumProperties);
size_t size = array.size();
propertyNames->array.reserveInitialCapacity(size);
for (size_t i = 0; i < size; ++i)
- propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].ustring()).releaseRef()));
+ propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].ustring()).leakRef()));
return JSPropertyNameArrayRetain(propertyNames);
}
void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array)
{
if (--array->refCount == 0) {
- JSLock lock(array->globalData->isSharedInstance);
+ APIEntryShim entryShim(array->globalData, false);
delete array;
}
}
void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName)
{
PropertyNameArray* propertyNames = toJS(array);
-
- propertyNames->globalData()->heap.registerThread();
- JSLock lock(propertyNames->globalData()->isSharedInstance);
-
+ APIEntryShim entryShim(propertyNames->globalData());
propertyNames->add(propertyName->identifier(propertyNames->globalData()));
}