+2005-10-05 Maciej Stachowiak <mjs@apple.com>
+
+ Reviewed by Eric and Darin.
+
+ <rdar://problem/4260506> Port JavaScriptGlue to TOT JavaScriptCore
+
+ * JSRun.cpp:
+ (JSRun::JSRun):
+ (JSRun::GlobalObject):
+ * JSRun.h:
+ (JSInterpreter::JSInterpreter):
+ * JSUtils.cpp:
+ (KJSValueToJSObject):
+ (JSObjectKJSValue):
+ (KJSValueToCFTypeInternal):
+ (KJSValueToCFType):
+ * JSUtils.h:
+ * JSValueWrapper.cpp:
+ (JSValueWrapper::JSValueWrapper):
+ (JSValueWrapper::GetValue):
+ (JSValueWrapper::JSObjectCopyPropertyNames):
+ (JSValueWrapper::JSObjectCopyProperty):
+ (JSValueWrapper::JSObjectSetProperty):
+ (JSValueWrapper::JSObjectCallFunction):
+ (JSValueWrapper::JSObjectMark):
+ * JSValueWrapper.h:
+ * JavaScriptGlue.cpp:
+ (JSRunCopyGlobalObject):
+ * JavaScriptGlue.xcodeproj/project.pbxproj:
+ * Makefile.am: Added.
+ * UserObjectImp.cpp:
+ (UserObjectPrototypeImp::GlobalUserObjectPrototypeImp):
+ (UserObjectImp::UserObjectImp):
+ (UserObjectImp::callAsFunction):
+ (UserObjectImp::getPropertyNames):
+ (UserObjectImp::userObjectGetter):
+ (UserObjectImp::getOwnPropertySlot):
+ (UserObjectImp::put):
+ (UserObjectImp::toPrimitive):
+ (UserObjectImp::mark):
+ * UserObjectImp.h:
+ * kxmlcore/FastMalloc.h: Added.
+ * kxmlcore/HashSet.h: Added.
+
2005-09-14 Maciej Stachowiak <mjs@apple.com>
Reviewed by Geoff.
JSRun::JSRun(CFStringRef source, JSFlags inFlags)
: JSBase(kJSRunTypeID),
fSource(CFStringToUString(source)),
- fGlobalObject(Object(new ObjectImp())),
+ fGlobalObject(new ObjectImp()),
fInterpreter(fGlobalObject, inFlags),
fFlags(inFlags)
{
return fSource;
}
-Object JSRun::GlobalObject() const
+ObjectImp *JSRun::GlobalObject() const
{
return fGlobalObject;
}
class JSInterpreter : public Interpreter {
public:
- JSInterpreter(const Object &global, JSFlags flags) : Interpreter(global), fJSFlags(flags) { }
- JSInterpreter(const Object &global) : Interpreter(global), fJSFlags(kJSFlagNone) { }
+ JSInterpreter(ObjectImp *global, JSFlags flags) : Interpreter(global), fJSFlags(flags) { }
+ JSInterpreter(ObjectImp *global) : Interpreter(global), fJSFlags(kJSFlagNone) { }
JSInterpreter() : Interpreter(), fJSFlags(kJSFlagNone) { }
JSInterpreter::~JSInterpreter() { }
JSFlags Flags() const { return fJSFlags; }
virtual ~JSRun();
UString GetSource() const;
- Object GlobalObject() const;
+ ObjectImp *GlobalObject() const;
JSInterpreter* GetInterpreter();
Completion Evaluate();
bool CheckSyntax();
JSFlags Flags() const;
private:
UString fSource;
- ProtectedObject fGlobalObject;
+ ProtectedPtr<ObjectImp> fGlobalObject;
JSInterpreter fInterpreter;
JSFlags fFlags;
};
-#endif
\ No newline at end of file
+#endif
#include "UserObjectImp.h"
#include "JSValueWrapper.h"
#include "JSObject.h"
+#include "JavaScriptCore/IdentifierSequencedSet.h"
struct ObjectImpList {
ObjectImp* imp;
CFTypeRef data;
};
-static CFTypeRef KJSValueToCFTypeInternal(const Value& inValue, ExecState *exec, ObjectImpList* inImps);
+static CFTypeRef KJSValueToCFTypeInternal(ValueImp *inValue, ExecState *exec, ObjectImpList* inImps);
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// KJSValueToJSObject
//--------------------------------------------------------------------------
-JSUserObject* KJSValueToJSObject(const Value& inValue, ExecState *exec)
+JSUserObject* KJSValueToJSObject(ValueImp *inValue, ExecState *exec)
{
- JSUserObject* result = NULL;
-#if JAG_PINK_OR_LATER
- UserObjectImp* userObjectImp;
- if (inValue.type() == ObjectType && (userObjectImp = dynamic_cast<UserObjectImp*>(inValue.imp())))
-#else
- if (UserObjectImp* userObjectImp = dynamic_cast<UserObjectImp*>(inValue.imp()))
-#endif
- {
- result = userObjectImp->GetJSUserObject();
- if (result) result->Retain();
- }
- else
- {
- JSValueWrapper* wrapperValue = new JSValueWrapper(inValue, exec);
- if (wrapperValue)
- {
- JSObjectCallBacks callBacks;
- JSValueWrapper::GetJSObectCallBacks(callBacks);
- result = (JSUserObject*)JSObjectCreate(wrapperValue, &callBacks);
- if (!result)
- {
- delete wrapperValue;
- }
- }
- }
- return result;
+ JSUserObject* result = NULL;
+
+ if (inValue->isObject(&UserObjectImp::info)) {
+ UserObjectImp* userObjectImp = static_cast<UserObjectImp *>(inValue);
+ result = userObjectImp->GetJSUserObject();
+ if (result)
+ result->Retain();
+ } else {
+ JSValueWrapper* wrapperValue = new JSValueWrapper(inValue, exec);
+ if (wrapperValue) {
+ JSObjectCallBacks callBacks;
+ JSValueWrapper::GetJSObectCallBacks(callBacks);
+ result = (JSUserObject*)JSObjectCreate(wrapperValue, &callBacks);
+ if (!result) {
+ delete wrapperValue;
+ }
+ }
+ }
+ return result;
}
//--------------------------------------------------------------------------
// JSObjectKJSValue
//--------------------------------------------------------------------------
-Value JSObjectKJSValue(JSUserObject* ptr)
+ValueImp *JSObjectKJSValue(JSUserObject* ptr)
{
InterpreterLock lock;
- Value result = Undefined();
+ ValueImp *result = Undefined();
if (ptr)
{
bool handled = false;
}
if (!handled)
{
- result = Object(new UserObjectImp(ptr));
+ result = new UserObjectImp(ptr);
}
}
return result;
// KJSValueToCFTypeInternal
//--------------------------------------------------------------------------
// Caller is responsible for releasing the returned CFTypeRef
-CFTypeRef KJSValueToCFTypeInternal(const Value& inValue, ExecState *exec, ObjectImpList* inImps)
+CFTypeRef KJSValueToCFTypeInternal(ValueImp *inValue, ExecState *exec, ObjectImpList* inImps)
{
-#if JAG_PINK_OR_LATER
- if (inValue.isNull())
+ if (inValue)
return NULL;
-#endif
CFTypeRef result = NULL;
InterpreterLock lock;
- switch (inValue.type())
+ switch (inValue->type())
{
case BooleanType:
{
- result = inValue.toBoolean(exec) ? kCFBooleanTrue : kCFBooleanFalse;
+ result = inValue->toBoolean(exec) ? kCFBooleanTrue : kCFBooleanFalse;
RetainCFType(result);
}
break;
case StringType:
{
- UString uString = inValue.toString(exec);
+ UString uString = inValue->toString(exec);
result = UStringToCFString(uString);
}
break;
case NumberType:
{
- double number1 = inValue.toNumber(exec);
- double number2 = (double)inValue.toInteger(exec);
+ double number1 = inValue->toNumber(exec);
+ double number2 = (double)inValue->toInteger(exec);
if (number1 == number2)
{
int intValue = (int)number2;
case ObjectType:
{
- if (UserObjectImp* userObjectImp = dynamic_cast<UserObjectImp*>(inValue.imp()))
- {
+ if (inValue->isObject(&UserObjectImp::info)) {
+ UserObjectImp* userObjectImp = static_cast<UserObjectImp *>(inValue);
JSUserObject* ptr = userObjectImp->GetJSUserObject();
if (ptr)
{
}
else
{
- Object object = inValue.toObject(exec);
+ ObjectImp *object = inValue->toObject(exec);
UInt8 isArray = false;
// if two objects reference each
- ObjectImp* imp = object.imp();
+ ObjectImp* imp = object;
ObjectImpList* temp = inImps;
while (temp) {
if (imp == temp->imp) {
//[...] HACK since we do not have access to the class info we use class name instead
#if 0
- if (object.inherits(&ArrayInstanceImp::info))
+ if (object->inherits(&ArrayInstanceImp::info))
#else
- if (object.className() == "Array")
+ if (object->className() == "Array")
#endif
{
isArray = true;
#if JAG_PINK_OR_LATER
JSInterpreter* intrepreter = (JSInterpreter*)exec->dynamicInterpreter();
if (intrepreter && (intrepreter->Flags() & kJSFlagConvertAssociativeArray)) {
- ReferenceList propList = object.propList(exec, false);
- ReferenceListIterator iter = propList.begin();
- ReferenceListIterator end = propList.end();
+ IdentifierSequencedSet propList;
+ object->getPropertyNames(exec, propList);
+ IdentifierSequencedSetIterator iter = propList.begin();
+ IdentifierSequencedSetIterator end = propList.end();
while(iter != end && isArray)
{
- Identifier propName = iter->getPropertyName(exec);
+ Identifier propName = *iter;
UString ustr = propName.ustring();
const UniChar* uniChars = (const UniChar*)ustr.data();
int size = ustr.size();
break;
}
}
- iter++;
+ ++iter;
}
}
#endif
if (isArray)
{
// This is an KJS array
- unsigned int length = object.get(exec, "length").toUInt32(exec);
+ unsigned int length = object->get(exec, "length")->toUInt32(exec);
result = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
if (result)
{
#if JAG_PINK_OR_LATER
for (unsigned i = 0; i < length; i++)
{
- CFTypeRef cfValue = KJSValueToCFTypeInternal(object.get(exec, i), exec, &imps);
+ CFTypeRef cfValue = KJSValueToCFTypeInternal(object->get(exec, i), exec, &imps);
CFArrayAppendValue((CFMutableArrayRef)result, cfValue);
ReleaseCFType(cfValue);
}
{
#if JAG_PINK_OR_LATER
// Not an arry, just treat it like a dictionary which contains (property name, property value) paiars
- ReferenceList propList = object.propList(exec, false);
+ IdentifierSequencedSet propList;
+ object->getPropertyNames(exec, propList);
{
result = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryValueCallBacks);
if (result)
{
- ReferenceListIterator iter = propList.begin();
- ReferenceListIterator end = propList.end();
+ IdentifierSequencedSetIterator iter = propList.begin();
+ IdentifierSequencedSetIterator end = propList.end();
while(iter != end)
{
- Identifier propName = iter->getPropertyName(exec);
- if (object.hasProperty(exec, propName))
+ Identifier propName = *iter;
+ if (object->hasProperty(exec, propName))
{
CFStringRef cfKey = IdentifierToCFString(propName);
- CFTypeRef cfValue = KJSValueToCFTypeInternal(object.get(exec, propName), exec, &imps);
+ CFTypeRef cfValue = KJSValueToCFTypeInternal(object->get(exec, propName), exec, &imps);
if (cfKey && cfValue)
{
CFDictionaryAddValue((CFMutableDictionaryRef)result, cfKey, cfValue);
ReleaseCFType(cfKey);
ReleaseCFType(cfValue);
}
- iter++;
+ ++iter;
}
}
}
#if !JAG_PINK_OR_LATER
case ReferenceType:
{
- Value value = inValue.getValue(exec);
+ ValueImp *value = inValue->getValue(exec);
result = KJSValueToCFTypeInternal(value, exec, NULL);
}
break;
#if JAG_PINK_OR_LATER
default:
- fprintf(stderr, "KJSValueToCFType: wrong value type %d\n", inValue.type());
+ fprintf(stderr, "KJSValueToCFType: wrong value type %d\n", inValue->type());
break;
#endif
}
return result;
}
-CFTypeRef KJSValueToCFType(const Value& inValue, ExecState *exec)
+CFTypeRef KJSValueToCFType(ValueImp *inValue, ExecState *exec)
{
return KJSValueToCFTypeInternal(inValue, exec, NULL);
}
Identifier CFStringToIdentifier(CFStringRef inCFString);
CFStringRef IdentifierToCFString(const Identifier& inIdentifier);
#endif
-JSUserObject* KJSValueToJSObject(const Value& inValue, ExecState *exec);
-CFTypeRef KJSValueToCFType(const Value& inValue, ExecState *exec);
-Value JSObjectKJSValue(JSUserObject* ptr);
+JSUserObject* KJSValueToJSObject(ValueImp *inValue, ExecState *exec);
+CFTypeRef KJSValueToCFType(ValueImp *inValue, ExecState *exec);
+ValueImp *JSObjectKJSValue(JSUserObject* ptr);
CFTypeRef GetCFNull(void);
inline CFTypeRef RetainCFType(CFTypeRef x) { if (x) x = CFRetain(x); return x; }
// JSValueWrapper.cpp
//
#include "JSValueWrapper.h"
+#include "JavaScriptCore/IdentifierSequencedSet.h"
-JSValueWrapper::JSValueWrapper(const Value& inValue, ExecState *inExec)
+JSValueWrapper::JSValueWrapper(ValueImp *inValue, ExecState *inExec)
: fValue(inValue), fExec(inExec)
{
}
{
}
-Value& JSValueWrapper::GetValue()
+ValueImp *JSValueWrapper::GetValue()
{
return fValue;
}
if (ptr)
{
ExecState* exec = ptr->GetExecState();
-#if JAG_PINK_OR_LATER
- Object object = ptr->GetValue().toObject(exec);
- ReferenceList list = object.propList(exec, false);
- ReferenceListIterator iterator = list.begin();
-#else
- Object object = ptr->GetValue().imp()->toObject(exec);
- List list = object.propList(exec, false);
- ListIterator iterator = list.begin();
-#endif
-
+ ObjectImp *object = ptr->GetValue()->toObject(exec);
+ IdentifierSequencedSet list;
+ object->getPropertyNames(exec, list);
+ IdentifierSequencedSetIterator iterator = list.begin();
while (iterator != list.end()) {
-#if JAG_PINK_OR_LATER
- Identifier name = iterator->getPropertyName(exec);
+ Identifier name = *iterator;
CFStringRef nameStr = IdentifierToCFString(name);
-#else
- UString name = iterator->getPropertyName(exec);
- CFStringRef nameStr = UStringToCFString(name);
-#endif
+
if (!result)
{
result = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
CFArrayAppendValue(result, nameStr);
}
ReleaseCFType(nameStr);
- iterator++;
+ ++iterator;
}
}
if (ptr)
{
ExecState* exec = ptr->GetExecState();
-#if JAG_PINK_OR_LATER
- Value propValue = ptr->GetValue().toObject(exec).get(exec, CFStringToIdentifier(propertyName));
-#else
- Value propValue = ptr->GetValue().imp()->toObject(exec).get(exec, CFStringToUString(propertyName));
-#endif
+ ValueImp *propValue = ptr->GetValue()->toObject(exec)->get(exec, CFStringToIdentifier(propertyName));
JSValueWrapper* wrapperValue = new JSValueWrapper(propValue, exec);
JSObjectCallBacks callBacks;
if (ptr)
{
ExecState* exec = ptr->GetExecState();
- Value value = JSObjectKJSValue((JSUserObject*)jsValue);
-#if JAG_PINK_OR_LATER
- Object objValue = ptr->GetValue().toObject(exec);
- objValue.put(exec, CFStringToIdentifier(propertyName), value);
-#else
- Object objValue = ptr->GetValue().imp()->toObject(exec);
- objValue.put(exec, CFStringToUString(propertyName), value);
-#endif
+ ValueImp *value = JSObjectKJSValue((JSUserObject*)jsValue);
+ ObjectImp *objValue = ptr->GetValue()->toObject(exec);
+ objValue->put(exec, CFStringToIdentifier(propertyName), value);
}
}
{
ExecState* exec = ptr->GetExecState();
- Value value = JSObjectKJSValue((JSUserObject*)thisObj);
-#if JAG_PINK_OR_LATER
- Object ksjThisObj = value.toObject(exec);
- Object objValue = ptr->GetValue().toObject(exec);
-#else
- Object ksjThisObj = value.imp()->toObject(exec);
- Object objValue = ptr->GetValue().imp()->toObject(exec);
-#endif
+ ValueImp *value = JSObjectKJSValue((JSUserObject*)thisObj);
+ ObjectImp *ksjThisObj = value->toObject(exec);
+ ObjectImp *objValue = ptr->GetValue()->toObject(exec);
List listArgs;
CFIndex argCount = args ? CFArrayGetCount(args) : 0;
for (CFIndex i = 0; i < argCount; i++)
{
JSObjectRef jsArg = (JSObjectRef)CFArrayGetValueAtIndex(args, i);
- Value kgsArg = JSObjectKJSValue((JSUserObject*)jsArg);
+ ValueImp *kgsArg = JSObjectKJSValue((JSUserObject*)jsArg);
listArgs.append(kgsArg);
}
- Value resultValue = objValue.call(exec, ksjThisObj, listArgs);
+ ValueImp *resultValue = objValue->call(exec, ksjThisObj, listArgs);
JSValueWrapper* wrapperValue = new JSValueWrapper(resultValue, ptr->GetExecState());
JSObjectCallBacks callBacks;
GetJSObectCallBacks(callBacks);
JSValueWrapper* ptr = (JSValueWrapper*)data;
if (ptr)
{
- ptr->fValue.imp()->mark();
+ ptr->fValue->mark();
}
}
+// -*- mode: c++; c-basic-offset: 4 -*-
+
#ifndef __JSValueWrapper_h
#define __JSValueWrapper_h
#include "JSObject.h"
class JSValueWrapper {
- public:
- JSValueWrapper(const Value& inValue, ExecState *inExec);
- virtual ~JSValueWrapper();
-
- Value& GetValue();
- ExecState* GetExecState() const;
-
- ProtectedValue fValue;
- ExecState* fExec;
-
- static void GetJSObectCallBacks(JSObjectCallBacks& callBacks);
-
- private:
- static void JSObjectDispose(void* data);
- static CFArrayRef JSObjectCopyPropertyNames(void* data);
- static JSObjectRef JSObjectCopyProperty(void* data, CFStringRef propertyName);
- static void JSObjectSetProperty(void* data, CFStringRef propertyName, JSObjectRef jsValue);
- static JSObjectRef JSObjectCallFunction(void* data, JSObjectRef thisObj, CFArrayRef args);
- static CFTypeRef JSObjectCopyCFValue(void* data);
- static void JSObjectMark(void* data);
+public:
+ JSValueWrapper(ValueImp *inValue, ExecState *inExec);
+ virtual ~JSValueWrapper();
+
+ ValueImp *GetValue();
+ ExecState* GetExecState() const;
+
+ ProtectedPtr<ValueImp> fValue;
+ ExecState* fExec;
+
+ static void GetJSObectCallBacks(JSObjectCallBacks& callBacks);
+
+private:
+ static void JSObjectDispose(void* data);
+ static CFArrayRef JSObjectCopyPropertyNames(void* data);
+ static JSObjectRef JSObjectCopyProperty(void* data, CFStringRef propertyName);
+ static void JSObjectSetProperty(void* data, CFStringRef propertyName, JSObjectRef jsValue);
+ static JSObjectRef JSObjectCallFunction(void* data, JSObjectRef thisObj, CFArrayRef args);
+ static CFTypeRef JSObjectCopyCFValue(void* data);
+ static void JSObjectMark(void* data);
};
-#endif
\ No newline at end of file
+#endif
JSRun* ptr = (JSRun*)ref;
if (ptr)
{
- Object globalObject = ptr->GlobalObject();
+ ObjectImp *globalObject = ptr->GlobalObject();
result = (JSObjectRef)KJSValueToJSObject(globalObject, ptr->GetInterpreter()->globalExec());
}
return result;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
- HEADER_SEARCH_PATHS = "";
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ HEADER_SEARCH_PATHS = .;
INSTALL_PATH = "$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
LIBRARY_SEARCH_PATHS = "";
OPTIMIZATION_CFLAGS = "-O0";
__text,
"$(APPLE_INTERNAL_DIR)/OrderFiles/JavaScriptGlue.order",
);
- WARNING_CFLAGS = (
- "-Wmost",
- "-Wno-four-char-constants",
- "-Wno-unknown-pragmas",
- );
WRAPPER_EXTENSION = framework;
ZERO_LINK = YES;
};
);
FRAMEWORK_VERSION = A;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
- HEADER_SEARCH_PATHS = "";
+ HEADER_SEARCH_PATHS = .;
INSTALL_PATH = "$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
LIBRARY_SEARCH_PATHS = "";
OTHER_CFLAGS = "";
__text,
"$(APPLE_INTERNAL_DIR)/OrderFiles/JavaScriptGlue.order",
);
- WARNING_CFLAGS = (
- "-Wmost",
- "-Wno-four-char-constants",
- "-Wno-unknown-pragmas",
- );
WRAPPER_EXTENSION = framework;
ZERO_LINK = NO;
};
"$(SYSTEM_LIBRARY_DIR)/Frameworks/WebKit.framework/Versions/A/Frameworks",
);
FRAMEWORK_VERSION = A;
- HEADER_SEARCH_PATHS = "";
+ HEADER_SEARCH_PATHS = .;
INSTALL_PATH = "$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
LIBRARY_SEARCH_PATHS = "";
OTHER_CFLAGS = "";
__text,
"$(APPLE_INTERNAL_DIR)/OrderFiles/JavaScriptGlue.order",
);
- WARNING_CFLAGS = (
- "-Wmost",
- "-Wno-four-char-constants",
- "-Wno-unknown-pragmas",
- );
WRAPPER_EXTENSION = framework;
};
name = Default;
14AC662C08CE7791006915A8 /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ HEADER_SEARCH_PATHS = .;
+ WARNING_CFLAGS = (
+ "-Wall",
+ "-W",
+ "-Wcast-align",
+ "-Wchar-subscripts",
+ "-Wformat-security",
+ "-Wmissing-format-attribute",
+ "-Wpointer-arith",
+ "-Wwrite-strings",
+ "-Wno-format-y2k",
+ "-Wno-unused-parameter",
+ "-Wno-long-double",
+ );
};
name = Development;
};
14AC662D08CE7791006915A8 /* Deployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ HEADER_SEARCH_PATHS = .;
+ WARNING_CFLAGS = (
+ "-Wall",
+ "-W",
+ "-Wcast-align",
+ "-Wchar-subscripts",
+ "-Wformat-security",
+ "-Wmissing-format-attribute",
+ "-Wpointer-arith",
+ "-Wwrite-strings",
+ "-Wno-format-y2k",
+ "-Wno-unused-parameter",
+ "-Wno-long-double",
+ );
};
name = Deployment;
};
14AC662E08CE7791006915A8 /* Default */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ HEADER_SEARCH_PATHS = .;
+ WARNING_CFLAGS = (
+ "-Wall",
+ "-W",
+ "-Wcast-align",
+ "-Wchar-subscripts",
+ "-Wformat-security",
+ "-Wmissing-format-attribute",
+ "-Wpointer-arith",
+ "-Wwrite-strings",
+ "-Wno-format-y2k",
+ "-Wno-unused-parameter",
+ "-Wno-long-double",
+ );
};
name = Default;
};
--- /dev/null
+all-am:
+ defaults write com.apple.Xcode PBXProductDirectory "$(SYMROOTS)"
+ defaults write com.apple.Xcode PBXIntermediatesDirectory "$(SYMROOTS)"
+ ../WebKitTools/Scripts/set-webkit-configuration --$(BUILDSTYLE)
+ xcodebuild -configuration $(BUILDSTYLE)
+clean-am:
+ defaults write com.apple.Xcode PBXProductDirectory "$(SYMROOTS)"
+ defaults write com.apple.Xcode PBXIntermediatesDirectory "$(SYMROOTS)"
+ ../WebKitTools/Scripts/set-webkit-configuration --$(BUILDSTYLE)
+ xcodebuild clean -configuration $(BUILDSTYLE)
#include "UserObjectImp.h"
+#include "JavaScriptCore/IdentifierSequencedSet.h"
const ClassInfo UserObjectImp::info = {"UserObject", 0, 0, 0};
{
if (!sUserObjectPrototypeImp)
{
- sUserObjectPrototypeImp = new UserObjectPrototypeImp();
- static ProtectedValue protectPrototype = Value(sUserObjectPrototypeImp);
+ sUserObjectPrototypeImp = new UserObjectPrototypeImp();
+ static ProtectedPtr<UserObjectPrototypeImp> protectPrototype;
}
return sUserObjectPrototypeImp;
}
}
UserObjectImp::UserObjectImp(JSUserObject* userObject) :
- ObjectImp(Object(UserObjectPrototypeImp::GlobalUserObjectPrototypeImp())),
+ ObjectImp(UserObjectPrototypeImp::GlobalUserObjectPrototypeImp()),
fJSUserObject((JSUserObject*)userObject->Retain())
{
}
return fJSUserObject ? fJSUserObject->ImplementsCall() : false;
}
-Value UserObjectImp::call(ExecState *exec, Object &thisObj, const List &args)
+ValueImp *UserObjectImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args)
{
- Value result = Undefined();
- JSUserObject* jsThisObj = KJSValueToJSObject(thisObj, exec);
- if (jsThisObj)
- {
- CFIndex argCount = args.size();
- CFArrayCallBacks arrayCallBacks;
- JSTypeGetCFArrayCallBacks(&arrayCallBacks);
- CFMutableArrayRef jsArgs = CFArrayCreateMutable(NULL, 0, &arrayCallBacks);
- if (jsArgs)
- {
- for (CFIndex i = 0; i < argCount; i++)
- {
- JSUserObject* jsArg = KJSValueToJSObject(args[i], exec);
- CFArrayAppendValue(jsArgs, (void*)jsArg);
- jsArg->Release();
- }
- }
-
-#if 0
- JSUserObject* jsResult = fJSUserObject->CallFunction(jsThisObj, jsArgs);
-#else
- int lockCount = Interpreter::lockCount();
- int i;
- for (i = 0; i < lockCount; i++)
- {
- Interpreter::unlock();
- }
-
- JSUserObject* jsResult = fJSUserObject->CallFunction(jsThisObj, jsArgs);
-
- for (i = 0; i < lockCount; i++)
- {
- Interpreter::lock();
- }
-#endif
- if (jsResult)
- {
- result = JSObjectKJSValue(jsResult);
- jsResult->Release();
- }
-
- ReleaseCFType(jsArgs);
- jsThisObj->Release();
- }
- return result;
+ ValueImp *result = Undefined();
+ JSUserObject* jsThisObj = KJSValueToJSObject(thisObj, exec);
+ if (jsThisObj) {
+ CFIndex argCount = args.size();
+ CFArrayCallBacks arrayCallBacks;
+ JSTypeGetCFArrayCallBacks(&arrayCallBacks);
+ CFMutableArrayRef jsArgs = CFArrayCreateMutable(NULL, 0, &arrayCallBacks);
+ if (jsArgs) {
+ for (CFIndex i = 0; i < argCount; i++) {
+ JSUserObject* jsArg = KJSValueToJSObject(args[i], exec);
+ CFArrayAppendValue(jsArgs, (void*)jsArg);
+ jsArg->Release();
+ }
+ }
+
+ int lockCount = Interpreter::lockCount();
+ int i;
+ for (i = 0; i < lockCount; i++) {
+ Interpreter::unlock();
+ }
+
+ JSUserObject* jsResult = fJSUserObject->CallFunction(jsThisObj, jsArgs);
+
+ for (i = 0; i < lockCount; i++) {
+ Interpreter::lock();
+ }
+ if (jsResult) {
+ result = JSObjectKJSValue(jsResult);
+ jsResult->Release();
+ }
+
+ ReleaseCFType(jsArgs);
+ jsThisObj->Release();
+ }
+ return result;
}
-ReferenceList UserObjectImp::propList(ExecState *exec, bool recursive)
-{
- ReferenceList propList;
- JSUserObject* ptr = GetJSUserObject();
- if (ptr)
- {
- Object theObject = toObject(exec);
- CFArrayRef propertyNames = ptr->CopyPropertyNames();
- if (propertyNames)
- {
- CFIndex count = CFArrayGetCount(propertyNames);
- CFIndex i;
- for (i = 0; i < count; i++)
- {
- CFStringRef propertyName = (CFStringRef)CFArrayGetValueAtIndex(propertyNames, i);
- propList.append(Reference(theObject, CFStringToIdentifier(propertyName)));
- }
- CFRelease(propertyNames);
- }
- }
- return propList;
-}
-
-bool UserObjectImp::hasProperty(ExecState *exec, const Identifier &propertyName) const
+void UserObjectImp::getPropertyNames(ExecState *exec, IdentifierSequencedSet& propertyNames)
{
- Value prop = get(exec, propertyName);
- if (prop.type() != UndefinedType)
- {
- return true;
- }
- return ObjectImp::hasProperty(exec, propertyName);
+ JSUserObject* ptr = GetJSUserObject();
+ if (ptr) {
+ CFArrayRef cfPropertyNames = ptr->CopyPropertyNames();
+ if (cfPropertyNames) {
+ CFIndex count = CFArrayGetCount(cfPropertyNames);
+ CFIndex i;
+ for (i = 0; i < count; i++) {
+ CFStringRef propertyName = (CFStringRef)CFArrayGetValueAtIndex(cfPropertyNames, i);
+ propertyNames.insert(CFStringToIdentifier(propertyName));
+ }
+ CFRelease(cfPropertyNames);
+ }
+ }
+ ObjectImp::getPropertyNames(exec, propertyNames);
}
-#if JAG_PINK_OR_LATER
-Value UserObjectImp::get(ExecState *exec, const Identifier &propertyName) const
+ValueImp *UserObjectImp::userObjectGetter(ExecState *, const Identifier& propertyName, const PropertySlot& slot)
{
- Value result = Undefined();
- CFStringRef cfPropName = IdentifierToCFString(propertyName);
- JSUserObject* jsResult = fJSUserObject->CopyProperty(cfPropName);
- if (jsResult)
- {
- result = JSObjectKJSValue(jsResult);
- jsResult->Release();
- }
- else
- {
- Value kjsValue = toPrimitive(exec);
- if (kjsValue.type() != NullType && kjsValue.type() != UndefinedType)
- {
- Object kjsObject = kjsValue.toObject(exec);
- Value kjsObjectProp = kjsObject.get(exec, propertyName);
- result = kjsObjectProp;
- }
- }
- ReleaseCFType(cfPropName);
- return result;
-
+ UserObjectImp *thisObj = static_cast<UserObjectImp *>(slot.slotBase());
+ CFStringRef cfPropName = IdentifierToCFString(propertyName);
+ JSUserObject *jsResult = thisObj->fJSUserObject->CopyProperty(cfPropName);
+ ReleaseCFType(cfPropName);
+ ValueImp *result = JSObjectKJSValue(jsResult);
+ jsResult->Release();
+
+ return result;
}
-void UserObjectImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
+bool UserObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
{
- CFStringRef cfPropName = IdentifierToCFString(propertyName);
- JSUserObject* jsValueObj = KJSValueToJSObject(value, exec);
-
- fJSUserObject->SetProperty(cfPropName, jsValueObj);
-
- if (jsValueObj) jsValueObj->Release();
- ReleaseCFType(cfPropName);
-}
-#else //JAG_PINK_OR_LATER
-Value UserObjectImp::get(ExecState* exec, const UString& propertyName) const
-{
- Value result = Undefined();
- CFStringRef cfPropName = UStringToCFString(propertyName);
- JSUserObject* jsResult = fJSUserObject->CopyProperty(cfPropName);
- if (jsResult)
- {
- result = JSObjectKJSValue(jsResult);
- jsResult->Release();
- }
- else
- {
- Value kjsValue = toPrimitive(exec);
- if (kjsValue != Null() && kjsValue != Undefined())
- {
- Object kjsObject = kjsValue.toObject(exec);
- Value kjsObjectProp = kjsObject.get(exec, propertyName);
- result = kjsObjectProp;
- }
- }
- ReleaseCFType(cfPropName);
- return result;
-
+ CFStringRef cfPropName = IdentifierToCFString(propertyName);
+ JSUserObject *jsResult = fJSUserObject->CopyProperty(cfPropName);
+ ReleaseCFType(cfPropName);
+ if (jsResult) {
+ slot.setCustom(this, userObjectGetter);
+ jsResult->Release();
+ return true;
+ } else {
+ ValueImp *kjsValue = toPrimitive(exec);
+ if (kjsValue->type() != NullType && kjsValue->type() != UndefinedType) {
+ ObjectImp *kjsObject = kjsValue->toObject(exec);
+ if (kjsObject->getPropertySlot(exec, propertyName, slot))
+ return true;
+ }
+ }
+ return ObjectImp::getOwnPropertySlot(exec, propertyName, slot);
}
-void UserObjectImp::put(ExecState* exec, const UString& propertyName, const Value& value, int attr)
+void UserObjectImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr)
{
- CFStringRef cfPropName = UStringToCFString(propertyName);
- JSUserObject* jsValueObj = KJSValueToJSObject(value, exec);
-
- fJSUserObject->SetProperty(cfPropName, jsValueObj);
-
- if (jsValueObj) jsValueObj->Release();
- ReleaseCFType(cfPropName);
+ CFStringRef cfPropName = IdentifierToCFString(propertyName);
+ JSUserObject *jsValueObj = KJSValueToJSObject(value, exec);
+
+ fJSUserObject->SetProperty(cfPropName, jsValueObj);
+
+ if (jsValueObj) jsValueObj->Release();
+ ReleaseCFType(cfPropName);
}
-#endif //JAG_PINK_OR_LATER
JSUserObject* UserObjectImp::GetJSUserObject() const
{
return fJSUserObject;
}
-
-
-Value UserObjectImp::toPrimitive(ExecState *exec, Type preferredType) const
+ValueImp *UserObjectImp::toPrimitive(ExecState *exec, Type preferredType) const
{
- Value result = Undefined();
- JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec);
- CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : NULL;
- if (cfValue)
- {
- CFTypeID cfType = CFGetTypeID(cfValue); // toPrimitive
- if (cfValue == GetCFNull())
- {
- result = Null();
- }
- else if (cfType == CFBooleanGetTypeID())
- {
- if (cfValue == kCFBooleanTrue)
- {
- result = KJS::Boolean(true);
- }
- else
- {
- result = KJS::Boolean(false);
- }
- }
- else if (cfType == CFStringGetTypeID())
- {
- result = KJS::String(CFStringToUString((CFStringRef)cfValue));
- }
- else if (cfType == CFNumberGetTypeID())
- {
- double d = 0.0;
- CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);
- result = KJS::Number(d);
- }
- else if (cfType == CFURLGetTypeID())
- {
- CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue);
- if (absURL)
- {
- result = KJS::String(CFStringToUString(CFURLGetString(absURL)));
- ReleaseCFType(absURL);
- }
- }
- ReleaseCFType(cfValue);
- }
- if (jsObjPtr) jsObjPtr->Release();
- return result;
+ ValueImp *result = Undefined();
+ JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec);
+ CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : NULL;
+ if (cfValue) {
+ CFTypeID cfType = CFGetTypeID(cfValue); // toPrimitive
+ if (cfValue == GetCFNull()) {
+ result = Null();
+ }
+ else if (cfType == CFBooleanGetTypeID()) {
+ if (cfValue == kCFBooleanTrue) {
+ result = KJS::Boolean(true);
+ } else {
+ result = KJS::Boolean(false);
+ }
+ } else if (cfType == CFStringGetTypeID()) {
+ result = KJS::String(CFStringToUString((CFStringRef)cfValue));
+ } else if (cfType == CFNumberGetTypeID()) {
+ double d = 0.0;
+ CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);
+ result = KJS::Number(d);
+ } else if (cfType == CFURLGetTypeID()) {
+ CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue);
+ if (absURL) {
+ result = KJS::String(CFStringToUString(CFURLGetString(absURL)));
+ ReleaseCFType(absURL);
+ }
+ }
+ ReleaseCFType(cfValue);
+ }
+ if (jsObjPtr)
+ jsObjPtr->Release();
+ return result;
}
void UserObjectImp::mark()
{
- ObjectImp::mark(); // call parent to mark self
- if (fJSUserObject)
- {
- fJSUserObject->Mark(); // mark child
- }
+ ObjectImp::mark(); // call parent to mark self
+ if (fJSUserObject) {
+ fJSUserObject->Mark(); // mark child
+ }
}
+// -*- mode: c++; c-basic-offset: 4 -*-
+
#ifndef __UserObjectImp_h
#define __UserObjectImp_h
class UserObjectImp : public ObjectImp
{
- public:
- UserObjectImp(JSUserObject* userObject);
- virtual ~UserObjectImp();
+public:
+ UserObjectImp(JSUserObject* userObject);
+ virtual ~UserObjectImp();
- virtual const ClassInfo *classInfo() const;
- static const ClassInfo info;
-
- virtual bool implementsCall() const;
-
- virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
- virtual ReferenceList UserObjectImp::propList(ExecState *exec, bool recursive=true);
-
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-#if JAG_PINK_OR_LATER
- virtual Value get(ExecState *exec, const Identifier &propertyName) const;
- virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
-#else
- virtual Value get(ExecState* exec, const UString& propertyName) const;
- virtual void put(ExecState* exec, const UString& propertyName, const Value& value, int attr = None);
-#endif
-
- virtual Value toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const;
- virtual bool toBoolean(ExecState *exec) const;
- virtual double toNumber(ExecState *exec) const;
- virtual UString toString(ExecState *exec) const;
+ virtual const ClassInfo *classInfo() const;
+ static const ClassInfo info;
+
+ virtual bool implementsCall() const;
+
+ virtual void getPropertyNames(ExecState *exec, IdentifierSequencedSet& propertyNames);
+
+ virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args);
+ virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
+ virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None);
+
+ ValueImp *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const;
+ virtual bool toBoolean(ExecState *exec) const;
+ virtual double toNumber(ExecState *exec) const;
+ virtual UString toString(ExecState *exec) const;
+
+ virtual void mark();
+
+ JSUserObject* GetJSUserObject() const;
+protected:
+ UserObjectImp();
+private:
+ static ValueImp *userObjectGetter(ExecState *, const Identifier&, const PropertySlot&);
-
- virtual void mark();
-
- JSUserObject* GetJSUserObject() const;
- protected:
- UserObjectImp();
- private:
- JSUserObject* fJSUserObject;
+ JSUserObject* fJSUserObject;
};
-#endif
\ No newline at end of file
+#endif
--- /dev/null
+#include <JavaScriptCore/FastMalloc.h>
--- /dev/null
+#include <JavaScriptCore/HashSet.h>