From 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 17 Dec 2008 18:05:15 -0800 Subject: Code drop from //branches/cupcake/...@124589 --- JavaScriptCore/API/APICast.h | 63 +- JavaScriptCore/API/JSBase.cpp | 69 +- JavaScriptCore/API/JSBase.h | 31 +- JavaScriptCore/API/JSBasePrivate.h | 52 ++ JavaScriptCore/API/JSCallbackConstructor.cpp | 49 +- JavaScriptCore/API/JSCallbackConstructor.h | 32 +- JavaScriptCore/API/JSCallbackFunction.cpp | 44 +- JavaScriptCore/API/JSCallbackFunction.h | 34 +- JavaScriptCore/API/JSCallbackObject.cpp | 14 +- JavaScriptCore/API/JSCallbackObject.h | 86 +- JavaScriptCore/API/JSCallbackObjectFunctions.h | 296 +++---- JavaScriptCore/API/JSClassRef.cpp | 168 +++- JavaScriptCore/API/JSClassRef.h | 57 +- JavaScriptCore/API/JSContextRef.cpp | 80 +- JavaScriptCore/API/JSContextRef.h | 60 +- JavaScriptCore/API/JSNode.c | 197 ----- JavaScriptCore/API/JSNode.h | 38 - JavaScriptCore/API/JSNodeList.c | 124 --- JavaScriptCore/API/JSNodeList.h | 35 - JavaScriptCore/API/JSObjectRef.cpp | 303 +++++-- JavaScriptCore/API/JSObjectRef.h | 57 +- JavaScriptCore/API/JSProfilerPrivate.cpp | 46 ++ JavaScriptCore/API/JSProfilerPrivate.h | 63 ++ JavaScriptCore/API/JSStringRef.cpp | 78 +- JavaScriptCore/API/JSStringRef.h | 7 +- JavaScriptCore/API/JSStringRefBSTR.cpp | 1 - JavaScriptCore/API/JSStringRefBSTR.h | 5 +- JavaScriptCore/API/JSStringRefCF.cpp | 29 +- JavaScriptCore/API/JSStringRefCF.h | 7 +- JavaScriptCore/API/JSValueRef.cpp | 115 +-- JavaScriptCore/API/JSValueRef.h | 13 +- JavaScriptCore/API/JavaScript.h | 3 +- JavaScriptCore/API/JavaScriptCore.h | 3 +- JavaScriptCore/API/Node.c | 86 -- JavaScriptCore/API/Node.h | 51 -- JavaScriptCore/API/NodeList.c | 82 -- JavaScriptCore/API/NodeList.h | 43 - JavaScriptCore/API/OpaqueJSString.cpp | 55 ++ JavaScriptCore/API/OpaqueJSString.h | 81 ++ JavaScriptCore/API/WebKitAvailability.h | 761 ++++++++++++++++++ JavaScriptCore/API/minidom.c | 126 --- JavaScriptCore/API/minidom.html | 9 - JavaScriptCore/API/minidom.js | 111 --- JavaScriptCore/API/testapi.c | 942 ---------------------- JavaScriptCore/API/testapi.js | 132 --- JavaScriptCore/API/tests/JSNode.c | 196 +++++ JavaScriptCore/API/tests/JSNode.h | 37 + JavaScriptCore/API/tests/JSNodeList.c | 123 +++ JavaScriptCore/API/tests/JSNodeList.h | 34 + JavaScriptCore/API/tests/Node.c | 85 ++ JavaScriptCore/API/tests/Node.h | 50 ++ JavaScriptCore/API/tests/NodeList.c | 81 ++ JavaScriptCore/API/tests/NodeList.h | 42 + JavaScriptCore/API/tests/minidom.c | 126 +++ JavaScriptCore/API/tests/minidom.html | 9 + JavaScriptCore/API/tests/minidom.js | 110 +++ JavaScriptCore/API/tests/testapi.c | 1026 ++++++++++++++++++++++++ JavaScriptCore/API/tests/testapi.js | 132 +++ 58 files changed, 4180 insertions(+), 2609 deletions(-) create mode 100644 JavaScriptCore/API/JSBasePrivate.h delete mode 100644 JavaScriptCore/API/JSNode.c delete mode 100644 JavaScriptCore/API/JSNode.h delete mode 100644 JavaScriptCore/API/JSNodeList.c delete mode 100644 JavaScriptCore/API/JSNodeList.h create mode 100644 JavaScriptCore/API/JSProfilerPrivate.cpp create mode 100644 JavaScriptCore/API/JSProfilerPrivate.h delete mode 100644 JavaScriptCore/API/Node.c delete mode 100644 JavaScriptCore/API/Node.h delete mode 100644 JavaScriptCore/API/NodeList.c delete mode 100644 JavaScriptCore/API/NodeList.h create mode 100644 JavaScriptCore/API/OpaqueJSString.cpp create mode 100644 JavaScriptCore/API/OpaqueJSString.h create mode 100644 JavaScriptCore/API/WebKitAvailability.h delete mode 100644 JavaScriptCore/API/minidom.c delete mode 100644 JavaScriptCore/API/minidom.html delete mode 100644 JavaScriptCore/API/minidom.js delete mode 100644 JavaScriptCore/API/testapi.c delete mode 100644 JavaScriptCore/API/testapi.js create mode 100644 JavaScriptCore/API/tests/JSNode.c create mode 100644 JavaScriptCore/API/tests/JSNode.h create mode 100644 JavaScriptCore/API/tests/JSNodeList.c create mode 100644 JavaScriptCore/API/tests/JSNodeList.h create mode 100644 JavaScriptCore/API/tests/Node.c create mode 100644 JavaScriptCore/API/tests/Node.h create mode 100644 JavaScriptCore/API/tests/NodeList.c create mode 100644 JavaScriptCore/API/tests/NodeList.h create mode 100644 JavaScriptCore/API/tests/minidom.c create mode 100644 JavaScriptCore/API/tests/minidom.html create mode 100644 JavaScriptCore/API/tests/minidom.js create mode 100644 JavaScriptCore/API/tests/testapi.c create mode 100644 JavaScriptCore/API/tests/testapi.js (limited to 'JavaScriptCore/API') diff --git a/JavaScriptCore/API/APICast.h b/JavaScriptCore/API/APICast.h index d8c7c18..ecd524c 100644 --- a/JavaScriptCore/API/APICast.h +++ b/JavaScriptCore/API/APICast.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * @@ -30,91 +29,83 @@ #include "ustring.h" #include "ExecState.h" -namespace KJS { - class ExecState; - class JSValue; - class JSObject; - class PropertyNameArray; -} - +typedef const struct OpaqueJSContextGroup* JSContextGroupRef; typedef const struct OpaqueJSContext* JSContextRef; typedef struct OpaqueJSContext* JSGlobalContextRef; -typedef struct OpaqueJSString* JSStringRef; typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; typedef const struct OpaqueJSValue* JSValueRef; typedef struct OpaqueJSValue* JSObjectRef; /* Opaque typing convenience methods */ -inline KJS::ExecState* toJS(JSContextRef c) +inline JSC::ExecState* toJS(JSContextRef c) { - return reinterpret_cast(const_cast(c)); + return reinterpret_cast(const_cast(c)); } -inline KJS::ExecState* toJS(JSGlobalContextRef c) +inline JSC::ExecState* toJS(JSGlobalContextRef c) { - return reinterpret_cast(c); + return reinterpret_cast(c); } -inline KJS::JSValue* toJS(JSValueRef v) +inline JSC::JSValue* toJS(JSValueRef v) { - return reinterpret_cast(const_cast(v)); + return reinterpret_cast(const_cast(v)); } -inline KJS::UString::Rep* toJS(JSStringRef b) +inline JSC::JSObject* toJS(JSObjectRef o) { - return reinterpret_cast(b); + return reinterpret_cast(o); } -inline KJS::JSObject* toJS(JSObjectRef o) +inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a) { - return reinterpret_cast(o); + return reinterpret_cast(a); } -inline KJS::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a) +inline JSC::JSGlobalData* toJS(JSContextGroupRef g) { - return reinterpret_cast(a); + return reinterpret_cast(const_cast(g)); } -inline JSValueRef toRef(KJS::JSValue* v) +inline JSValueRef toRef(JSC::JSValue* v) { return reinterpret_cast(v); } -inline JSValueRef* toRef(KJS::JSValue** v) -{ - return reinterpret_cast(const_cast(v)); -} - -inline JSStringRef toRef(KJS::UString::Rep* s) +inline JSValueRef* toRef(JSC::JSValue** v) { - return reinterpret_cast(s); + return reinterpret_cast(const_cast(v)); } -inline JSObjectRef toRef(KJS::JSObject* o) +inline JSObjectRef toRef(JSC::JSObject* o) { return reinterpret_cast(o); } -inline JSObjectRef toRef(const KJS::JSObject* o) +inline JSObjectRef toRef(const JSC::JSObject* o) { - return reinterpret_cast(const_cast(o)); + return reinterpret_cast(const_cast(o)); } -inline JSContextRef toRef(KJS::ExecState* e) +inline JSContextRef toRef(JSC::ExecState* e) { return reinterpret_cast(e); } -inline JSGlobalContextRef toGlobalRef(KJS::ExecState* e) +inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e) { - ASSERT(!e->callingExecState()); return reinterpret_cast(e); } -inline JSPropertyNameAccumulatorRef toRef(KJS::PropertyNameArray* l) +inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l) { return reinterpret_cast(l); } +inline JSContextGroupRef toRef(JSC::JSGlobalData* g) +{ + return reinterpret_cast(g); +} + #endif // APICast_h diff --git a/JavaScriptCore/API/JSBase.cpp b/JavaScriptCore/API/JSBase.cpp index d8acc42..bd2935c 100644 --- a/JavaScriptCore/API/JSBase.cpp +++ b/JavaScriptCore/API/JSBase.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * @@ -21,30 +20,38 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "JSBase.h" +#include "JSBasePrivate.h" #include "APICast.h" -#include -#include -#include +#include "completion.h" +#include "OpaqueJSString.h" +#include "SourceCode.h" +#include +#include #include -#include +#include +#include +#include -using namespace KJS; +using namespace JSC; JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsThisObject = toJS(thisObject); - UString::Rep* scriptRep = toJS(script); - UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; + // Interpreter::evaluate sets "this" to the global object if it is NULL - Completion completion = Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject); + JSGlobalObject* globalObject = exec->dynamicGlobalObject(); + SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber); + Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject); if (completion.complType() == Throw) { if (exception) @@ -61,12 +68,12 @@ JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef th bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { - JSLock lock; - ExecState* exec = toJS(ctx); - UString::Rep* scriptRep = toJS(script); - UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; - Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep)); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber); + Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), source); if (completion.complType() == Throw) { if (exception) *exception = toRef(completion.value()); @@ -76,12 +83,34 @@ bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourc return true; } -void JSGarbageCollect(JSContextRef) +void JSGarbageCollect(JSContextRef ctx) { - JSLock lock; - if (!Collector::isBusy()) - Collector::collect(); + // We used to recommend passing NULL as an argument here, which caused the only heap to be collected. + // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC + // will happen when the context group is destroyed). + // Because the function argument was originally ignored, some clients may pass their released context here, + // in which case there is a risk of crashing if another thread performs GC on the same heap in between. + if (!ctx) + return; + + ExecState* exec = toJS(ctx); + JSGlobalData& globalData = exec->globalData(); + + JSLock lock(globalData.isSharedInstance); + + if (!globalData.heap.isBusy()) + globalData.heap.collect(); + // FIXME: Perhaps we should trigger a second mark and sweep // once the garbage collector is done if this is called when // the collector is busy. } + +void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) +{ + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + exec->globalData().heap.reportExtraMemoryCost(size); +} diff --git a/JavaScriptCore/API/JSBase.h b/JavaScriptCore/API/JSBase.h index 7cf7c7d..f44d4ad 100644 --- a/JavaScriptCore/API/JSBase.h +++ b/JavaScriptCore/API/JSBase.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * @@ -27,10 +26,15 @@ #ifndef JSBase_h #define JSBase_h +#ifndef __cplusplus #include +#endif /* JavaScript engine interface */ +/*! @typedef JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. */ +typedef const struct OpaqueJSContextGroup* JSContextGroupRef; + /*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */ typedef const struct OpaqueJSContext* JSContextRef; @@ -64,8 +68,10 @@ typedef struct OpaqueJSValue* JSObjectRef; #if defined(__GNUC__) #define JS_EXPORT __attribute__((visibility("default"))) #elif defined(WIN32) || defined(_WIN32) - // TODO: Export symbols with JS_EXPORT when using MSVC. - // See http://bugs.webkit.org/show_bug.cgi?id=16227 + /* + * TODO: Export symbols with JS_EXPORT when using MSVC. + * See http://bugs.webkit.org/show_bug.cgi?id=16227 + */ #define JS_EXPORT #else #define JS_EXPORT @@ -78,7 +84,7 @@ extern "C" { /* Script Evaluation */ /*! -@function +@function JSEvaluateScript @abstract Evaluates a string of JavaScript. @param ctx The execution context to use. @param script A JSString containing the script to evaluate. @@ -103,18 +109,17 @@ JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSOb JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); /*! -@function +@function JSGarbageCollect @abstract Performs a JavaScript garbage collection. -@param ctx This parameter is currently unused. Pass NULL. +@param ctx The execution context to use. @discussion JavaScript values that are on the machine stack, in a register, protected by JSValueProtect, set as the global object of an execution context, - or reachable from any such value will not be collected. - + or reachable from any such value will not be collected. + During JavaScript execution, you are not required to call this function; the - JavaScript engine will garbage collect as needed. One place you may want to call - this function, however, is after releasing the last reference to a JSGlobalContextRef. - At that point, a garbage collection can free the objects still referenced by the - JSGlobalContextRef's global object, along with the global object itself. + JavaScript engine will garbage collect as needed. JavaScript values created + within a context group are automatically destroyed when the last reference + to the context group is released. */ JS_EXPORT void JSGarbageCollect(JSContextRef ctx); @@ -122,4 +127,4 @@ JS_EXPORT void JSGarbageCollect(JSContextRef ctx); } #endif -#endif // JSBase_h +#endif /* JSBase_h */ diff --git a/JavaScriptCore/API/JSBasePrivate.h b/JavaScriptCore/API/JSBasePrivate.h new file mode 100644 index 0000000..6beacda --- /dev/null +++ b/JavaScriptCore/API/JSBasePrivate.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSBasePrivate_h +#define JSBasePrivate_h + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! +@function +@abstract Reports an object's non-GC memory payload to the garbage collector. +@param ctx The execution context to use. +@param size The payload's size, in bytes. +@discussion Use this function to notify the garbage collector that a GC object +owns a large non-GC memory region. Calling this function will encourage the +garbage collector to collect soon, hoping to reclaim that large non-GC memory +region. +*/ +JS_EXPORT void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +#ifdef __cplusplus +} +#endif + +#endif /* JSBasePrivate_h */ diff --git a/JavaScriptCore/API/JSCallbackConstructor.cpp b/JavaScriptCore/API/JSCallbackConstructor.cpp index 46c1823..29c26ea 100644 --- a/JavaScriptCore/API/JSCallbackConstructor.cpp +++ b/JavaScriptCore/API/JSCallbackConstructor.cpp @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,16 +27,17 @@ #include "JSCallbackConstructor.h" #include "APICast.h" -#include -#include +#include +#include +#include #include -namespace KJS { +namespace JSC { -const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0}; +const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 }; -JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback) - : JSObject(exec->lexicalGlobalObject()->objectPrototype()) +JSCallbackConstructor::JSCallbackConstructor(PassRefPtr structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback) + : JSObject(structure) , m_class(jsClass) , m_callback(callback) { @@ -51,32 +51,29 @@ JSCallbackConstructor::~JSCallbackConstructor() JSClassRelease(m_class); } -bool JSCallbackConstructor::implementsHasInstance() const -{ - return true; -} - -bool JSCallbackConstructor::implementsConstruct() const -{ - return true; -} - -JSObject* JSCallbackConstructor::construct(ExecState* exec, const List &args) +static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args) { JSContextRef ctx = toRef(exec); - JSObjectRef thisRef = toRef(this); + JSObjectRef constructorRef = toRef(constructor); - if (m_callback) { + JSObjectCallAsConstructorCallback callback = static_cast(constructor)->callback(); + if (callback) { int argumentCount = static_cast(args.size()); Vector arguments(argumentCount); for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(args[i]); + arguments[i] = toRef(args.at(exec, i)); - JSLock::DropAllLocks dropAllLocks; - return toJS(m_callback(ctx, thisRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); + JSLock::DropAllLocks dropAllLocks(exec); + return toJS(callback(ctx, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); } - return toJS(JSObjectMake(ctx, m_class, 0)); + return toJS(JSObjectMake(ctx, static_cast(constructor)->classRef(), 0)); +} + +ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructJSCallback; + return ConstructTypeHost; } -} // namespace KJS +} // namespace JSC diff --git a/JavaScriptCore/API/JSCallbackConstructor.h b/JavaScriptCore/API/JSCallbackConstructor.h index fc45cb5..01f15a8 100644 --- a/JavaScriptCore/API/JSCallbackConstructor.h +++ b/JavaScriptCore/API/JSCallbackConstructor.h @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,32 +27,31 @@ #define JSCallbackConstructor_h #include "JSObjectRef.h" -#include +#include -namespace KJS { +namespace JSC { -class JSCallbackConstructor : public JSObject -{ +class JSCallbackConstructor : public JSObject { public: - JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback); + JSCallbackConstructor(PassRefPtr, JSClassRef, JSObjectCallAsConstructorCallback); virtual ~JSCallbackConstructor(); - - virtual bool implementsHasInstance() const; - - virtual bool implementsConstruct() const; - virtual JSObject* construct(ExecState*, const List &args); - - virtual const ClassInfo *classInfo() const { return &info; } + JSClassRef classRef() const { return m_class; } + JSObjectCallAsConstructorCallback callback() const { return m_callback; } static const ClassInfo info; + static PassRefPtr createStructureID(JSValue* proto) + { + return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance | HasStandardGetOwnPropertySlot)); + } + private: - JSCallbackConstructor(); // prevent default construction - JSCallbackConstructor(const JSCallbackConstructor&); + virtual ConstructType getConstructData(ConstructData&); + virtual const ClassInfo* classInfo() const { return &info; } JSClassRef m_class; JSObjectCallAsConstructorCallback m_callback; }; -} // namespace KJS +} // namespace JSC #endif // JSCallbackConstructor_h diff --git a/JavaScriptCore/API/JSCallbackFunction.cpp b/JavaScriptCore/API/JSCallbackFunction.cpp index fb3937d..45d726a 100644 --- a/JavaScriptCore/API/JSCallbackFunction.cpp +++ b/JavaScriptCore/API/JSCallbackFunction.cpp @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,40 +28,43 @@ #include "JSCallbackFunction.h" #include "APICast.h" -#include "function.h" -#include "function_object.h" -#include +#include "JSFunction.h" +#include "FunctionPrototype.h" +#include +#include #include -namespace KJS { +namespace JSC { -const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0}; +ASSERT_CLASS_FITS_IN_CELL(JSCallbackFunction); + +const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 }; JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name) - : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name) + : InternalFunction(&exec->globalData(), exec->lexicalGlobalObject()->callbackFunctionStructure(), name) , m_callback(callback) { } -// InternalFunctionImp mish-mashes constructor and function behavior -- we should -// refactor the code so this override isn't necessary -bool JSCallbackFunction::implementsHasInstance() const { - return false; -} - -JSValue* JSCallbackFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args) +JSValue* JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args) { JSContextRef execRef = toRef(exec); - JSObjectRef thisRef = toRef(this); - JSObjectRef thisObjRef = toRef(thisObj); + JSObjectRef functionRef = toRef(functionObject); + JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec)); int argumentCount = static_cast(args.size()); Vector arguments(argumentCount); for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(args[i]); + arguments[i] = toRef(args.at(exec, i)); - JSLock::DropAllLocks dropAllLocks; - return toJS(m_callback(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); + JSLock::DropAllLocks dropAllLocks(exec); + return toJS(static_cast(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); +} + +CallType JSCallbackFunction::getCallData(CallData& callData) +{ + callData.native.function = call; + return CallTypeHost; } -} // namespace KJS +} // namespace JSC diff --git a/JavaScriptCore/API/JSCallbackFunction.h b/JavaScriptCore/API/JSCallbackFunction.h index 48be3d2..806a992 100644 --- a/JavaScriptCore/API/JSCallbackFunction.h +++ b/JavaScriptCore/API/JSCallbackFunction.h @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,30 +26,33 @@ #ifndef JSCallbackFunction_h #define JSCallbackFunction_h +#include "InternalFunction.h" #include "JSObjectRef.h" -#include "function.h" -#include "object.h" -namespace KJS { +namespace JSC { -class JSCallbackFunction : public InternalFunctionImp -{ +class JSCallbackFunction : public InternalFunction { public: - JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name); + JSCallbackFunction(ExecState*, JSObjectCallAsFunctionCallback, const Identifier& name); - virtual bool implementsHasInstance() const; - virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args); - - virtual const ClassInfo *classInfo() const { return &info; } static const ClassInfo info; + // InternalFunction mish-mashes constructor and function behavior -- we should + // refactor the code so this override isn't necessary + static PassRefPtr createStructureID(JSValue* proto) + { + return StructureID::create(proto, TypeInfo(ObjectType, HasStandardGetOwnPropertySlot)); + } + private: - JSCallbackFunction(); // prevent default construction - JSCallbackFunction(const JSCallbackFunction&); - + virtual CallType getCallData(CallData&); + virtual const ClassInfo* classInfo() const { return &info; } + + static JSValue* call(ExecState*, JSObject*, JSValue*, const ArgList&); + JSObjectCallAsFunctionCallback m_callback; }; -} // namespace KJS +} // namespace JSC #endif // JSCallbackFunction_h diff --git a/JavaScriptCore/API/JSCallbackObject.cpp b/JavaScriptCore/API/JSCallbackObject.cpp index 129b304..4be35bd 100644 --- a/JavaScriptCore/API/JSCallbackObject.cpp +++ b/JavaScriptCore/API/JSCallbackObject.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * Copyright (C) 2007 Eric Seidel @@ -30,12 +29,13 @@ #include "collector.h" -namespace KJS { +namespace JSC { -// Define the two types of JSCallbackObjects we support. -template <> const ClassInfo JSCallbackObject::info = { "CallbackObject", 0, 0 }; -template <> const ClassInfo JSCallbackObject::info = { "CallbackGlobalObject", 0, 0 }; +ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject); +ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject); -COMPILE_ASSERT(sizeof(JSCallbackObject) <= CELL_SIZE, global_callback_object_fits_in_cell); +// Define the two types of JSCallbackObjects we support. +template <> const ClassInfo JSCallbackObject::info = { "CallbackObject", 0, 0, 0 }; +template <> const ClassInfo JSCallbackObject::info = { "CallbackGlobalObject", 0, 0, 0 }; -} // namespace KJS +} // namespace JSC diff --git a/JavaScriptCore/API/JSCallbackObject.h b/JavaScriptCore/API/JSCallbackObject.h index 7eb32a6..7543e17 100644 --- a/JavaScriptCore/API/JSCallbackObject.h +++ b/JavaScriptCore/API/JSCallbackObject.h @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2007 Eric Seidel * * Redistribution and use in source and binary forms, with or without @@ -30,64 +29,85 @@ #include "JSObjectRef.h" #include "JSValueRef.h" -#include "object.h" +#include "JSObject.h" -namespace KJS { +namespace JSC { template -class JSCallbackObject : public Base -{ +class JSCallbackObject : public Base { public: - JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype, void* data); + JSCallbackObject(ExecState*, PassRefPtr, JSClassRef, void* data); JSCallbackObject(JSClassRef); virtual ~JSCallbackObject(); + void setPrivate(void* data); + void* getPrivate(); + + static const ClassInfo info; + + JSClassRef classRef() const { return m_callbackObjectData->jsClass; } + bool inherits(JSClassRef) const; + + static PassRefPtr createStructureID(JSValue* proto) + { + return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance | OverridesHasInstance)); + } + +private: virtual UString className() const; virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); virtual bool getOwnPropertySlot(ExecState*, unsigned, PropertySlot&); - virtual void put(ExecState*, const Identifier&, JSValue*, int attr); - virtual void put(ExecState*, unsigned, JSValue*, int attr); + virtual void put(ExecState*, const Identifier&, JSValue*, PutPropertySlot&); virtual bool deleteProperty(ExecState*, const Identifier&); virtual bool deleteProperty(ExecState*, unsigned); - virtual bool implementsConstruct() const; - virtual JSObject* construct(ExecState*, const List& args); - - virtual bool implementsHasInstance() const; - virtual bool hasInstance(ExecState *exec, JSValue *value); - - virtual bool implementsCall() const; - virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args); + virtual bool hasInstance(ExecState* exec, JSValue* value, JSValue* proto); virtual void getPropertyNames(ExecState*, PropertyNameArray&); virtual double toNumber(ExecState*) const; virtual UString toString(ExecState*) const; - void setPrivate(void* data); - void* getPrivate(); - - virtual const ClassInfo *classInfo() const { return &info; } - static const ClassInfo info; + virtual ConstructType getConstructData(ConstructData&); + virtual CallType getCallData(CallData&); + virtual const ClassInfo* classInfo() const { return &info; } - bool inherits(JSClassRef) const; - -private: void init(ExecState*); + + static JSCallbackObject* asCallbackObject(JSValue*); + + static JSValue* call(ExecState*, JSObject* functionObject, JSValue* thisValue, const ArgList&); + static JSObject* construct(ExecState*, JSObject* constructor, const ArgList&); + + static JSValue* cachedValueGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue* staticValueGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue* staticFunctionGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue* callbackGetter(ExecState*, const Identifier&, const PropertySlot&); + + struct JSCallbackObjectData { + JSCallbackObjectData(void* privateData, JSClassRef jsClass) + : privateData(privateData) + , jsClass(jsClass) + { + JSClassRetain(jsClass); + } + + ~JSCallbackObjectData() + { + JSClassRelease(jsClass); + } + + void* privateData; + JSClassRef jsClass; + }; - static JSValue* cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); - static JSValue* staticValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot); - static JSValue* staticFunctionGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot); - static JSValue* callbackGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); - - void* m_privateData; - JSClassRef m_class; + OwnPtr m_callbackObjectData; }; -} // namespace KJS +} // namespace JSC // include the actual template class implementation #include "JSCallbackObjectFunctions.h" diff --git a/JavaScriptCore/API/JSCallbackObjectFunctions.h b/JavaScriptCore/API/JSCallbackObjectFunctions.h index f987dd8..f008987 100644 --- a/JavaScriptCore/API/JSCallbackObjectFunctions.h +++ b/JavaScriptCore/API/JSCallbackObjectFunctions.h @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * Copyright (C) 2007 Eric Seidel * * Redistribution and use in source and binary forms, with or without @@ -25,33 +24,42 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "APICast.h" +#include "Error.h" #include "JSCallbackFunction.h" #include "JSClassRef.h" -#include "JSObjectRef.h" #include "JSGlobalObject.h" +#include "JSLock.h" +#include "JSObjectRef.h" +#include "JSString.h" #include "JSStringRef.h" +#include "OpaqueJSString.h" #include "PropertyNameArray.h" -#include "internal.h" #include -namespace KJS { +namespace JSC { + +template +inline JSCallbackObject* JSCallbackObject::asCallbackObject(JSValue* value) +{ + ASSERT(asObject(value)->inherits(&info)); + return static_cast(asObject(value)); +} template -JSCallbackObject::JSCallbackObject(ExecState* exec, JSClassRef jsClass, JSValue* prototype, void* data) - : Base(prototype) - , m_privateData(data) - , m_class(JSClassRetain(jsClass)) +JSCallbackObject::JSCallbackObject(ExecState* exec, PassRefPtr structure, JSClassRef jsClass, void* data) + : Base(structure) + , m_callbackObjectData(new JSCallbackObjectData(data, jsClass)) { init(exec); } -// Global object constructor. FIXME: Move this into a JSGlobalCallbackObject subclass. +// Global object constructor. +// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one. template JSCallbackObject::JSCallbackObject(JSClassRef jsClass) - : m_privateData(0) - , m_class(JSClassRetain(jsClass)) + : Base() + , m_callbackObjectData(new JSCallbackObjectData(0, jsClass)) { ASSERT(Base::isGlobalObject()); init(static_cast(this)->globalExec()); @@ -63,7 +71,7 @@ void JSCallbackObject::init(ExecState* exec) ASSERT(exec); Vector initRoutines; - JSClassRef jsClass = m_class; + JSClassRef jsClass = classRef(); do { if (JSObjectInitializeCallback initialize = jsClass->initialize) initRoutines.append(initialize); @@ -71,7 +79,7 @@ void JSCallbackObject::init(ExecState* exec) // initialize from base to derived for (int i = static_cast(initRoutines.size()) - 1; i >= 0; i--) { - JSLock::DropAllLocks dropAllLocks; + JSLock::DropAllLocks dropAllLocks(exec); JSObjectInitializeCallback initialize = initRoutines[i]; initialize(toRef(exec), toRef(this)); } @@ -82,19 +90,17 @@ JSCallbackObject::~JSCallbackObject() { JSObjectRef thisRef = toRef(this); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) - if (JSObjectFinalizeCallback finalize = jsClass->finalize) { + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) + if (JSObjectFinalizeCallback finalize = jsClass->finalize) finalize(thisRef); - } - - JSClassRelease(m_class); } template UString JSCallbackObject::className() const { - if (!m_class->className.isNull()) - return m_class->className; + UString thisClassName = classRef()->className(); + if (!thisClassName.isNull()) + return thisClassName; return Base::className(); } @@ -104,35 +110,39 @@ bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifie { JSContextRef ctx = toRef(exec); JSObjectRef thisRef = toRef(this); - JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); + RefPtr propertyNameRef; - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { // optional optimization to bypass getProperty in cases when we only need to know if the property exists if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) { - JSLock::DropAllLocks dropAllLocks; - if (hasProperty(ctx, thisRef, propertyNameRef)) { + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (hasProperty(ctx, thisRef, propertyNameRef.get())) { slot.setCustom(this, callbackGetter); return true; } } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) { - JSLock::DropAllLocks dropAllLocks; - if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) { + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) { // cache the value so we don't have to compute it again // FIXME: This violates the PropertySlot design a little bit. // We should either use this optimization everywhere, or nowhere. - slot.setCustom(reinterpret_cast(toJS(value)), cachedValueGetter); + slot.setCustom(asObject(toJS(value)), cachedValueGetter); return true; } } - if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) { + if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) { if (staticValues->contains(propertyName.ustring().rep())) { slot.setCustom(this, staticValueGetter); return true; } } - if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { + if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) { if (staticFunctions->contains(propertyName.ustring().rep())) { slot.setCustom(this, staticFunctionGetter); return true; @@ -146,54 +156,52 @@ bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifie template bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) { - return getOwnPropertySlot(exec, Identifier::from(propertyName), slot); + return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot); } template -void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) +void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot) { JSContextRef ctx = toRef(exec); JSObjectRef thisRef = toRef(this); - JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); + RefPtr propertyNameRef; JSValueRef valueRef = toRef(value); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) { - JSLock::DropAllLocks dropAllLocks; - if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()))) + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot()))) return; } - if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) { + if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) { if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) { if (entry->attributes & kJSPropertyAttributeReadOnly) return; if (JSObjectSetPropertyCallback setProperty = entry->setProperty) { - JSLock::DropAllLocks dropAllLocks; - if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()))) + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot()))) return; } else throwError(exec, ReferenceError, "Attempt to set a property that is not settable."); } } - if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { + if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) { if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) { if (entry->attributes & kJSPropertyAttributeReadOnly) return; - JSCallbackObject::putDirect(propertyName, value, attr); // put as override property + JSCallbackObject::putDirect(propertyName, value); // put as override property return; } } } - return Base::put(exec, propertyName, value, attr); -} - -template -void JSCallbackObject::put(ExecState* exec, unsigned propertyName, JSValue* value, int attr) -{ - return put(exec, Identifier::from(propertyName), value, attr); + return Base::put(exec, propertyName, value, slot); } template @@ -201,16 +209,18 @@ bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& p { JSContextRef ctx = toRef(exec); JSObjectRef thisRef = toRef(this); - JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); + RefPtr propertyNameRef; - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) { - JSLock::DropAllLocks dropAllLocks; - if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (deleteProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) return true; } - if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) { + if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) { if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) { if (entry->attributes & kJSPropertyAttributeDontDelete) return false; @@ -218,7 +228,7 @@ bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& p } } - if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { + if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) { if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) { if (entry->attributes & kJSPropertyAttributeDontDelete) return false; @@ -233,97 +243,89 @@ bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& p template bool JSCallbackObject::deleteProperty(ExecState* exec, unsigned propertyName) { - return deleteProperty(exec, Identifier::from(propertyName)); + return deleteProperty(exec, Identifier::from(exec, propertyName)); } template -bool JSCallbackObject::implementsConstruct() const +ConstructType JSCallbackObject::getConstructData(ConstructData& constructData) { - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) - if (jsClass->callAsConstructor) - return true; - - return false; + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { + if (jsClass->callAsConstructor) { + constructData.native.function = construct; + return ConstructTypeHost; + } + } + return ConstructTypeNone; } template -JSObject* JSCallbackObject::construct(ExecState* exec, const List& args) +JSObject* JSCallbackObject::construct(ExecState* exec, JSObject* constructor, const ArgList& args) { JSContextRef execRef = toRef(exec); - JSObjectRef thisRef = toRef(this); + JSObjectRef constructorRef = toRef(constructor); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { + for (JSClassRef jsClass = static_cast*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) { int argumentCount = static_cast(args.size()); Vector arguments(argumentCount); for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(args[i]); - JSLock::DropAllLocks dropAllLocks; - return toJS(callAsConstructor(execRef, thisRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); + arguments[i] = toRef(args.at(exec, i)); + JSLock::DropAllLocks dropAllLocks(exec); + return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); } } - ASSERT(0); // implementsConstruct should prevent us from reaching here + ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here return 0; } template -bool JSCallbackObject::implementsHasInstance() const -{ - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) - if (jsClass->hasInstance) - return true; - - return false; -} - -template -bool JSCallbackObject::hasInstance(ExecState *exec, JSValue *value) +bool JSCallbackObject::hasInstance(ExecState* exec, JSValue* value, JSValue*) { JSContextRef execRef = toRef(exec); JSObjectRef thisRef = toRef(this); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) { - JSLock::DropAllLocks dropAllLocks; + JSLock::DropAllLocks dropAllLocks(exec); return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot())); } - - ASSERT_NOT_REACHED(); // implementsHasInstance should prevent us from reaching here - return 0; + } + return false; } - template -bool JSCallbackObject::implementsCall() const +CallType JSCallbackObject::getCallData(CallData& callData) { - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) - if (jsClass->callAsFunction) - return true; - - return false; + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { + if (jsClass->callAsFunction) { + callData.native.function = call; + return CallTypeHost; + } + } + return CallTypeNone; } template -JSValue* JSCallbackObject::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args) +JSValue* JSCallbackObject::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args) { JSContextRef execRef = toRef(exec); - JSObjectRef thisRef = toRef(this); - JSObjectRef thisObjRef = toRef(thisObj); + JSObjectRef functionRef = toRef(functionObject); + JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec)); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { + for (JSClassRef jsClass = static_cast*>(functionObject)->classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) { int argumentCount = static_cast(args.size()); Vector arguments(argumentCount); for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(args[i]); - JSLock::DropAllLocks dropAllLocks; - return toJS(callAsFunction(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); + arguments[i] = toRef(args.at(exec, i)); + JSLock::DropAllLocks dropAllLocks(exec); + return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); } } - ASSERT_NOT_REACHED(); // implementsCall should prevent us from reaching here - return 0; + ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here + return noValue(); } template @@ -332,31 +334,31 @@ void JSCallbackObject::getPropertyNames(ExecState* exec, PropertyNameArray JSContextRef execRef = toRef(exec); JSObjectRef thisRef = toRef(this); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) { - JSLock::DropAllLocks dropAllLocks; + JSLock::DropAllLocks dropAllLocks(exec); getPropertyNames(execRef, thisRef, toRef(&propertyNames)); } - if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) { - typedef OpaqueJSClass::StaticValuesTable::const_iterator iterator; + if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) { + typedef OpaqueJSClassStaticValuesTable::const_iterator iterator; iterator end = staticValues->end(); for (iterator it = staticValues->begin(); it != end; ++it) { UString::Rep* name = it->first.get(); StaticValueEntry* entry = it->second; if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum)) - propertyNames.add(Identifier(name)); + propertyNames.add(Identifier(exec, name)); } } - if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { - typedef OpaqueJSClass::StaticFunctionsTable::const_iterator iterator; + if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) { + typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator; iterator end = staticFunctions->end(); for (iterator it = staticFunctions->begin(); it != end; ++it) { UString::Rep* name = it->first.get(); StaticFunctionEntry* entry = it->second; if (!(entry->attributes & kJSPropertyAttributeDontEnum)) - propertyNames.add(Identifier(name)); + propertyNames.add(Identifier(exec, name)); } } } @@ -367,12 +369,17 @@ void JSCallbackObject::getPropertyNames(ExecState* exec, PropertyNameArray template double JSCallbackObject::toNumber(ExecState* exec) const { + // We need this check to guard against the case where this object is rhs of + // a binary expression where lhs threw an exception in its conversion to + // primitive + if (exec->hadException()) + return NaN; JSContextRef ctx = toRef(exec); JSObjectRef thisRef = toRef(this); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) { - JSLock::DropAllLocks dropAllLocks; + JSLock::DropAllLocks dropAllLocks(exec); if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot()))) return toJS(value)->getNumber(); } @@ -386,10 +393,14 @@ UString JSCallbackObject::toString(ExecState* exec) const JSContextRef ctx = toRef(exec); JSObjectRef thisRef = toRef(this); - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) { - JSLock::DropAllLocks dropAllLocks; - if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot()))) + JSValueRef value; + { + JSLock::DropAllLocks dropAllLocks(exec); + value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot())); + } + if (value) return toJS(value)->getString(); } @@ -399,19 +410,19 @@ UString JSCallbackObject::toString(ExecState* exec) const template void JSCallbackObject::setPrivate(void* data) { - m_privateData = data; + m_callbackObjectData->privateData = data; } template void* JSCallbackObject::getPrivate() { - return m_privateData; + return m_callbackObjectData->privateData; } template bool JSCallbackObject::inherits(JSClassRef c) const { - for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) if (jsClass == c) return true; @@ -419,7 +430,7 @@ bool JSCallbackObject::inherits(JSClassRef c) const } template -JSValue* JSCallbackObject::cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot) +JSValue* JSCallbackObject::cachedValueGetter(ExecState*, const Identifier&, const PropertySlot& slot) { JSValue* v = slot.slotBase(); ASSERT(v); @@ -427,20 +438,21 @@ JSValue* JSCallbackObject::cachedValueGetter(ExecState*, JSObject*, const } template -JSValue* JSCallbackObject::staticValueGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) +JSValue* JSCallbackObject::staticValueGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) { - ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info)); - JSCallbackObject* thisObj = static_cast(slot.slotBase()); + JSCallbackObject* thisObj = asCallbackObject(slot.slotBase()); JSObjectRef thisRef = toRef(thisObj); - JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); + RefPtr propertyNameRef; - for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass) - if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) + for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) + if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) if (JSObjectGetPropertyCallback getProperty = entry->getProperty) { - JSLock::DropAllLocks dropAllLocks; - if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) return toJS(value); } @@ -448,21 +460,20 @@ JSValue* JSCallbackObject::staticValueGetter(ExecState* exec, JSObject*, c } template -JSValue* JSCallbackObject::staticFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) +JSValue* JSCallbackObject::staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) { - ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info)); - JSCallbackObject* thisObj = static_cast(slot.slotBase()); + JSCallbackObject* thisObj = asCallbackObject(slot.slotBase()); // Check for cached or override property. - PropertySlot slot2; + PropertySlot slot2(thisObj); if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2)) - return slot2.getValue(exec, thisObj, propertyName); + return slot2.getValue(exec, propertyName); - for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass) { - if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { + for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) { + if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) { if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) { if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) { - JSObject* o = new JSCallbackFunction(exec, callAsFunction, propertyName); + JSObject* o = new (exec) JSCallbackFunction(exec, callAsFunction, propertyName); thisObj->putDirect(propertyName, o, entry->attributes); return o; } @@ -474,22 +485,23 @@ JSValue* JSCallbackObject::staticFunctionGetter(ExecState* exec, JSObject* } template -JSValue* JSCallbackObject::callbackGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) +JSValue* JSCallbackObject::callbackGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) { - ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info)); - JSCallbackObject* thisObj = static_cast(slot.slotBase()); + JSCallbackObject* thisObj = asCallbackObject(slot.slotBase()); JSObjectRef thisRef = toRef(thisObj); - JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); + RefPtr propertyNameRef; - for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass) + for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) { - JSLock::DropAllLocks dropAllLocks; - if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.ustring()); + JSLock::DropAllLocks dropAllLocks(exec); + if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) return toJS(value); } return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist."); } -} // namespace KJS +} // namespace JSC diff --git a/JavaScriptCore/API/JSClassRef.cpp b/JavaScriptCore/API/JSClassRef.cpp index 98aaaf5..88fd70d 100644 --- a/JavaScriptCore/API/JSClassRef.cpp +++ b/JavaScriptCore/API/JSClassRef.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * @@ -30,21 +29,18 @@ #include "APICast.h" #include "JSCallbackObject.h" #include "JSObjectRef.h" -#include +#include +#include +#include #include -#include -using namespace KJS; +using namespace JSC; const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass) - // FIXME: - : className(definition->className) - , parentClass(definition->parentClass) + : parentClass(definition->parentClass) , prototypeClass(0) - , staticValues(0) - , staticFunctions(0) , initialize(definition->initialize) , finalize(definition->finalize) , hasProperty(definition->hasProperty) @@ -56,23 +52,25 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* , callAsConstructor(definition->callAsConstructor) , hasInstance(definition->hasInstance) , convertToType(definition->convertToType) - , cachedPrototype(0) + , m_className(UString::Rep::createFromUTF8(definition->className)) + , m_staticValues(0) + , m_staticFunctions(0) { + initializeThreading(); + if (const JSStaticValue* staticValue = definition->staticValues) { - staticValues = new StaticValuesTable(); + m_staticValues = new OpaqueJSClassStaticValuesTable(); while (staticValue->name) { - // FIXME: - staticValues->add(Identifier(staticValue->name).ustring().rep(), + m_staticValues->add(UString::Rep::createFromUTF8(staticValue->name), new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes)); ++staticValue; } } - + if (const JSStaticFunction* staticFunction = definition->staticFunctions) { - staticFunctions = new StaticFunctionsTable(); + m_staticFunctions = new OpaqueJSClassStaticFunctionsTable(); while (staticFunction->name) { - // FIXME: - staticFunctions->add(Identifier(staticFunction->name).ustring().rep(), + m_staticFunctions->add(UString::Rep::createFromUTF8(staticFunction->name), new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes)); ++staticFunction; } @@ -84,48 +82,131 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* OpaqueJSClass::~OpaqueJSClass() { - if (staticValues) { - deleteAllValues(*staticValues); - delete staticValues; + ASSERT(!m_className.rep()->identifierTable()); + + if (m_staticValues) { + OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end(); + for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) { + ASSERT(!it->first->identifierTable()); + delete it->second; + } + delete m_staticValues; } - if (staticFunctions) { - deleteAllValues(*staticFunctions); - delete staticFunctions; + if (m_staticFunctions) { + OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end(); + for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) { + ASSERT(!it->first->identifierTable()); + delete it->second; + } + delete m_staticFunctions; } if (prototypeClass) JSClassRelease(prototypeClass); } -JSClassRef OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition) +PassRefPtr OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition) { - return new OpaqueJSClass(definition, 0); + return adoptRef(new OpaqueJSClass(definition, 0)); } void clearReferenceToPrototype(JSObjectRef prototype) { - OpaqueJSClass* jsClass = static_cast(JSObjectGetPrivate(prototype)); - ASSERT(jsClass); - jsClass->cachedPrototype = 0; + OpaqueJSClassContextData* jsClassData = static_cast(JSObjectGetPrivate(prototype)); + ASSERT(jsClassData); + jsClassData->cachedPrototype = 0; } -JSClassRef OpaqueJSClass::create(const JSClassDefinition* definition) +PassRefPtr OpaqueJSClass::create(const JSClassDefinition* definition) { if (const JSStaticFunction* staticFunctions = definition->staticFunctions) { // copy functions into a prototype class JSClassDefinition protoDefinition = kJSClassDefinitionEmpty; protoDefinition.staticFunctions = staticFunctions; protoDefinition.finalize = clearReferenceToPrototype; - OpaqueJSClass* protoClass = new OpaqueJSClass(&protoDefinition, 0); + + // We are supposed to use JSClassRetain/Release but since we know that we currently have + // the only reference to this class object we cheat and use a RefPtr instead. + RefPtr protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0)); // remove functions from the original class JSClassDefinition objectDefinition = *definition; objectDefinition.staticFunctions = 0; - return new OpaqueJSClass(&objectDefinition, protoClass); + + return adoptRef(new OpaqueJSClass(&objectDefinition, protoClass.get())); + } + + return adoptRef(new OpaqueJSClass(definition, 0)); +} + +OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass) + : m_class(jsClass) + , cachedPrototype(0) +{ + if (jsClass->m_staticValues) { + staticValues = new OpaqueJSClassStaticValuesTable; + OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end(); + for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) { + ASSERT(!it->first->identifierTable()); + staticValues->add(UString::Rep::createCopying(it->first->data(), it->first->size()), + new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes)); + } + + } else + staticValues = 0; + + + if (jsClass->m_staticFunctions) { + staticFunctions = new OpaqueJSClassStaticFunctionsTable; + OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end(); + for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) { + ASSERT(!it->first->identifierTable()); + staticFunctions->add(UString::Rep::createCopying(it->first->data(), it->first->size()), + new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes)); + } + + } else + staticFunctions = 0; +} + +OpaqueJSClassContextData::~OpaqueJSClassContextData() +{ + if (staticValues) { + deleteAllValues(*staticValues); + delete staticValues; } - return new OpaqueJSClass(definition, 0); + if (staticFunctions) { + deleteAllValues(*staticFunctions); + delete staticFunctions; + } +} + +OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec) +{ + OpaqueJSClassContextData*& contextData = exec->globalData().opaqueJSClassData.add(this, 0).first->second; + if (!contextData) + contextData = new OpaqueJSClassContextData(this); + return *contextData; +} + +UString OpaqueJSClass::className() +{ + // Make a deep copy, so that the caller has no chance to put the original into IdentifierTable. + return UString(m_className.data(), m_className.size()); +} + +OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec) +{ + OpaqueJSClassContextData& jsClassData = contextData(exec); + return jsClassData.staticValues; +} + +OpaqueJSClassStaticFunctionsTable* OpaqueJSClass::staticFunctions(JSC::ExecState* exec) +{ + OpaqueJSClassContextData& jsClassData = contextData(exec); + return jsClassData.staticFunctions; } /*! @@ -136,7 +217,7 @@ JSClassRef OpaqueJSClass::create(const JSClassDefinition* definition) @param jsClass A JSClass whose prototype you want to get. @result The JSObject prototype that was automatically generated for jsClass, or NULL if no prototype was automatically generated. This is the prototype that will be used when constructing an object using jsClass. */ -JSObject* OpaqueJSClass::prototype(JSContextRef ctx) +JSObject* OpaqueJSClass::prototype(ExecState* exec) { /* Class (C++) and prototype (JS) inheritance are parallel, so: * (C++) | (JS) @@ -148,17 +229,16 @@ JSObject* OpaqueJSClass::prototype(JSContextRef ctx) if (!prototypeClass) return 0; - - ExecState* exec = toJS(ctx); - - if (!cachedPrototype) { + + OpaqueJSClassContextData& jsClassData = contextData(exec); + + if (!jsClassData.cachedPrototype) { // Recursive, but should be good enough for our purposes - JSObject* parentPrototype = 0; - if (parentClass) - parentPrototype = parentClass->prototype(ctx); // can be null - if (!parentPrototype) - parentPrototype = exec->dynamicGlobalObject()->objectPrototype(); - cachedPrototype = new JSCallbackObject(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction + jsClassData.cachedPrototype = new (exec) JSCallbackObject(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData); // set jsClassData as the object's private data, so it can clear our reference on destruction + if (parentClass) { + if (JSObject* prototype = parentClass->prototype(exec)) + jsClassData.cachedPrototype->setPrototype(prototype); + } } - return cachedPrototype; + return jsClassData.cachedPrototype; } diff --git a/JavaScriptCore/API/JSClassRef.h b/JavaScriptCore/API/JSClassRef.h index eb2b35b..71fae18 100644 --- a/JavaScriptCore/API/JSClassRef.h +++ b/JavaScriptCore/API/JSClassRef.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * @@ -29,7 +28,7 @@ #include "JSObjectRef.h" -#include +#include #include #include #include @@ -56,22 +55,42 @@ struct StaticFunctionEntry { JSPropertyAttributes attributes; }; -struct OpaqueJSClass : public RefCounted { - static OpaqueJSClass* create(const JSClassDefinition*); - static OpaqueJSClass* createNoAutomaticPrototype(const JSClassDefinition*); +typedef HashMap, StaticValueEntry*> OpaqueJSClassStaticValuesTable; +typedef HashMap, StaticFunctionEntry*> OpaqueJSClassStaticFunctionsTable; + +class OpaqueJSClass; + +// An OpaqueJSClass (JSClass) is created without a context, so it can be used with any context, even across context groups. +// This structure holds data members that vary across context groups. +struct OpaqueJSClassContextData : Noncopyable { + OpaqueJSClassContextData(OpaqueJSClass*); + ~OpaqueJSClassContextData(); + + // It is necessary to keep OpaqueJSClass alive because of the following rare scenario: + // 1. A class is created and used, so its context data is stored in JSGlobalData hash map. + // 2. The class is released, and when all JS objects that use it are collected, OpaqueJSClass + // is deleted (that's the part prevented by this RefPtr). + // 3. Another class is created at the same address. + // 4. When it is used, the old context data is found in JSGlobalData and used. + RefPtr m_class; + + OpaqueJSClassStaticValuesTable* staticValues; + OpaqueJSClassStaticFunctionsTable* staticFunctions; + JSC::JSObject* cachedPrototype; +}; + +struct OpaqueJSClass : public ThreadSafeShared { + static PassRefPtr create(const JSClassDefinition*); + static PassRefPtr createNoAutomaticPrototype(const JSClassDefinition*); ~OpaqueJSClass(); - KJS::JSObject* prototype(JSContextRef ctx); - - typedef HashMap, StaticValueEntry*> StaticValuesTable; - typedef HashMap, StaticFunctionEntry*> StaticFunctionsTable; + JSC::UString className(); + OpaqueJSClassStaticValuesTable* staticValues(JSC::ExecState*); + OpaqueJSClassStaticFunctionsTable* staticFunctions(JSC::ExecState*); + JSC::JSObject* prototype(JSC::ExecState*); - KJS::UString className; OpaqueJSClass* parentClass; OpaqueJSClass* prototypeClass; - - StaticValuesTable* staticValues; - StaticFunctionsTable* staticFunctions; JSObjectInitializeCallback initialize; JSObjectFinalizeCallback finalize; @@ -86,12 +105,18 @@ struct OpaqueJSClass : public RefCounted { JSObjectConvertToTypeCallback convertToType; private: + friend struct OpaqueJSClassContextData; + OpaqueJSClass(); OpaqueJSClass(const OpaqueJSClass&); OpaqueJSClass(const JSClassDefinition*, OpaqueJSClass* protoClass); - - friend void clearReferenceToPrototype(JSObjectRef prototype); - KJS::JSObject* cachedPrototype; + + OpaqueJSClassContextData& contextData(JSC::ExecState*); + + // UStrings in these data members should not be put into any IdentifierTable. + JSC::UString m_className; + OpaqueJSClassStaticValuesTable* m_staticValues; + OpaqueJSClassStaticFunctionsTable* m_staticFunctions; }; #endif // JSClassRef_h diff --git a/JavaScriptCore/API/JSContextRef.cpp b/JavaScriptCore/API/JSContextRef.cpp index 203326e..ee7286d 100644 --- a/JavaScriptCore/API/JSContextRef.cpp +++ b/JavaScriptCore/API/JSContextRef.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * @@ -28,49 +27,104 @@ #include "JSContextRef.h" #include "APICast.h" +#include "InitializeThreading.h" #include "JSCallbackObject.h" #include "JSClassRef.h" #include "JSGlobalObject.h" -#include "object.h" +#include "JSObject.h" #include -using namespace KJS; +using namespace JSC; + +JSContextGroupRef JSContextGroupCreate() +{ + return toRef(JSGlobalData::create().releaseRef()); +} + +JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) +{ + toJS(group)->ref(); + return group; +} + +void JSContextGroupRelease(JSContextGroupRef group) +{ + toJS(group)->deref(); +} JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) { - JSLock lock; + JSLock lock(true); + return JSGlobalContextCreateInGroup(toRef(&JSGlobalData::sharedInstance()), globalObjectClass); +} + +JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) +{ + initializeThreading(); + + JSLock lock(true); + + RefPtr globalData = group ? PassRefPtr(toJS(group)) : JSGlobalData::create(); if (!globalObjectClass) { - JSGlobalObject* globalObject = new JSGlobalObject; + JSGlobalObject* globalObject = new (globalData.get()) JSGlobalObject; return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec())); } - JSGlobalObject* globalObject = new JSCallbackObject(globalObjectClass); - JSGlobalContextRef ctx = toGlobalRef(globalObject->globalExec()); - JSValue* prototype = globalObjectClass->prototype(ctx); + JSGlobalObject* globalObject = new (globalData.get()) JSCallbackObject(globalObjectClass); + ExecState* exec = globalObject->globalExec(); + JSValue* prototype = globalObjectClass->prototype(exec); if (!prototype) prototype = jsNull(); - globalObject->reset(prototype); - return JSGlobalContextRetain(ctx); + globalObject->resetPrototype(prototype); + return JSGlobalContextRetain(toGlobalRef(exec)); } JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx) { - JSLock lock; ExecState* exec = toJS(ctx); + JSLock lock(exec); + + JSGlobalData& globalData = exec->globalData(); + + globalData.heap.registerThread(); + gcProtect(exec->dynamicGlobalObject()); + globalData.ref(); return ctx; } void JSGlobalContextRelease(JSGlobalContextRef ctx) { - JSLock lock; ExecState* exec = toJS(ctx); + JSLock lock(exec); + gcUnprotect(exec->dynamicGlobalObject()); + + JSGlobalData& globalData = exec->globalData(); + if (globalData.refCount() == 2) { // One reference is held by JSGlobalObject, another added by JSGlobalContextRetain(). + // The last reference was released, this is our last chance to collect. + ASSERT(!globalData.heap.protectedObjectCount()); + ASSERT(!globalData.heap.isBusy()); + globalData.heap.destroy(); + } else + globalData.heap.collect(); + + globalData.deref(); } JSObjectRef JSContextGetGlobalObject(JSContextRef ctx) { ExecState* exec = toJS(ctx); - return toRef(exec->dynamicGlobalObject()); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + // It is necessary to call toThisObject to get the wrapper object when used with WebCore. + return toRef(exec->lexicalGlobalObject()->toThisObject(exec)); +} + +JSContextGroupRef JSContextGetGroup(JSContextRef ctx) +{ + ExecState* exec = toJS(ctx); + return toRef(&exec->globalData()); } diff --git a/JavaScriptCore/API/JSContextRef.h b/JavaScriptCore/API/JSContextRef.h index df0a397..bb6ea6e 100644 --- a/JavaScriptCore/API/JSContextRef.h +++ b/JavaScriptCore/API/JSContextRef.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * @@ -29,8 +28,11 @@ #include #include +#include +#ifndef __cplusplus #include +#endif #ifdef __cplusplus extern "C" { @@ -38,14 +40,58 @@ extern "C" { /*! @function +@abstract Creates a JavaScript context group. +@discussion A JSContextGroup associates JavaScript contexts with one another. + Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging + JavaScript objects between contexts in different groups will produce undefined behavior. + When objects from the same context group are used in multiple threads, explicit + synchronization is required. +@result The created JSContextGroup. +*/ +JS_EXPORT JSContextGroupRef JSContextGroupCreate() AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! +@function +@abstract Retains a JavaScript context group. +@param group The JSContextGroup to retain. +@result A JSContextGroup that is the same as group. +*/ +JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! +@function +@abstract Releases a JavaScript context group. +@param group The JSContextGroup to release. +*/ +JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! +@function @abstract Creates a global JavaScript execution context. @discussion JSGlobalContextCreate allocates a global object and populates it with all the built-in JavaScript objects, such as Object, Function, String, and Array. + + The created context can only be used on the main thread. JavaScript values cannot be + shared or exchanged between contexts. @param globalObjectClass The class to use when creating the global object. Pass NULL to use the default object class. @result A JSGlobalContext with a global object of class globalObjectClass. */ -JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass); +JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1; + +/*! +@function +@abstract Creates a global JavaScript execution context in the context group provided. +@discussion JSGlobalContextCreateInGroup allocates a global object and populates it with + all the built-in JavaScript objects, such as Object, Function, String, and Array. +@param globalObjectClass The class to use when creating the global object. Pass + NULL to use the default object class. +@param group The context group to use. The created global context retains the group. + Pass NULL to create a unique group for the context. +@result A JSGlobalContext with a global object of class globalObjectClass and a context + group equal to group. +*/ +JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; /*! @function @@ -70,8 +116,16 @@ JS_EXPORT void JSGlobalContextRelease(JSGlobalContextRef ctx); */ JS_EXPORT JSObjectRef JSContextGetGlobalObject(JSContextRef ctx); +/*! +@function +@abstract Gets the context group to which a JavaScript execution context belongs. +@param ctx The JSContext whose group you want to get. +@result ctx's group. +*/ +JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + #ifdef __cplusplus } #endif -#endif // JSContextRef_h +#endif /* JSContextRef_h */ diff --git a/JavaScriptCore/API/JSNode.c b/JavaScriptCore/API/JSNode.c deleted file mode 100644 index c1f6294..0000000 --- a/JavaScriptCore/API/JSNode.c +++ /dev/null @@ -1,197 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "JSNode.h" -#include "JSNodeList.h" -#include "JSObjectRef.h" -#include "JSStringRef.h" -#include "JSValueRef.h" -#include "Node.h" -#include "NodeList.h" -#include "UnusedParam.h" -#include - -static JSValueRef JSNode_appendChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - UNUSED_PARAM(function); - - // Example of throwing a type error for invalid values - if (!JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) { - JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes"); - *exception = JSValueMakeString(context, message); - JSStringRelease(message); - } else if (argumentCount < 1 || !JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) { - JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node"); - *exception = JSValueMakeString(context, message); - JSStringRelease(message); - } else { - Node* node = JSObjectGetPrivate(thisObject); - Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], NULL)); - - Node_appendChild(node, child); - } - - return JSValueMakeUndefined(context); -} - -static JSValueRef JSNode_removeChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - UNUSED_PARAM(function); - - // Example of ignoring invalid values - if (argumentCount > 0) { - if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) { - if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) { - Node* node = JSObjectGetPrivate(thisObject); - Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception)); - - Node_removeChild(node, child); - } - } - } - - return JSValueMakeUndefined(context); -} - -static JSValueRef JSNode_replaceChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - UNUSED_PARAM(function); - - if (argumentCount > 1) { - if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) { - if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) { - if (JSValueIsObjectOfClass(context, arguments[1], JSNode_class(context))) { - Node* node = JSObjectGetPrivate(thisObject); - Node* newChild = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception)); - Node* oldChild = JSObjectGetPrivate(JSValueToObject(context, arguments[1], exception)); - - Node_replaceChild(node, newChild, oldChild); - } - } - } - } - - return JSValueMakeUndefined(context); -} - -static JSStaticFunction JSNode_staticFunctions[] = { - { "appendChild", JSNode_appendChild, kJSPropertyAttributeDontDelete }, - { "removeChild", JSNode_removeChild, kJSPropertyAttributeDontDelete }, - { "replaceChild", JSNode_replaceChild, kJSPropertyAttributeDontDelete }, - { 0, 0, 0 } -}; - -static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) -{ - UNUSED_PARAM(propertyName); - UNUSED_PARAM(exception); - - Node* node = JSObjectGetPrivate(object); - if (node) { - JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType); - JSValueRef value = JSValueMakeString(context, nodeType); - JSStringRelease(nodeType); - return value; - } - - return NULL; -} - -static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) -{ - UNUSED_PARAM(propertyName); - UNUSED_PARAM(exception); - - Node* node = JSObjectGetPrivate(thisObject); - ASSERT(node); - return JSNodeList_new(context, NodeList_new(node)); -} - -static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) -{ - UNUSED_PARAM(object); - UNUSED_PARAM(propertyName); - UNUSED_PARAM(exception); - - return JSValueMakeUndefined(context); -} - -static JSStaticValue JSNode_staticValues[] = { - { "nodeType", JSNode_getNodeType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "childNodes", JSNode_getChildNodes, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "firstChild", JSNode_getFirstChild, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -static void JSNode_initialize(JSContextRef context, JSObjectRef object) -{ - UNUSED_PARAM(context); - - Node* node = JSObjectGetPrivate(object); - ASSERT(node); - - Node_ref(node); -} - -static void JSNode_finalize(JSObjectRef object) -{ - Node* node = JSObjectGetPrivate(object); - ASSERT(node); - - Node_deref(node); -} - -JSClassRef JSNode_class(JSContextRef context) -{ - UNUSED_PARAM(context); - - static JSClassRef jsClass; - if (!jsClass) { - JSClassDefinition definition = kJSClassDefinitionEmpty; - definition.staticValues = JSNode_staticValues; - definition.staticFunctions = JSNode_staticFunctions; - definition.initialize = JSNode_initialize; - definition.finalize = JSNode_finalize; - - jsClass = JSClassCreate(&definition); - } - return jsClass; -} - -JSObjectRef JSNode_new(JSContextRef context, Node* node) -{ - return JSObjectMake(context, JSNode_class(context), node); -} - -JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - UNUSED_PARAM(object); - UNUSED_PARAM(argumentCount); - UNUSED_PARAM(arguments); - UNUSED_PARAM(exception); - - return JSNode_new(context, Node_new()); -} diff --git a/JavaScriptCore/API/JSNode.h b/JavaScriptCore/API/JSNode.h deleted file mode 100644 index cd3a441..0000000 --- a/JavaScriptCore/API/JSNode.h +++ /dev/null @@ -1,38 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef JSNode_h -#define JSNode_h - -#include "JSBase.h" -#include "Node.h" -#include - -extern JSObjectRef JSNode_new(JSContextRef context, Node* node); -extern JSClassRef JSNode_class(JSContextRef context); -extern JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - -#endif // JSNode_h diff --git a/JavaScriptCore/API/JSNodeList.c b/JavaScriptCore/API/JSNodeList.c deleted file mode 100644 index 0da7c8d..0000000 --- a/JavaScriptCore/API/JSNodeList.c +++ /dev/null @@ -1,124 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "JSNode.h" -#include "JSNodeList.h" -#include "JSObjectRef.h" -#include "JSValueRef.h" -#include "UnusedParam.h" -#include - -static JSValueRef JSNodeList_item(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - UNUSED_PARAM(object); - - if (argumentCount > 0) { - NodeList* nodeList = JSObjectGetPrivate(thisObject); - ASSERT(nodeList); - Node* node = NodeList_item(nodeList, (unsigned)JSValueToNumber(context, arguments[0], exception)); - if (node) - return JSNode_new(context, node); - } - - return JSValueMakeUndefined(context); -} - -static JSStaticFunction JSNodeList_staticFunctions[] = { - { "item", JSNodeList_item, kJSPropertyAttributeDontDelete }, - { 0, 0, 0 } -}; - -static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) -{ - UNUSED_PARAM(propertyName); - UNUSED_PARAM(exception); - - NodeList* nodeList = JSObjectGetPrivate(thisObject); - ASSERT(nodeList); - return JSValueMakeNumber(context, NodeList_length(nodeList)); -} - -static JSStaticValue JSNodeList_staticValues[] = { - { "length", JSNodeList_length, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { 0, 0, 0, 0 } -}; - -static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) -{ - NodeList* nodeList = JSObjectGetPrivate(thisObject); - ASSERT(nodeList); - double index = JSValueToNumber(context, JSValueMakeString(context, propertyName), exception); - unsigned uindex = (unsigned)index; - if (uindex == index) { // false for NaN - Node* node = NodeList_item(nodeList, uindex); - if (node) - return JSNode_new(context, node); - } - - return NULL; -} - -static void JSNodeList_initialize(JSContextRef context, JSObjectRef thisObject) -{ - UNUSED_PARAM(context); - - NodeList* nodeList = JSObjectGetPrivate(thisObject); - ASSERT(nodeList); - - NodeList_ref(nodeList); -} - -static void JSNodeList_finalize(JSObjectRef thisObject) -{ - NodeList* nodeList = JSObjectGetPrivate(thisObject); - ASSERT(nodeList); - - NodeList_deref(nodeList); -} - -static JSClassRef JSNodeList_class(JSContextRef context) -{ - UNUSED_PARAM(context); - - static JSClassRef jsClass; - if (!jsClass) { - JSClassDefinition definition = kJSClassDefinitionEmpty; - definition.staticValues = JSNodeList_staticValues; - definition.staticFunctions = JSNodeList_staticFunctions; - definition.getProperty = JSNodeList_getProperty; - definition.initialize = JSNodeList_initialize; - definition.finalize = JSNodeList_finalize; - - jsClass = JSClassCreate(&definition); - } - - return jsClass; -} - -JSObjectRef JSNodeList_new(JSContextRef context, NodeList* nodeList) -{ - return JSObjectMake(context, JSNodeList_class(context), nodeList); -} diff --git a/JavaScriptCore/API/JSNodeList.h b/JavaScriptCore/API/JSNodeList.h deleted file mode 100644 index 0bc5f74..0000000 --- a/JavaScriptCore/API/JSNodeList.h +++ /dev/null @@ -1,35 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef JSNodeList_h -#define JSNodeList_h - -#include "JSBase.h" -#include "NodeList.h" - -extern JSObjectRef JSNodeList_new(JSContextRef, NodeList*); - -#endif // JSNodeList_h diff --git a/JavaScriptCore/API/JSObjectRef.cpp b/JavaScriptCore/API/JSObjectRef.cpp index c6cda25..a4f32ba 100644 --- a/JavaScriptCore/API/JSObjectRef.cpp +++ b/JavaScriptCore/API/JSObjectRef.cpp @@ -1,6 +1,6 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,108 +27,200 @@ #include "config.h" #include "JSObjectRef.h" -#include #include "APICast.h" -#include "JSValueRef.h" +#include "DateConstructor.h" +#include "ErrorConstructor.h" +#include "FunctionConstructor.h" +#include "JSArray.h" #include "JSCallbackConstructor.h" #include "JSCallbackFunction.h" #include "JSCallbackObject.h" #include "JSClassRef.h" +#include "JSFunction.h" #include "JSGlobalObject.h" - +#include "JSObject.h" +#include "JSRetainPtr.h" +#include "JSString.h" +#include "JSValueRef.h" +#include "ObjectPrototype.h" #include "PropertyNameArray.h" -#include "function.h" -#include "function_object.h" +#include "RegExpConstructor.h" #include "identifier.h" -#include "internal.h" -#include "object.h" -#include "object_object.h" +#include -using namespace KJS; +using namespace JSC; JSClassRef JSClassCreate(const JSClassDefinition* definition) { - JSLock lock; - JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype) + RefPtr jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype) ? OpaqueJSClass::createNoAutomaticPrototype(definition) : OpaqueJSClass::create(definition); - return JSClassRetain(jsClass); + return jsClass.release().releaseRef(); } JSClassRef JSClassRetain(JSClassRef jsClass) { - JSLock lock; jsClass->ref(); return jsClass; } void JSClassRelease(JSClassRef jsClass) { - JSLock lock; jsClass->deref(); } JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); if (!jsClass) - return toRef(new JSObject(exec->lexicalGlobalObject()->objectPrototype())); // slightly more efficient + return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure())); // slightly more efficient - JSValue* jsPrototype = jsClass->prototype(ctx); - if (!jsPrototype) - jsPrototype = exec->lexicalGlobalObject()->objectPrototype(); + JSCallbackObject* object = new (exec) JSCallbackObject(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data); + if (JSObject* prototype = jsClass->prototype(exec)) + object->setPrototype(prototype); - return toRef(new JSCallbackObject(exec, jsClass, jsPrototype, data)); + return toRef(object); } JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction) { - JSLock lock; ExecState* exec = toJS(ctx); - Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous"); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous"); - return toRef(new JSCallbackFunction(exec, callAsFunction, nameID)); + return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID)); } JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor) { - JSLock lock; ExecState* exec = toJS(ctx); - + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSValue* jsPrototype = jsClass - ? jsClass->prototype(ctx) - : exec->dynamicGlobalObject()->objectPrototype(); + ? jsClass->prototype(exec) + : exec->lexicalGlobalObject()->objectPrototype(); - JSCallbackConstructor* constructor = new JSCallbackConstructor(exec, jsClass, callAsConstructor); + JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor); constructor->putDirect(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) { - JSLock lock; - ExecState* exec = toJS(ctx); - UString::Rep* bodyRep = toJS(body); - UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; - - Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous"); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous"); - List args; + ArgList args; for (unsigned i = 0; i < parameterCount; i++) - args.append(jsString(UString(toJS(parameterNames[i])))); - args.append(jsString(UString(bodyRep))); + args.append(jsString(exec, parameterNames[i]->ustring())); + args.append(jsString(exec, body->ustring())); + + JSObject* result = constructFunction(exec, args, nameID, sourceURL->ustring(), startingLineNumber); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec->exception()); + exec->clearException(); + result = 0; + } + return toRef(result); +} + +JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + JSObject* result; + if (argumentCount) { + ArgList argList; + for (size_t i = 0; i < argumentCount; ++i) + argList.append(toJS(arguments[i])); + + result = constructArray(exec, argList); + } else + result = constructEmptyArray(exec); + + if (exec->hadException()) { + if (exception) + *exception = toRef(exec->exception()); + exec->clearException(); + result = 0; + } + + return toRef(result); +} + +JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + ArgList argList; + for (size_t i = 0; i < argumentCount; ++i) + argList.append(toJS(arguments[i])); + + JSObject* result = constructDate(exec, argList); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec->exception()); + exec->clearException(); + result = 0; + } + + return toRef(result); +} - JSObject* result = exec->dynamicGlobalObject()->functionConstructor()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber); +JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + ArgList argList; + for (size_t i = 0; i < argumentCount; ++i) + argList.append(toJS(arguments[i])); + + JSObject* result = constructError(exec, argList); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); result = 0; } + + return toRef(result); +} + +JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + ArgList argList; + for (size_t i = 0; i < argumentCount; ++i) + argList.append(toJS(arguments[i])); + + JSObject* result = constructRegExp(exec, argList); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec->exception()); + exec->clearException(); + result = 0; + } + return toRef(result); } @@ -143,27 +235,29 @@ void JSObjectSetPrototype(JSContextRef, JSObjectRef object, JSValueRef value) JSObject* jsObject = toJS(object); JSValue* jsValue = toJS(value); - jsObject->setPrototype(jsValue); + jsObject->setPrototype(jsValue->isObject() ? jsValue : jsNull()); } bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); - UString::Rep* nameRep = toJS(propertyName); - return jsObject->hasProperty(exec, Identifier(nameRep)); + return jsObject->hasProperty(exec, propertyName->identifier(&exec->globalData())); } JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); - UString::Rep* nameRep = toJS(propertyName); - JSValue* jsValue = jsObject->get(exec, Identifier(nameRep)); + JSValue* jsValue = jsObject->get(exec, propertyName->identifier(&exec->globalData())); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); @@ -174,13 +268,21 @@ JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); - UString::Rep* nameRep = toJS(propertyName); + Identifier name(propertyName->identifier(&exec->globalData())); JSValue* jsValue = toJS(value); - - jsObject->put(exec, Identifier(nameRep), jsValue, attributes); + + if (attributes && !jsObject->hasProperty(exec, name)) + jsObject->putWithAttributes(exec, name, jsValue, attributes); + else { + PutPropertySlot slot; + jsObject->put(exec, name, jsValue, slot); + } + if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); @@ -190,8 +292,10 @@ void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); JSValue* jsValue = jsObject->get(exec, propertyIndex); @@ -206,8 +310,10 @@ JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsi void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); JSValue* jsValue = toJS(value); @@ -221,12 +327,13 @@ void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned p bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); - UString::Rep* nameRep = toJS(propertyName); - bool result = jsObject->deleteProperty(exec, Identifier(nameRep)); + bool result = jsObject->deleteProperty(exec, propertyName->identifier(&exec->globalData())); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); @@ -264,25 +371,32 @@ bool JSObjectSetPrivate(JSObjectRef object, void* data) bool JSObjectIsFunction(JSContextRef, JSObjectRef object) { - JSObject* jsObject = toJS(object); - return jsObject->implementsCall(); + CallData callData; + return toJS(object)->getCallData(callData) != CallTypeNone; } JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); JSObject* jsThisObject = toJS(thisObject); if (!jsThisObject) - jsThisObject = exec->dynamicGlobalObject(); - - List argList; + jsThisObject = exec->globalThisValue(); + + ArgList argList; for (size_t i = 0; i < argumentCount; i++) argList.append(toJS(arguments[i])); - JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false + CallData callData; + CallType callType = jsObject->getCallData(callData); + if (callType == CallTypeNone) + return 0; + + JSValueRef result = toRef(call(exec, jsObject, callType, callData, jsThisObject, argList)); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); @@ -295,20 +409,27 @@ JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObject bool JSObjectIsConstructor(JSContextRef, JSObjectRef object) { JSObject* jsObject = toJS(object); - return jsObject->implementsConstruct(); + ConstructData constructData; + return jsObject->getConstructData(constructData) != ConstructTypeNone; } JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsObject = toJS(object); - - List argList; + + ConstructData constructData; + ConstructType constructType = jsObject->getConstructData(constructData); + if (constructType == ConstructTypeNone) + return 0; + + ArgList argList; for (size_t i = 0; i < argumentCount; i++) argList.append(toJS(arguments[i])); - - JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false + JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList)); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); @@ -318,40 +439,51 @@ JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size return result; } -struct OpaqueJSPropertyNameArray -{ - OpaqueJSPropertyNameArray() : refCount(0) +struct OpaqueJSPropertyNameArray { + OpaqueJSPropertyNameArray(JSGlobalData* globalData) + : refCount(0) + , globalData(globalData) { } unsigned refCount; - PropertyNameArray array; + JSGlobalData* globalData; + Vector > array; }; JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object) { - JSLock lock; JSObject* jsObject = toJS(object); ExecState* exec = toJS(ctx); - - JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(); - jsObject->getPropertyNames(exec, propertyNames->array); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + JSGlobalData* globalData = &exec->globalData(); + + JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(globalData); + PropertyNameArray array(globalData); + jsObject->getPropertyNames(exec, array); + + size_t size = array.size(); + propertyNames->array.reserveCapacity(size); + for (size_t i = 0; i < size; ++i) + propertyNames->array.append(JSRetainPtr(Adopt, OpaqueJSString::create(array[i].ustring()).releaseRef())); return JSPropertyNameArrayRetain(propertyNames); } JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array) { - JSLock lock; ++array->refCount; return array; } void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array) { - JSLock lock; - if (--array->refCount == 0) + if (--array->refCount == 0) { + JSLock lock(array->globalData->isSharedInstance); delete array; + } } size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array) @@ -361,14 +493,15 @@ size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array) JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index) { - return toRef(array->array[static_cast(index)].ustring().rep()); + return array->array[static_cast(index)].get(); } void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName) { - JSLock lock; PropertyNameArray* propertyNames = toJS(array); - UString::Rep* rep = toJS(propertyName); - - propertyNames->add(Identifier(rep)); + + propertyNames->globalData()->heap.registerThread(); + JSLock lock(propertyNames->globalData()->isSharedInstance); + + propertyNames->add(propertyName->identifier(propertyNames->globalData())); } diff --git a/JavaScriptCore/API/JSObjectRef.h b/JavaScriptCore/API/JSObjectRef.h index bf4041f..461764c 100644 --- a/JavaScriptCore/API/JSObjectRef.h +++ b/JavaScriptCore/API/JSObjectRef.h @@ -1,6 +1,6 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +29,12 @@ #include #include +#include +#ifndef __cplusplus #include -#include // for size_t +#endif +#include /* for size_t */ #ifdef __cplusplus extern "C" { @@ -338,7 +341,7 @@ Standard JavaScript practice calls for storing function objects in prototypes, s A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute. */ typedef struct { - int version; // current (and only) version is 0 + int version; /* current (and only) version is 0 */ JSClassAttributes attributes; const char* className; @@ -428,6 +431,52 @@ JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStrin JS_EXPORT JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor); /*! + @function + @abstract Creates a JavaScript Array object. + @param ctx The execution context to use. + @param argumentCount An integer count of the number of arguments in arguments. + @param arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0. + @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. + @result A JSObject that is an Array. + @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument + is supplied, this function returns an array with one element. + */ +JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! + @function + @abstract Creates a JavaScript Date object, as if by invoking the built-in Date constructor. + @param ctx The execution context to use. + @param argumentCount An integer count of the number of arguments in arguments. + @param arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0. + @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. + @result A JSObject that is a Date. + */ +JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! + @function + @abstract Creates a JavaScript Error object, as if by invoking the built-in Error constructor. + @param ctx The execution context to use. + @param argumentCount An integer count of the number of arguments in arguments. + @param arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0. + @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. + @result A JSObject that is a Error. + */ +JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! + @function + @abstract Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor. + @param ctx The execution context to use. + @param argumentCount An integer count of the number of arguments in arguments. + @param arguments A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0. + @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. + @result A JSObject that is a RegExp. + */ +JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1; + +/*! @function @abstract Creates a function with a given script as its body. @param ctx The execution context to use. @@ -642,4 +691,4 @@ JS_EXPORT void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef acc } #endif -#endif // JSObjectRef_h +#endif /* JSObjectRef_h */ diff --git a/JavaScriptCore/API/JSProfilerPrivate.cpp b/JavaScriptCore/API/JSProfilerPrivate.cpp new file mode 100644 index 0000000..ea277f0 --- /dev/null +++ b/JavaScriptCore/API/JSProfilerPrivate.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSProfilerPrivate.h" + +#include "APICast.h" +#include "OpaqueJSString.h" +#include "Profiler.h" + +using namespace JSC; + +void JSStartProfiling(JSContextRef ctx, JSStringRef title) +{ + Profiler::profiler()->startProfiling(toJS(ctx), title->ustring()); +} + +void JSEndProfiling(JSContextRef ctx, JSStringRef title) +{ + ExecState* exec = toJS(ctx); + Profiler* profiler = Profiler::profiler(); + profiler->stopProfiling(exec, title->ustring()); +} + diff --git a/JavaScriptCore/API/JSProfilerPrivate.h b/JavaScriptCore/API/JSProfilerPrivate.h new file mode 100644 index 0000000..b3fe533 --- /dev/null +++ b/JavaScriptCore/API/JSProfilerPrivate.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSProfiler_h +#define JSProfiler_h + +#include + +#ifndef __cplusplus +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/*! +@function JSStartProfiling +@abstract Enables the profler. +@param ctx The execution context to use. +@param title The title of the profile. +@result The profiler is turned on. +*/ +JS_EXPORT void JSStartProfiling(JSContextRef ctx, JSStringRef title); + +/*! +@function JSEndProfiling +@abstract Disables the profler. +@param ctx The execution context to use. +@param title The title of the profile. +@result The profiler is turned off. If there is no name, the most recently started + profile is stopped. If the name does not match any profile then no profile + is stopped. +*/ +JS_EXPORT void JSEndProfiling(JSContextRef ctx, JSStringRef title); + +#ifdef __cplusplus +} +#endif + +#endif /* JSProfiler_h */ diff --git a/JavaScriptCore/API/JSStringRef.cpp b/JavaScriptCore/API/JSStringRef.cpp index 9a307d0..6452ffc 100644 --- a/JavaScriptCore/API/JSStringRef.cpp +++ b/JavaScriptCore/API/JSStringRef.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * @@ -27,92 +26,77 @@ #include "config.h" #include "JSStringRef.h" -#include - -#include "APICast.h" -#include -#include -#include -#include -#include -#include +#include "OpaqueJSString.h" #include -using namespace KJS; +using namespace JSC; using namespace WTF::Unicode; JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars) { - JSLock lock; - return toRef(UString(reinterpret_cast(chars), static_cast(numChars)).rep()->ref()); + return OpaqueJSString::create(chars, numChars).releaseRef(); } JSStringRef JSStringCreateWithUTF8CString(const char* string) { - JSLock lock; - - size_t length = strlen(string); - Vector< ::UChar, 1024> buffer(length); - ::UChar* p = buffer.data(); - if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length)) - return 0; - - return toRef(UString(reinterpret_cast(buffer.data()), p - buffer.data()).rep()->ref()); + if (string) { + size_t length = strlen(string); + Vector buffer(length); + UChar* p = buffer.data(); + if (conversionOK == convertUTF8ToUTF16(&string, string + length, &p, p + length)) + return OpaqueJSString::create(buffer.data(), p - buffer.data()).releaseRef(); + } + + // Null string. + return OpaqueJSString::create().releaseRef(); } JSStringRef JSStringRetain(JSStringRef string) { - JSLock lock; - UString::Rep* rep = toJS(string); - return toRef(rep->ref()); + string->ref(); + return string; } void JSStringRelease(JSStringRef string) { - JSLock lock; - UString::Rep* rep = toJS(string); - rep->deref(); + string->deref(); } size_t JSStringGetLength(JSStringRef string) { - UString::Rep* rep = toJS(string); - return rep->size(); + return string->length(); } const JSChar* JSStringGetCharactersPtr(JSStringRef string) { - UString::Rep* rep = toJS(string); - return reinterpret_cast(rep->data()); + return string->characters(); } size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string) { - UString::Rep* rep = toJS(string); - // Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair. - return rep->size() * 3 + 1; // + 1 for terminating '\0' + return string->length() * 3 + 1; // + 1 for terminating '\0' } size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize) { - JSLock lock; - UString::Rep* rep = toJS(string); - CString cString = UString(rep).UTF8String(); + if (!bufferSize) + return 0; + + char* p = buffer; + const UChar* d = string->characters(); + ConversionResult result = convertUTF16ToUTF8(&d, d + string->length(), &p, p + bufferSize - 1, true); + *p++ = '\0'; + if (result != conversionOK && result != targetExhausted) + return 0; - size_t length = std::min(bufferSize, cString.size() + 1); // + 1 for terminating '\0' - memcpy(buffer, cString.c_str(), length); - return length; + return p - buffer; } bool JSStringIsEqual(JSStringRef a, JSStringRef b) { - JSLock lock; - - UString::Rep* aRep = toJS(a); - UString::Rep* bRep = toJS(b); - - return UString(aRep) == UString(bRep); + unsigned len = a->length(); + return len == b->length() && 0 == memcmp(a->characters(), b->characters(), len * sizeof(UChar)); } bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b) diff --git a/JavaScriptCore/API/JSStringRef.h b/JavaScriptCore/API/JSStringRef.h index fb5649f..8b17ee2 100644 --- a/JavaScriptCore/API/JSStringRef.h +++ b/JavaScriptCore/API/JSStringRef.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * @@ -29,8 +28,10 @@ #include +#ifndef __cplusplus #include -#include // for size_t +#endif +#include /* for size_t */ #ifdef __cplusplus extern "C" { @@ -140,4 +141,4 @@ JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b); } #endif -#endif // JSStringRef_h +#endif /* JSStringRef_h */ diff --git a/JavaScriptCore/API/JSStringRefBSTR.cpp b/JavaScriptCore/API/JSStringRefBSTR.cpp index 1a538ab..a7d3e99 100644 --- a/JavaScriptCore/API/JSStringRefBSTR.cpp +++ b/JavaScriptCore/API/JSStringRefBSTR.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2007 Apple Inc. All rights reserved. * diff --git a/JavaScriptCore/API/JSStringRefBSTR.h b/JavaScriptCore/API/JSStringRefBSTR.h index 4987f83..59f19b7 100644 --- a/JavaScriptCore/API/JSStringRefBSTR.h +++ b/JavaScriptCore/API/JSStringRefBSTR.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2007 Apple Inc. All rights reserved. * @@ -38,7 +37,7 @@ extern "C" { #endif -// COM convenience methods +/* COM convenience methods */ /*! @function @@ -60,4 +59,4 @@ JS_EXPORT BSTR JSStringCopyBSTR(const JSStringRef string); } #endif -#endif // JSStringRefBSTR_h +#endif /* JSStringRefBSTR_h */ diff --git a/JavaScriptCore/API/JSStringRefCF.cpp b/JavaScriptCore/API/JSStringRefCF.cpp index 70a5aa7..3a37866 100644 --- a/JavaScriptCore/API/JSStringRefCF.cpp +++ b/JavaScriptCore/API/JSStringRefCF.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Computer, Inc. All rights reserved. * @@ -29,29 +28,25 @@ #include "APICast.h" #include "JSStringRef.h" -#include +#include "OpaqueJSString.h" #include -#include - -using namespace KJS; +#include +#include JSStringRef JSStringCreateWithCFString(CFStringRef string) { - JSLock lock; CFIndex length = CFStringGetLength(string); - UString::Rep* rep; - if (!length) - rep = UString("").rep()->ref(); - else { - UniChar* buffer = static_cast(fastMalloc(sizeof(UniChar) * length)); - CFStringGetCharacters(string, CFRangeMake(0, length), buffer); - rep = UString(reinterpret_cast(buffer), length, false).rep()->ref(); + if (length) { + OwnArrayPtr buffer(new UniChar[length]); + CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get()); + COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size); + return OpaqueJSString::create(reinterpret_cast(buffer.get()), length).releaseRef(); + } else { + return OpaqueJSString::create(0, 0).releaseRef(); + } } - return toRef(rep); -} CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string) { - UString::Rep* rep = toJS(string); - return CFStringCreateWithCharacters(alloc, reinterpret_cast(rep->data()), rep->size()); + return CFStringCreateWithCharacters(alloc, reinterpret_cast(string->characters()), string->length()); } diff --git a/JavaScriptCore/API/JSStringRefCF.h b/JavaScriptCore/API/JSStringRefCF.h index ef84a9c..a424765 100644 --- a/JavaScriptCore/API/JSStringRefCF.h +++ b/JavaScriptCore/API/JSStringRefCF.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Computer, Inc. All rights reserved. * @@ -34,7 +33,7 @@ extern "C" { #endif -// CFString convenience methods +/* CFString convenience methods */ /*! @function @@ -53,9 +52,9 @@ JS_EXPORT JSStringRef JSStringCreateWithCFString(CFStringRef string); @result A CFString containing string. Ownership follows the Create Rule. */ JS_EXPORT CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string); - + #ifdef __cplusplus } #endif -#endif // JSStringRefCF_h +#endif /* JSStringRefCF_h */ diff --git a/JavaScriptCore/API/JSValueRef.cpp b/JavaScriptCore/API/JSValueRef.cpp index 468a2d1..15dd633 100644 --- a/JavaScriptCore/API/JSValueRef.cpp +++ b/JavaScriptCore/API/JSValueRef.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * @@ -31,13 +30,12 @@ #include "APICast.h" #include "JSCallbackObject.h" -#include -#include -#include +#include +#include #include #include #include -#include +#include #include @@ -45,27 +43,22 @@ JSType JSValueGetType(JSContextRef, JSValueRef value) { - KJS::JSValue* jsValue = toJS(value); - switch (jsValue->type()) { - case KJS::UndefinedType: - return kJSTypeUndefined; - case KJS::NullType: - return kJSTypeNull; - case KJS::BooleanType: - return kJSTypeBoolean; - case KJS::NumberType: - return kJSTypeNumber; - case KJS::StringType: - return kJSTypeString; - case KJS::ObjectType: - return kJSTypeObject; - default: - ASSERT(!"JSValueGetType: unknown type code.\n"); - return kJSTypeUndefined; - } + JSC::JSValue* jsValue = toJS(value); + if (jsValue->isUndefined()) + return kJSTypeUndefined; + if (jsValue->isNull()) + return kJSTypeNull; + if (jsValue->isBoolean()) + return kJSTypeBoolean; + if (jsValue->isNumber()) + return kJSTypeNumber; + if (jsValue->isString()) + return kJSTypeString; + ASSERT(jsValue->isObject()); + return kJSTypeObject; } -using namespace KJS; // placed here to avoid conflict between KJS::JSType and JSType, above. +using namespace JSC; // placed here to avoid conflict between JSC::JSType and JSType, above. bool JSValueIsUndefined(JSContextRef, JSValueRef value) { @@ -118,8 +111,10 @@ bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass) bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSValue* jsA = toJS(a); JSValue* jsB = toJS(b); @@ -132,27 +127,26 @@ bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* ex return result; } -bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b) +bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b) { - JSLock lock; - ExecState* exec = toJS(ctx); JSValue* jsA = toJS(a); JSValue* jsB = toJS(b); - bool result = strictEqual(exec, jsA, jsB); // can't throw because it doesn't perform value conversion - ASSERT(!exec->hadException()); + bool result = strictEqual(jsA, jsB); return result; } bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSValue* jsValue = toJS(value); JSObject* jsConstructor = toJS(constructor); - if (!jsConstructor->implementsHasInstance()) + if (!jsConstructor->structureID()->typeInfo().implementsHasInstance()) return false; - bool result = jsConstructor->hasInstance(exec, jsValue); // false if an exception is thrown + bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); @@ -176,17 +170,22 @@ JSValueRef JSValueMakeBoolean(JSContextRef, bool value) return toRef(jsBoolean(value)); } -JSValueRef JSValueMakeNumber(JSContextRef, double value) +JSValueRef JSValueMakeNumber(JSContextRef ctx, double value) { - JSLock lock; - return toRef(jsNumber(value)); + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + return toRef(jsNumber(exec, value)); } -JSValueRef JSValueMakeString(JSContextRef, JSStringRef string) +JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) { - JSLock lock; - UString::Rep* rep = toJS(string); - return toRef(jsString(UString(rep))); + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + return toRef(jsString(exec, string->ustring())); } bool JSValueToBoolean(JSContextRef ctx, JSValueRef value) @@ -198,9 +197,11 @@ bool JSValueToBoolean(JSContextRef ctx, JSValueRef value) double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { - JSLock lock; - JSValue* jsValue = toJS(value); ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + JSValue* jsValue = toJS(value); double number = jsValue->toNumber(exec); if (exec->hadException()) { @@ -214,24 +215,28 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { - JSLock lock; - JSValue* jsValue = toJS(value); ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + JSValue* jsValue = toJS(value); - JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref()); + RefPtr stringRef(OpaqueJSString::create(jsValue->toString(exec))); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); - stringRef = 0; + stringRef.clear(); } - return stringRef; + return stringRef.release().releaseRef(); } JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSValue* jsValue = toJS(value); JSObjectRef objectRef = toRef(jsValue->toObject(exec)); @@ -244,16 +249,22 @@ JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exce return objectRef; } -void JSValueProtect(JSContextRef, JSValueRef value) +void JSValueProtect(JSContextRef ctx, JSValueRef value) { - JSLock lock; + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSValue* jsValue = toJS(value); gcProtect(jsValue); } -void JSValueUnprotect(JSContextRef, JSValueRef value) +void JSValueUnprotect(JSContextRef ctx, JSValueRef value) { - JSLock lock; + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSValue* jsValue = toJS(value); gcUnprotect(jsValue); } diff --git a/JavaScriptCore/API/JSValueRef.h b/JavaScriptCore/API/JSValueRef.h index 6f1ce08..7a7bf93 100644 --- a/JavaScriptCore/API/JSValueRef.h +++ b/JavaScriptCore/API/JSValueRef.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * @@ -29,7 +28,9 @@ #include +#ifndef __cplusplus #include +#endif /*! @enum JSType @@ -127,7 +128,7 @@ JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value); */ JS_EXPORT bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass); -// Comparing values +/* Comparing values */ /*! @function @@ -161,7 +162,7 @@ JS_EXPORT bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b */ JS_EXPORT bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception); -// Creating values +/* Creating values */ /*! @function @@ -207,7 +208,7 @@ JS_EXPORT JSValueRef JSValueMakeNumber(JSContextRef ctx, double number); */ JS_EXPORT JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string); -// Converting to primitive values +/* Converting to primitive values */ /*! @function @@ -248,7 +249,7 @@ JS_EXPORT JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JS */ JS_EXPORT JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception); -// Garbage collection +/* Garbage collection */ /*! @function @abstract Protects a JavaScript value from garbage collection. @@ -274,4 +275,4 @@ JS_EXPORT void JSValueUnprotect(JSContextRef ctx, JSValueRef value); } #endif -#endif // JSValueRef_h +#endif /* JSValueRef_h */ diff --git a/JavaScriptCore/API/JavaScript.h b/JavaScriptCore/API/JavaScript.h index 3a6cc38..f8d92d8 100644 --- a/JavaScriptCore/API/JavaScript.h +++ b/JavaScriptCore/API/JavaScript.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006 Apple Inc. All rights reserved. * Copyright (C) 2008 Alp Toker @@ -34,4 +33,4 @@ #include #include -#endif // JavaScript_h +#endif /* JavaScript_h */ diff --git a/JavaScriptCore/API/JavaScriptCore.h b/JavaScriptCore/API/JavaScriptCore.h index be6b8b2..87d6018 100644 --- a/JavaScriptCore/API/JavaScriptCore.h +++ b/JavaScriptCore/API/JavaScriptCore.h @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * @@ -30,4 +29,4 @@ #include #include -#endif // JavaScriptCore_h +#endif /* JavaScriptCore_h */ diff --git a/JavaScriptCore/API/Node.c b/JavaScriptCore/API/Node.c deleted file mode 100644 index 3ff82e2..0000000 --- a/JavaScriptCore/API/Node.c +++ /dev/null @@ -1,86 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Node.h" -#include -#include - -Node* Node_new(void) -{ - Node* node = (Node*)malloc(sizeof(Node)); - node->refCount = 0; - node->nodeType = "Node"; - node->childNodesTail = NULL; - - return node; -} - -void Node_appendChild(Node* node, Node* child) -{ - Node_ref(child); - NodeLink* nodeLink = (NodeLink*)malloc(sizeof(NodeLink)); - nodeLink->node = child; - nodeLink->prev = node->childNodesTail; - node->childNodesTail = nodeLink; -} - -void Node_removeChild(Node* node, Node* child) -{ - // Linear search from tail -- good enough for our purposes here - NodeLink* current; - NodeLink** currentHandle; - for (currentHandle = &node->childNodesTail, current = *currentHandle; current; currentHandle = ¤t->prev, current = *currentHandle) { - if (current->node == child) { - Node_deref(current->node); - *currentHandle = current->prev; - free(current); - break; - } - } -} - -void Node_replaceChild(Node* node, Node* newChild, Node* oldChild) -{ - // Linear search from tail -- good enough for our purposes here - NodeLink* current; - for (current = node->childNodesTail; current; current = current->prev) { - if (current->node == oldChild) { - Node_deref(current->node); - current->node = newChild; - } - } -} - -void Node_ref(Node* node) -{ - ++node->refCount; -} - -void Node_deref(Node* node) -{ - if (--node->refCount == 0) - free(node); -} diff --git a/JavaScriptCore/API/Node.h b/JavaScriptCore/API/Node.h deleted file mode 100644 index 04b2c70..0000000 --- a/JavaScriptCore/API/Node.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef Node_h -#define Node_h - -typedef struct __Node Node; -typedef struct __NodeLink NodeLink; - -struct __NodeLink { - Node* node; - NodeLink* prev; -}; - -struct __Node { - unsigned refCount; - const char* nodeType; - NodeLink* childNodesTail; -}; - -extern Node* Node_new(void); -extern void Node_ref(Node* node); -extern void Node_deref(Node* node); -extern void Node_appendChild(Node* node, Node* child); -extern void Node_removeChild(Node* node, Node* child); -extern void Node_replaceChild(Node* node, Node* newChild, Node* oldChild); - -#endif // Node_h diff --git a/JavaScriptCore/API/NodeList.c b/JavaScriptCore/API/NodeList.c deleted file mode 100644 index 21b2c62..0000000 --- a/JavaScriptCore/API/NodeList.c +++ /dev/null @@ -1,82 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "NodeList.h" - -#include - -extern NodeList* NodeList_new(Node* parentNode) -{ - Node_ref(parentNode); - - NodeList* nodeList = (NodeList*)malloc(sizeof(NodeList)); - nodeList->parentNode = parentNode; - nodeList->refCount = 0; - return nodeList; -} - -extern unsigned NodeList_length(NodeList* nodeList) -{ - // Linear count from tail -- good enough for our purposes here - unsigned i = 0; - NodeLink* n = nodeList->parentNode->childNodesTail; - while (n) { - n = n->prev; - ++i; - } - - return i; -} - -extern Node* NodeList_item(NodeList* nodeList, unsigned index) -{ - unsigned length = NodeList_length(nodeList); - if (index >= length) - return NULL; - - // Linear search from tail -- good enough for our purposes here - NodeLink* n = nodeList->parentNode->childNodesTail; - unsigned i = 0; - unsigned count = length - 1 - index; - while (i < count) { - ++i; - n = n->prev; - } - return n->node; -} - -extern void NodeList_ref(NodeList* nodeList) -{ - ++nodeList->refCount; -} - -extern void NodeList_deref(NodeList* nodeList) -{ - if (--nodeList->refCount == 0) { - Node_deref(nodeList->parentNode); - free(nodeList); - } -} diff --git a/JavaScriptCore/API/NodeList.h b/JavaScriptCore/API/NodeList.h deleted file mode 100644 index 289d206..0000000 --- a/JavaScriptCore/API/NodeList.h +++ /dev/null @@ -1,43 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef NodeList_h -#define NodeList_h - -#include "Node.h" - -typedef struct { - unsigned refCount; - Node* parentNode; -} NodeList; - -extern NodeList* NodeList_new(Node* parentNode); -extern unsigned NodeList_length(NodeList*); -extern Node* NodeList_item(NodeList*, unsigned); -extern void NodeList_ref(NodeList*); -extern void NodeList_deref(NodeList*); - -#endif // NodeList_h diff --git a/JavaScriptCore/API/OpaqueJSString.cpp b/JavaScriptCore/API/OpaqueJSString.cpp new file mode 100644 index 0000000..0819141 --- /dev/null +++ b/JavaScriptCore/API/OpaqueJSString.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "OpaqueJSString.h" + +#include +#include +#include + +using namespace JSC; + +PassRefPtr OpaqueJSString::create(const UString& ustring) +{ + if (!ustring.isNull()) + return adoptRef(new OpaqueJSString(ustring.data(), ustring.size())); + return 0; +} + +UString OpaqueJSString::ustring() const +{ + if (this && m_characters) + return UString(m_characters, m_length, true); + return UString::null(); +} + +Identifier OpaqueJSString::identifier(JSGlobalData* globalData) const +{ + if (!this || !m_characters) + return Identifier(globalData, static_cast(0)); + + return Identifier(globalData, m_characters, m_length); +} diff --git a/JavaScriptCore/API/OpaqueJSString.h b/JavaScriptCore/API/OpaqueJSString.h new file mode 100644 index 0000000..da05b06 --- /dev/null +++ b/JavaScriptCore/API/OpaqueJSString.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef OpaqueJSString_h +#define OpaqueJSString_h + +#include + +namespace JSC { + class Identifier; + class JSGlobalData; +} + +struct OpaqueJSString : public ThreadSafeShared { + + static PassRefPtr create() // null + { + return adoptRef(new OpaqueJSString); + } + + static PassRefPtr create(const UChar* characters, unsigned length) + { + return adoptRef(new OpaqueJSString(characters, length)); + } + + static PassRefPtr create(const JSC::UString&); + + UChar* characters() { return this ? m_characters : 0; } + unsigned length() { return this ? m_length : 0; } + + JSC::UString ustring() const; + JSC::Identifier identifier(JSC::JSGlobalData*) const; + +private: + friend class WTF::ThreadSafeShared; + + OpaqueJSString() + : m_characters(0) + , m_length(0) + { + } + + OpaqueJSString(const UChar* characters, unsigned length) + : m_length(length) + { + m_characters = new UChar[length]; + memcpy(m_characters, characters, length * sizeof(UChar)); + } + + ~OpaqueJSString() + { + delete[] m_characters; + } + + UChar* m_characters; + unsigned m_length; +}; + +#endif diff --git a/JavaScriptCore/API/WebKitAvailability.h b/JavaScriptCore/API/WebKitAvailability.h new file mode 100644 index 0000000..fae3904 --- /dev/null +++ b/JavaScriptCore/API/WebKitAvailability.h @@ -0,0 +1,761 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __WebKitAvailability__ +#define __WebKitAvailability__ + +/* The structure of this header is based on AvailabilityMacros.h. The major difference is that the availability + macros are defined in terms of WebKit version numbers rather than Mac OS X system version numbers, as WebKit + releases span multiple versions of Mac OS X. +*/ + +#define WEBKIT_VERSION_1_0 0x0100 +#define WEBKIT_VERSION_1_1 0x0110 +#define WEBKIT_VERSION_1_2 0x0120 +#define WEBKIT_VERSION_1_3 0x0130 +#define WEBKIT_VERSION_2_0 0x0200 +#define WEBKIT_VERSION_3_0 0x0300 +#define WEBKIT_VERSION_3_1 0x0310 +#define WEBKIT_VERSION_LATEST 0x9999 + +#ifdef __APPLE__ +#import +#else +// For non-Mac platforms, require the newest version. +#define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_LATEST +/* + * only certain compilers support __attribute__((deprecated)) + */ +#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) + #define DEPRECATED_ATTRIBUTE __attribute__((deprecated)) +#else + #define DEPRECATED_ATTRIBUTE +#endif +#endif + +/* The versions of GCC that shipped with Xcode prior to 3.0 (GCC build number < 5400) did not support attributes on methods. + If we are building with one of these versions, we need to omit the attribute. We achieve this by wrapping the annotation + in WEBKIT_OBJC_METHOD_ANNOTATION, which will remove the annotation when an old version of GCC is in use and will otherwise + expand to the annotation. The same is needed for protocol methods. +*/ +#if defined(__APPLE_CC__) && __APPLE_CC__ < 5400 + #define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) +#else + #define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION +#endif + + +/* If minimum WebKit version is not specified, assume the version that shipped with the target Mac OS X version */ +#ifndef WEBKIT_VERSION_MIN_REQUIRED + #if !defined(MAC_OS_X_VERSION_10_2) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_2 + #error WebKit was not available prior to Mac OS X 10.2 + #elif !defined(MAC_OS_X_VERSION_10_3) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3 + /* WebKit 1.0 is the only version available on Mac OS X 10.2. */ + #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_1_0 + #elif !defined(MAC_OS_X_VERSION_10_4) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4 + /* WebKit 1.1 is the version that shipped on Mac OS X 10.3. */ + #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_1_1 + #elif !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + /* WebKit 2.0 is the version that shipped on Mac OS X 10.4. */ + #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_2_0 + #elif !defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 + /* WebKit 3.0 is the version that shipped on Mac OS X 10.5. */ + #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_3_0 + #else + #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_LATEST + #endif +#endif + + +/* If maximum WebKit version is not specified, assume largerof(latest, minimum) */ +#ifndef WEBKIT_VERSION_MAX_ALLOWED + #if WEBKIT_VERSION_MIN_REQUIRED > WEBKIT_VERSION_LATEST + #define WEBKIT_VERSION_MAX_ALLOWED WEBKIT_VERSION_MIN_REQUIRED + #else + #define WEBKIT_VERSION_MAX_ALLOWED WEBKIT_VERSION_LATEST + #endif +#endif + + +/* Sanity check the configured values */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_MIN_REQUIRED + #error WEBKIT_VERSION_MAX_ALLOWED must be >= WEBKIT_VERSION_MIN_REQUIRED +#endif +#if WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_0 + #error WEBKIT_VERSION_MIN_REQUIRED must be >= WEBKIT_VERSION_1_0 +#endif + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER + * + * Used on functions introduced in WebKit 1.0 + */ +#define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED + * + * Used on functions introduced in WebKit 1.0, + * and deprecated in WebKit 1.0 + */ +#define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE + +/* + * DEPRECATED_IN_WEBKIT_VERSION_1_0_AND_LATER + * + * Used on types deprecated in WebKit 1.0 + */ +#define DEPRECATED_IN_WEBKIT_VERSION_1_0_AND_LATER DEPRECATED_ATTRIBUTE + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER + * + * Used on declarations introduced in WebKit 1.1 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_1_1 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_1 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED + * + * Used on declarations introduced in WebKit 1.1, + * and deprecated in WebKit 1.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_1 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_1 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated in WebKit 1.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_1 + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_1 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * DEPRECATED_IN_WEBKIT_VERSION_1_1_AND_LATER + * + * Used on types deprecated in WebKit 1.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_1 + #define DEPRECATED_IN_WEBKIT_VERSION_1_1_AND_LATER DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_IN_WEBKIT_VERSION_1_1_AND_LATER +#endif + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER + * + * Used on declarations introduced in WebKit 1.2 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_1_2 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_2 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED + * + * Used on declarations introduced in WebKit 1.2, + * and deprecated in WebKit 1.2 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated in WebKit 1.2 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2 + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 + * + * Used on declarations introduced in WebKit 1.1, + * but later deprecated in WebKit 1.2 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * DEPRECATED_IN_WEBKIT_VERSION_1_2_AND_LATER + * + * Used on types deprecated in WebKit 1.2 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2 + #define DEPRECATED_IN_WEBKIT_VERSION_1_2_AND_LATER DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_IN_WEBKIT_VERSION_1_2_AND_LATER +#endif + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER + * + * Used on declarations introduced in WebKit 1.3 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_1_3 + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_3 + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED + * + * Used on declarations introduced in WebKit 1.3, + * and deprecated in WebKit 1.3 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3 + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated in WebKit 1.3 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3 + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 + * + * Used on declarations introduced in WebKit 1.1, + * but later deprecated in WebKit 1.3 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 + * + * Used on declarations introduced in WebKit 1.2, + * but later deprecated in WebKit 1.3 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * DEPRECATED_IN_WEBKIT_VERSION_1_3_AND_LATER + * + * Used on types deprecated in WebKit 1.3 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3 + #define DEPRECATED_IN_WEBKIT_VERSION_1_3_AND_LATER DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_IN_WEBKIT_VERSION_1_3_AND_LATER +#endif + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER + * + * Used on declarations introduced in WebKit 2.0 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED + * + * Used on declarations introduced in WebKit 2.0, + * and deprecated in WebKit 2.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated in WebKit 2.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 + * + * Used on declarations introduced in WebKit 1.1, + * but later deprecated in WebKit 2.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 + * + * Used on declarations introduced in WebKit 1.2, + * but later deprecated in WebKit 2.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 + * + * Used on declarations introduced in WebKit 1.3, + * but later deprecated in WebKit 2.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0 + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER +#endif + +/* + * DEPRECATED_IN_WEBKIT_VERSION_2_0_AND_LATER + * + * Used on types deprecated in WebKit 2.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0 + #define DEPRECATED_IN_WEBKIT_VERSION_2_0_AND_LATER DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_IN_WEBKIT_VERSION_2_0_AND_LATER +#endif + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER + * + * Used on declarations introduced in WebKit 3.0 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED + * + * Used on declarations introduced in WebKit 3.0, + * and deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 + * + * Used on declarations introduced in WebKit 1.1, + * but later deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 + * + * Used on declarations introduced in WebKit 1.2, + * but later deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 + * + * Used on declarations introduced in WebKit 1.3, + * but later deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 + * + * Used on declarations introduced in WebKit 2.0, + * but later deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER +#endif + +/* + * DEPRECATED_IN_WEBKIT_VERSION_3_0_AND_LATER + * + * Used on types deprecated in WebKit 3.0 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0 + #define DEPRECATED_IN_WEBKIT_VERSION_3_0_AND_LATER DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_IN_WEBKIT_VERSION_3_0_AND_LATER +#endif + + + + + + +/* + * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER + * + * Used on declarations introduced in WebKit 3.1 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED + * + * Used on declarations introduced in WebKit 3.1, + * and deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.1, + * but later deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.2, + * but later deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.3, + * but later deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 2.0, + * but later deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 3.0, + * but later deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER +#endif + +/* + * DEPRECATED_IN_WEBKIT_VERSION_3_1_AND_LATER + * + * Used on types deprecated in WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1 + #define DEPRECATED_IN_WEBKIT_VERSION_3_1_AND_LATER DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_IN_WEBKIT_VERSION_3_1_AND_LATER +#endif + + + + + + +/* + * AVAILABLE_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced after WebKit 3.1 + */ +#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_LATEST + #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1 UNAVAILABLE_ATTRIBUTE +#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_LATEST + #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1 WEAK_IMPORT_ATTRIBUTE +#else + #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1 +#endif + +/* + * AVAILABLE_AFTER_WEBKIT_VERSION_3_1_BUT_DEPRECATED + * + * Used on declarations introduced after WebKit 3.1, + * and deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1_BUT_DEPRECATED DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1_BUT_DEPRECATED AVAILABLE_AFTER_WEBKIT_VERSION_3_1 +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.0, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.1, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.2, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 1.3, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 2.0, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 3.0, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER +#endif + +/* + * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on declarations introduced in WebKit 3.1, + * but later deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER +#endif + +/* + * DEPRECATED_AFTER_WEBKIT_VERSION_3_1 + * + * Used on types deprecated after WebKit 3.1 + */ +#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST + #define DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE +#else + #define DEPRECATED_AFTER_WEBKIT_VERSION_3_1 +#endif + + +#endif /* __WebKitAvailability__ */ diff --git a/JavaScriptCore/API/minidom.c b/JavaScriptCore/API/minidom.c deleted file mode 100644 index cfbaaa0..0000000 --- a/JavaScriptCore/API/minidom.c +++ /dev/null @@ -1,126 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2007 Alp Toker - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "JSContextRef.h" -#include "JSNode.h" -#include "JSObjectRef.h" -#include "JSStringRef.h" -#include -#include -#include -#include - -static char* createStringWithContentsOfFile(const char* fileName); -static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - -int main(int argc, char* argv[]) -{ - UNUSED_PARAM(argc); - UNUSED_PARAM(argv); - - JSGlobalContextRef context = JSGlobalContextCreate(NULL); - JSObjectRef globalObject = JSContextGetGlobalObject(context); - - JSStringRef printIString = JSStringCreateWithUTF8CString("print"); - JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunctionWithCallback(context, printIString, print), kJSPropertyAttributeNone, NULL); - JSStringRelease(printIString); - - JSStringRef node = JSStringCreateWithUTF8CString("Node"); - JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_class(context), JSNode_construct), kJSPropertyAttributeNone, NULL); - JSStringRelease(node); - - char* scriptUTF8 = createStringWithContentsOfFile("minidom.js"); - JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8); - JSValueRef exception; - JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 0, &exception); - if (result) - printf("PASS: Test script executed successfully.\n"); - else { - printf("FAIL: Test script threw exception:\n"); - JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL); - size_t exceptionUTF8Size = JSStringGetMaximumUTF8CStringSize(exceptionIString); - char* exceptionUTF8 = (char*)malloc(exceptionUTF8Size); - JSStringGetUTF8CString(exceptionIString, exceptionUTF8, exceptionUTF8Size); - printf("%s\n", exceptionUTF8); - free(exceptionUTF8); - JSStringRelease(exceptionIString); - } - JSStringRelease(script); - free(scriptUTF8); - - globalObject = 0; - JSGlobalContextRelease(context); - JSGarbageCollect(context); - printf("PASS: Program exited normally.\n"); - return 0; -} - -static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - UNUSED_PARAM(object); - UNUSED_PARAM(thisObject); - - if (argumentCount > 0) { - JSStringRef string = JSValueToStringCopy(context, arguments[0], exception); - size_t numChars = JSStringGetMaximumUTF8CStringSize(string); - char stringUTF8[numChars]; - JSStringGetUTF8CString(string, stringUTF8, numChars); - printf("%s\n", stringUTF8); - } - - return JSValueMakeUndefined(context); -} - -static char* createStringWithContentsOfFile(const char* fileName) -{ - char* buffer; - - size_t buffer_size = 0; - size_t buffer_capacity = 1024; - buffer = (char*)malloc(buffer_capacity); - - FILE* f = fopen(fileName, "r"); - if (!f) { - fprintf(stderr, "Could not open file: %s\n", fileName); - return 0; - } - - while (!feof(f) && !ferror(f)) { - buffer_size += fread(buffer + buffer_size, 1, buffer_capacity - buffer_size, f); - if (buffer_size == buffer_capacity) { // guarantees space for trailing '\0' - buffer_capacity *= 2; - buffer = (char*)realloc(buffer, buffer_capacity); - ASSERT(buffer); - } - - ASSERT(buffer_size < buffer_capacity); - } - fclose(f); - buffer[buffer_size] = '\0'; - - return buffer; -} diff --git a/JavaScriptCore/API/minidom.html b/JavaScriptCore/API/minidom.html deleted file mode 100644 index 7ea4747..0000000 --- a/JavaScriptCore/API/minidom.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -

-
-
diff --git a/JavaScriptCore/API/minidom.js b/JavaScriptCore/API/minidom.js
deleted file mode 100644
index 7624d39..0000000
--- a/JavaScriptCore/API/minidom.js
+++ /dev/null
@@ -1,111 +0,0 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
-/*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-function shouldBe(a, b)
-{
-    var evalA;
-    try {
-        evalA = eval(a);
-    } catch(e) {
-        evalA = e;
-    }
-    
-    if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
-        print("PASS: " + a + " should be " + b + " and is.", "green");
-    else
-        print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
-}
-
-function test()
-{
-    print("Node is " + Node);
-    for (var p in Node)
-        print(p + ": " + Node[p]);
-    
-    node = new Node();
-    print("node is " + node);
-    for (var p in node)
-        print(p + ": " + node[p]);
-
-    child1 = new Node();
-    child2 = new Node();
-    child3 = new Node();
-    
-    node.appendChild(child1);
-    node.appendChild(child2);
-
-    var childNodes = node.childNodes;
-    
-    for (var i = 0; i < childNodes.length + 1; i++) {
-        print("item " + i + ": " + childNodes.item(i));
-    }
-    
-    for (var i = 0; i < childNodes.length + 1; i++) {
-        print(i + ": " + childNodes[i]);
-    }
-
-    node.removeChild(child1);
-    node.replaceChild(child3, child2);
-    
-    for (var i = 0; i < childNodes.length + 1; i++) {
-        print("item " + i + ": " + childNodes.item(i));
-    }
-
-    for (var i = 0; i < childNodes.length + 1; i++) {
-        print(i + ": " + childNodes[i]);
-    }
-
-    try {
-        node.appendChild(null);
-    } catch(e) {
-        print("caught: " + e);
-    }
-    
-    try {
-        var o = new Object();
-        o.appendChild = node.appendChild;
-        o.appendChild(node);
-    } catch(e) {
-        print("caught: " + e);
-    }
-    
-    try {
-        node.appendChild();
-    } catch(e) {
-        print("caught: " + e);
-    }
-    
-    oldNodeType = node.nodeType;
-    node.nodeType = 1;
-    shouldBe("node.nodeType", oldNodeType);
-    
-    shouldBe("node instanceof Node", true);
-    shouldBe("new Object() instanceof Node", false);
-    
-    print(Node);
-}
-
-test();
diff --git a/JavaScriptCore/API/testapi.c b/JavaScriptCore/API/testapi.c
deleted file mode 100644
index 850aed8..0000000
--- a/JavaScriptCore/API/testapi.c
+++ /dev/null
@@ -1,942 +0,0 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
-/*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#include "JavaScriptCore.h"
-#include 
-#include 
-#include 
-
-static JSGlobalContextRef context = 0;
-
-static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
-{
-    if (JSValueToBoolean(context, value) != expectedValue)
-        fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue);
-}
-
-static void assertEqualsAsNumber(JSValueRef value, double expectedValue)
-{
-    double number = JSValueToNumber(context, value, NULL);
-
-    // FIXME  - On i386 the isnan(double) macro tries to map to the isnan(float) function,
-    // causing a build break with -Wshorten-64-to-32 enabled.  The issue is known by the appropriate team.
-    // After that's resolved, we can remove these casts
-    if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue)))
-        fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue);
-}
-
-static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
-{
-    JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
-
-    size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
-    char jsBuffer[jsSize];
-    JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
-    
-    unsigned i;
-    for (i = 0; jsBuffer[i]; i++)
-        if (jsBuffer[i] != expectedValue[i])
-            fprintf(stderr, "assertEqualsAsUTF8String failed at character %d: %c(%d) != %c(%d)\n", i, jsBuffer[i], jsBuffer[i], expectedValue[i], expectedValue[i]);
-        
-    if (jsSize < strlen(jsBuffer) + 1)
-        fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
-
-    JSStringRelease(valueAsString);
-}
-
-static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
-{
-    JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
-
-    size_t jsLength = JSStringGetLength(valueAsString);
-    const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
-
-    CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault, 
-                                                                    expectedValue,
-                                                                    kCFStringEncodingUTF8);    
-    CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
-    UniChar cfBuffer[cfLength];
-    CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
-    CFRelease(expectedValueAsCFString);
-
-    if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0)
-        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n");
-    
-    if (jsLength != (size_t)cfLength)
-        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
-    
-    JSStringRelease(valueAsString);
-}
-
-static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect()
-
-/* MyObject pseudo-class */
-
-static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-
-    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")
-        || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
-        || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")
-        || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")
-        || JSStringIsEqualToUTF8CString(propertyName, "0")) {
-        return true;
-    }
-    
-    return false;
-}
-
-static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-    
-    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
-        return JSValueMakeNumber(context, 1);
-    }
-    
-    if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
-        return JSValueMakeNumber(context, 1);
-    }
-
-    if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
-        return JSValueMakeUndefined(context);
-    }
-    
-    if (JSStringIsEqualToUTF8CString(propertyName, "0")) {
-        *exception = JSValueMakeNumber(context, 1);
-        return JSValueMakeNumber(context, 1);
-    }
-    
-    return NULL;
-}
-
-static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(value);
-    UNUSED_PARAM(exception);
-
-    if (JSStringIsEqualToUTF8CString(propertyName, "cantSet"))
-        return true; // pretend we set the property in order to swallow it
-    
-    return false;
-}
-
-static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-    
-    if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete"))
-        return true;
-    
-    if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) {
-        *exception = JSValueMakeNumber(context, 2);
-        return false;
-    }
-
-    return false;
-}
-
-static void MyObject_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-    
-    JSStringRef propertyName;
-    
-    propertyName = JSStringCreateWithUTF8CString("alwaysOne");
-    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
-    JSStringRelease(propertyName);
-    
-    propertyName = JSStringCreateWithUTF8CString("myPropertyName");
-    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
-    JSStringRelease(propertyName);
-}
-
-static JSValueRef MyObject_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(thisObject);
-    UNUSED_PARAM(exception);
-
-    if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
-        return JSValueMakeNumber(context, 1);
-    
-    return JSValueMakeUndefined(context);
-}
-
-static JSObjectRef MyObject_callAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(object);
-
-    if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
-        return JSValueToObject(context, JSValueMakeNumber(context, 1), exception);
-    
-    return JSValueToObject(context, JSValueMakeNumber(context, 0), exception);
-}
-
-static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
-{
-    UNUSED_PARAM(context);
-    UNUSED_PARAM(constructor);
-
-    JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
-    JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, exception), exception);
-    JSStringRelease(numberString);
-
-    return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, exception);
-}
-
-static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
-{
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(exception);
-    
-    switch (type) {
-    case kJSTypeNumber:
-        return JSValueMakeNumber(context, 1);
-    default:
-        break;
-    }
-
-    // string conversion -- forward to default object class
-    return NULL;
-}
-
-static JSStaticValue evilStaticValues[] = {
-    { "nullGetSet", 0, 0, kJSPropertyAttributeNone },
-    { 0, 0, 0, 0 }
-};
-
-static JSStaticFunction evilStaticFunctions[] = {
-    { "nullCall", 0, kJSPropertyAttributeNone },
-    { 0, 0, 0 }
-};
-
-JSClassDefinition MyObject_definition = {
-    0,
-    kJSClassAttributeNone,
-    
-    "MyObject",
-    NULL,
-    
-    evilStaticValues,
-    evilStaticFunctions,
-    
-    NULL,
-    NULL,
-    MyObject_hasProperty,
-    MyObject_getProperty,
-    MyObject_setProperty,
-    MyObject_deleteProperty,
-    MyObject_getPropertyNames,
-    MyObject_callAsFunction,
-    MyObject_callAsConstructor,
-    MyObject_hasInstance,
-    MyObject_convertToType,
-};
-
-static JSClassRef MyObject_class(JSContextRef context)
-{
-    UNUSED_PARAM(context);
-
-    static JSClassRef jsClass;
-    if (!jsClass)
-        jsClass = JSClassCreate(&MyObject_definition);
-    
-    return jsClass;
-}
-
-static JSValueRef Base_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-{
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(propertyName);
-    UNUSED_PARAM(exception);
-
-    return JSValueMakeNumber(ctx, 1); // distinguish base get form derived get
-}
-
-static bool Base_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
-{
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(propertyName);
-    UNUSED_PARAM(value);
-
-    *exception = JSValueMakeNumber(ctx, 1); // distinguish base set from derived set
-    return true;
-}
-
-static JSValueRef Base_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(function);
-    UNUSED_PARAM(thisObject);
-    UNUSED_PARAM(argumentCount);
-    UNUSED_PARAM(arguments);
-    UNUSED_PARAM(exception);
-    
-    return JSValueMakeNumber(ctx, 1); // distinguish base call from derived call
-}
-
-static JSStaticFunction Base_staticFunctions[] = {
-    { "baseProtoDup", NULL, kJSPropertyAttributeNone },
-    { "baseProto", Base_callAsFunction, kJSPropertyAttributeNone },
-    { 0, 0, 0 }
-};
-
-static JSStaticValue Base_staticValues[] = {
-    { "baseDup", Base_get, Base_set, kJSPropertyAttributeNone },
-    { "baseOnly", Base_get, Base_set, kJSPropertyAttributeNone },
-    { 0, 0, 0, 0 }
-};
-
-static bool TestInitializeFinalize;
-static void Base_initialize(JSContextRef context, JSObjectRef object)
-{
-    UNUSED_PARAM(context);
-
-    if (TestInitializeFinalize) {
-        ASSERT((void*)1 == JSObjectGetPrivate(object));
-        JSObjectSetPrivate(object, (void*)2);
-    }
-}
-
-static unsigned Base_didFinalize;
-static void Base_finalize(JSObjectRef object)
-{
-    UNUSED_PARAM(object);
-    if (TestInitializeFinalize) {
-        ASSERT((void*)4 == JSObjectGetPrivate(object));
-        Base_didFinalize = true;
-    }
-}
-
-static JSClassRef Base_class(JSContextRef context)
-{
-    UNUSED_PARAM(context);
-
-    static JSClassRef jsClass;
-    if (!jsClass) {
-        JSClassDefinition definition = kJSClassDefinitionEmpty;
-        definition.staticValues = Base_staticValues;
-        definition.staticFunctions = Base_staticFunctions;
-        definition.initialize = Base_initialize;
-        definition.finalize = Base_finalize;
-        jsClass = JSClassCreate(&definition);
-    }
-    return jsClass;
-}
-
-static JSValueRef Derived_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-{
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(propertyName);
-    UNUSED_PARAM(exception);
-
-    return JSValueMakeNumber(ctx, 2); // distinguish base get form derived get
-}
-
-static bool Derived_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
-{
-    UNUSED_PARAM(ctx);
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(propertyName);
-    UNUSED_PARAM(value);
-
-    *exception = JSValueMakeNumber(ctx, 2); // distinguish base set from derived set
-    return true;
-}
-
-static JSValueRef Derived_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(function);
-    UNUSED_PARAM(thisObject);
-    UNUSED_PARAM(argumentCount);
-    UNUSED_PARAM(arguments);
-    UNUSED_PARAM(exception);
-    
-    return JSValueMakeNumber(ctx, 2); // distinguish base call from derived call
-}
-
-static JSStaticFunction Derived_staticFunctions[] = {
-    { "protoOnly", Derived_callAsFunction, kJSPropertyAttributeNone },
-    { "protoDup", NULL, kJSPropertyAttributeNone },
-    { "baseProtoDup", Derived_callAsFunction, kJSPropertyAttributeNone },
-    { 0, 0, 0 }
-};
-
-static JSStaticValue Derived_staticValues[] = {
-    { "derivedOnly", Derived_get, Derived_set, kJSPropertyAttributeNone },
-    { "protoDup", Derived_get, Derived_set, kJSPropertyAttributeNone },
-    { "baseDup", Derived_get, Derived_set, kJSPropertyAttributeNone },
-    { 0, 0, 0, 0 }
-};
-
-static void Derived_initialize(JSContextRef context, JSObjectRef object)
-{
-    UNUSED_PARAM(context);
-
-    if (TestInitializeFinalize) {
-        ASSERT((void*)2 == JSObjectGetPrivate(object));
-        JSObjectSetPrivate(object, (void*)3);
-    }
-}
-
-static void Derived_finalize(JSObjectRef object)
-{
-    if (TestInitializeFinalize) {
-        ASSERT((void*)3 == JSObjectGetPrivate(object));
-        JSObjectSetPrivate(object, (void*)4);
-    }
-}
-
-static JSClassRef Derived_class(JSContextRef context)
-{
-    static JSClassRef jsClass;
-    if (!jsClass) {
-        JSClassDefinition definition = kJSClassDefinitionEmpty;
-        definition.parentClass = Base_class(context);
-        definition.staticValues = Derived_staticValues;
-        definition.staticFunctions = Derived_staticFunctions;
-        definition.initialize = Derived_initialize;
-        definition.finalize = Derived_finalize;
-        jsClass = JSClassCreate(&definition);
-    }
-    return jsClass;
-}
-
-static JSValueRef print_callAsFunction(JSContextRef context, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(functionObject);
-    UNUSED_PARAM(thisObject);
-    UNUSED_PARAM(exception);
-    
-    if (argumentCount > 0) {
-        JSStringRef string = JSValueToStringCopy(context, arguments[0], NULL);
-        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
-        char stringUTF8[sizeUTF8];
-        JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
-        printf("%s\n", stringUTF8);
-        JSStringRelease(string);
-    }
-    
-    return JSValueMakeUndefined(context);
-}
-
-static JSObjectRef myConstructor_callAsConstructor(JSContextRef context, JSObjectRef constructorObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(constructorObject);
-    UNUSED_PARAM(exception);
-    
-    JSObjectRef result = JSObjectMake(context, NULL, NULL);
-    if (argumentCount > 0) {
-        JSStringRef value = JSStringCreateWithUTF8CString("value");
-        JSObjectSetProperty(context, result, value, arguments[0], kJSPropertyAttributeNone, NULL);
-        JSStringRelease(value);
-    }
-    
-    return result;
-}
-
-
-static void globalObject_initialize(JSContextRef context, JSObjectRef object)
-{
-    UNUSED_PARAM(object);
-    // Ensure that an execution context is passed in
-    ASSERT(context);
-
-    // Ensure that the global object is set to the object that we were passed
-    JSObjectRef globalObject = JSContextGetGlobalObject(context);
-    ASSERT(globalObject);
-    ASSERT(object == globalObject);
-
-    // Ensure that the standard global properties have been set on the global object
-    JSStringRef array = JSStringCreateWithUTF8CString("Array");
-    JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
-    JSStringRelease(array);
-
-    UNUSED_PARAM(arrayConstructor);
-    ASSERT(arrayConstructor);
-}
-
-static JSValueRef globalObject_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-{
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(propertyName);
-    UNUSED_PARAM(exception);
-
-    return JSValueMakeNumber(ctx, 3);
-}
-
-static bool globalObject_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
-{
-    UNUSED_PARAM(object);
-    UNUSED_PARAM(propertyName);
-    UNUSED_PARAM(value);
-
-    *exception = JSValueMakeNumber(ctx, 3);
-    return true;
-}
-
-static JSValueRef globalObject_call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    UNUSED_PARAM(function);
-    UNUSED_PARAM(thisObject);
-    UNUSED_PARAM(argumentCount);
-    UNUSED_PARAM(arguments);
-    UNUSED_PARAM(exception);
-
-    return JSValueMakeNumber(ctx, 3);
-}
-
-static JSStaticValue globalObject_staticValues[] = {
-    { "globalStaticValue", globalObject_get, globalObject_set, kJSPropertyAttributeNone },
-    { 0, 0, 0, 0 }
-};
-
-static JSStaticFunction globalObject_staticFunctions[] = {
-    { "globalStaticFunction", globalObject_call, kJSPropertyAttributeNone },
-    { 0, 0, 0 }
-};
-
-static char* createStringWithContentsOfFile(const char* fileName);
-
-static void testInitializeFinalize()
-{
-    JSObjectRef o = JSObjectMake(context, Derived_class(context), (void*)1);
-    UNUSED_PARAM(o);
-    ASSERT(JSObjectGetPrivate(o) == (void*)3);
-}
-
-int main(int argc, char* argv[])
-{
-    UNUSED_PARAM(argc);
-    UNUSED_PARAM(argv);
-    
-    // Test garbage collection with a fresh context
-    context = JSGlobalContextCreate(NULL);
-    TestInitializeFinalize = true;
-    testInitializeFinalize();
-    JSGlobalContextRelease(context);
-    JSGarbageCollect(context);
-    TestInitializeFinalize = false;
-
-    ASSERT(Base_didFinalize);
-
-    JSClassDefinition globalObjectClassDefinition = kJSClassDefinitionEmpty;
-    globalObjectClassDefinition.initialize = globalObject_initialize;
-    globalObjectClassDefinition.staticValues = globalObject_staticValues;
-    globalObjectClassDefinition.staticFunctions = globalObject_staticFunctions;
-    globalObjectClassDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
-    JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition);
-    context = JSGlobalContextCreate(globalObjectClass);
-    
-    JSObjectRef globalObject = JSContextGetGlobalObject(context);
-    ASSERT(JSValueIsObject(context, globalObject));
-    
-    JSValueRef jsUndefined = JSValueMakeUndefined(context);
-    JSValueRef jsNull = JSValueMakeNull(context);
-    JSValueRef jsTrue = JSValueMakeBoolean(context, true);
-    JSValueRef jsFalse = JSValueMakeBoolean(context, false);
-    JSValueRef jsZero = JSValueMakeNumber(context, 0);
-    JSValueRef jsOne = JSValueMakeNumber(context, 1);
-    JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
-    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL);
-    JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context));
-
-    // FIXME: test funny utf8 characters
-    JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
-    JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString);
-    
-    JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
-    JSValueRef jsOneString = JSValueMakeString(context, jsOneIString);
-
-    UniChar singleUniChar = 65; // Capital A
-    CFMutableStringRef cfString = 
-        CFStringCreateMutableWithExternalCharactersNoCopy(kCFAllocatorDefault,
-                                                          &singleUniChar,
-                                                          1,
-                                                          1,
-                                                          kCFAllocatorNull);
-
-    JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
-    JSValueRef jsCFString = JSValueMakeString(context, jsCFIString);
-    
-    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
-    
-    JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
-    JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);
-
-    CFIndex cfStringLength = CFStringGetLength(cfString);
-    UniChar buffer[cfStringLength];
-    CFStringGetCharacters(cfString, 
-                          CFRangeMake(0, cfStringLength), 
-                          buffer);
-    JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
-    JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
-    
-    JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
-    JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
-
-    ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
-    ASSERT(JSValueGetType(context, jsNull) == kJSTypeNull);
-    ASSERT(JSValueGetType(context, jsTrue) == kJSTypeBoolean);
-    ASSERT(JSValueGetType(context, jsFalse) == kJSTypeBoolean);
-    ASSERT(JSValueGetType(context, jsZero) == kJSTypeNumber);
-    ASSERT(JSValueGetType(context, jsOne) == kJSTypeNumber);
-    ASSERT(JSValueGetType(context, jsOneThird) == kJSTypeNumber);
-    ASSERT(JSValueGetType(context, jsEmptyString) == kJSTypeString);
-    ASSERT(JSValueGetType(context, jsOneString) == kJSTypeString);
-    ASSERT(JSValueGetType(context, jsCFString) == kJSTypeString);
-    ASSERT(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString);
-    ASSERT(JSValueGetType(context, jsCFEmptyString) == kJSTypeString);
-    ASSERT(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString);
-
-    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
-    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
-    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL);
-    JSStringRelease(myObjectIString);
-    
-    JSValueRef exception;
-
-    // Conversions that throw exceptions
-    exception = NULL;
-    ASSERT(NULL == JSValueToObject(context, jsNull, &exception));
-    ASSERT(exception);
-    
-    exception = NULL;
-    // FIXME  - On i386 the isnan(double) macro tries to map to the isnan(float) function,
-    // causing a build break with -Wshorten-64-to-32 enabled.  The issue is known by the appropriate team.
-    // After that's resolved, we can remove these casts
-    ASSERT(isnan((float)JSValueToNumber(context, jsObjectNoProto, &exception)));
-    ASSERT(exception);
-
-    exception = NULL;
-    ASSERT(!JSValueToStringCopy(context, jsObjectNoProto, &exception));
-    ASSERT(exception);
-    
-    ASSERT(JSValueToBoolean(context, myObject));
-    
-    exception = NULL;
-    ASSERT(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(context, 1), &exception));
-    ASSERT(exception);
-    
-    exception = NULL;
-    JSObjectGetPropertyAtIndex(context, myObject, 0, &exception);
-    ASSERT(1 == JSValueToNumber(context, exception, NULL));
-
-    assertEqualsAsBoolean(jsUndefined, false);
-    assertEqualsAsBoolean(jsNull, false);
-    assertEqualsAsBoolean(jsTrue, true);
-    assertEqualsAsBoolean(jsFalse, false);
-    assertEqualsAsBoolean(jsZero, false);
-    assertEqualsAsBoolean(jsOne, true);
-    assertEqualsAsBoolean(jsOneThird, true);
-    assertEqualsAsBoolean(jsEmptyString, false);
-    assertEqualsAsBoolean(jsOneString, true);
-    assertEqualsAsBoolean(jsCFString, true);
-    assertEqualsAsBoolean(jsCFStringWithCharacters, true);
-    assertEqualsAsBoolean(jsCFEmptyString, false);
-    assertEqualsAsBoolean(jsCFEmptyStringWithCharacters, false);
-    
-    assertEqualsAsNumber(jsUndefined, nan(""));
-    assertEqualsAsNumber(jsNull, 0);
-    assertEqualsAsNumber(jsTrue, 1);
-    assertEqualsAsNumber(jsFalse, 0);
-    assertEqualsAsNumber(jsZero, 0);
-    assertEqualsAsNumber(jsOne, 1);
-    assertEqualsAsNumber(jsOneThird, 1.0 / 3.0);
-    assertEqualsAsNumber(jsEmptyString, 0);
-    assertEqualsAsNumber(jsOneString, 1);
-    assertEqualsAsNumber(jsCFString, nan(""));
-    assertEqualsAsNumber(jsCFStringWithCharacters, nan(""));
-    assertEqualsAsNumber(jsCFEmptyString, 0);
-    assertEqualsAsNumber(jsCFEmptyStringWithCharacters, 0);
-    ASSERT(sizeof(JSChar) == sizeof(UniChar));
-    
-    assertEqualsAsCharactersPtr(jsUndefined, "undefined");
-    assertEqualsAsCharactersPtr(jsNull, "null");
-    assertEqualsAsCharactersPtr(jsTrue, "true");
-    assertEqualsAsCharactersPtr(jsFalse, "false");
-    assertEqualsAsCharactersPtr(jsZero, "0");
-    assertEqualsAsCharactersPtr(jsOne, "1");
-    assertEqualsAsCharactersPtr(jsOneThird, "0.3333333333333333");
-    assertEqualsAsCharactersPtr(jsEmptyString, "");
-    assertEqualsAsCharactersPtr(jsOneString, "1");
-    assertEqualsAsCharactersPtr(jsCFString, "A");
-    assertEqualsAsCharactersPtr(jsCFStringWithCharacters, "A");
-    assertEqualsAsCharactersPtr(jsCFEmptyString, "");
-    assertEqualsAsCharactersPtr(jsCFEmptyStringWithCharacters, "");
-    
-    assertEqualsAsUTF8String(jsUndefined, "undefined");
-    assertEqualsAsUTF8String(jsNull, "null");
-    assertEqualsAsUTF8String(jsTrue, "true");
-    assertEqualsAsUTF8String(jsFalse, "false");
-    assertEqualsAsUTF8String(jsZero, "0");
-    assertEqualsAsUTF8String(jsOne, "1");
-    assertEqualsAsUTF8String(jsOneThird, "0.3333333333333333");
-    assertEqualsAsUTF8String(jsEmptyString, "");
-    assertEqualsAsUTF8String(jsOneString, "1");
-    assertEqualsAsUTF8String(jsCFString, "A");
-    assertEqualsAsUTF8String(jsCFStringWithCharacters, "A");
-    assertEqualsAsUTF8String(jsCFEmptyString, "");
-    assertEqualsAsUTF8String(jsCFEmptyStringWithCharacters, "");
-    
-    ASSERT(JSValueIsStrictEqual(context, jsTrue, jsTrue));
-    ASSERT(!JSValueIsStrictEqual(context, jsOne, jsOneString));
-
-    ASSERT(JSValueIsEqual(context, jsOne, jsOneString, NULL));
-    ASSERT(!JSValueIsEqual(context, jsTrue, jsFalse, NULL));
-    
-    CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString);
-    CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString);
-    ASSERT(CFEqual(cfJSString, cfString));
-    ASSERT(CFEqual(cfJSEmptyString, cfEmptyString));
-    CFRelease(cfJSString);
-    CFRelease(cfJSEmptyString);
-
-    CFRelease(cfString);
-    CFRelease(cfEmptyString);
-    
-    jsGlobalValue = JSObjectMake(context, NULL, NULL);
-    JSValueProtect(context, jsGlobalValue);
-    JSGarbageCollect(context);
-    ASSERT(JSValueIsObject(context, jsGlobalValue));
-    JSValueUnprotect(context, jsGlobalValue);
-
-    JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
-    JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
-    ASSERT(JSCheckScriptSyntax(context, goodSyntax, NULL, 0, NULL));
-    ASSERT(!JSCheckScriptSyntax(context, badSyntax, NULL, 0, NULL));
-
-    JSValueRef result;
-    JSValueRef v;
-    JSObjectRef o;
-    JSStringRef string;
-
-    result = JSEvaluateScript(context, goodSyntax, NULL, NULL, 1, NULL);
-    ASSERT(result);
-    ASSERT(JSValueIsEqual(context, result, jsOne, NULL));
-
-    exception = NULL;
-    result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception);
-    ASSERT(!result);
-    ASSERT(JSValueIsObject(context, exception));
-    
-    JSStringRef array = JSStringCreateWithUTF8CString("Array");
-    JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
-    JSStringRelease(array);
-    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
-    ASSERT(result);
-    ASSERT(JSValueIsObject(context, result));
-    ASSERT(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
-    ASSERT(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(context), arrayConstructor, NULL));
-
-    o = JSValueToObject(context, result, NULL);
-    exception = NULL;
-    ASSERT(JSValueIsUndefined(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
-    ASSERT(!exception);
-    
-    JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(context, 1), &exception);
-    ASSERT(!exception);
-    
-    exception = NULL;
-    ASSERT(1 == JSValueToNumber(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception), &exception));
-    ASSERT(!exception);
-
-    JSStringRef functionBody;
-    JSObjectRef function;
-    
-    exception = NULL;
-    functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
-    JSStringRef line = JSStringCreateWithUTF8CString("line");
-    ASSERT(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception));
-    ASSERT(JSValueIsObject(context, exception));
-    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
-    assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact)
-    JSStringRelease(functionBody);
-    JSStringRelease(line);
-
-    exception = NULL;
-    functionBody = JSStringCreateWithUTF8CString("return Array;");
-    function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception);
-    JSStringRelease(functionBody);
-    ASSERT(!exception);
-    ASSERT(JSObjectIsFunction(context, function));
-    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
-    ASSERT(v);
-    ASSERT(JSValueIsEqual(context, v, arrayConstructor, NULL));
-    
-    exception = NULL;
-    function = JSObjectMakeFunction(context, NULL, 0, NULL, jsEmptyIString, NULL, 0, &exception);
-    ASSERT(!exception);
-    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, &exception);
-    ASSERT(v && !exception);
-    ASSERT(JSValueIsUndefined(context, v));
-    
-    exception = NULL;
-    v = NULL;
-    JSStringRef foo = JSStringCreateWithUTF8CString("foo");
-    JSStringRef argumentNames[] = { foo };
-    functionBody = JSStringCreateWithUTF8CString("return foo;");
-    function = JSObjectMakeFunction(context, foo, 1, argumentNames, functionBody, NULL, 1, &exception);
-    ASSERT(function && !exception);
-    JSValueRef arguments[] = { JSValueMakeNumber(context, 2) };
-    v = JSObjectCallAsFunction(context, function, NULL, 1, arguments, &exception);
-    JSStringRelease(foo);
-    JSStringRelease(functionBody);
-    
-    string = JSValueToStringCopy(context, function, NULL);
-    assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) \n{\n  return foo;\n}");
-    JSStringRelease(string);
-
-    JSStringRef print = JSStringCreateWithUTF8CString("print");
-    JSObjectRef printFunction = JSObjectMakeFunctionWithCallback(context, print, print_callAsFunction);
-    JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone, NULL); 
-    JSStringRelease(print);
-    
-    ASSERT(!JSObjectSetPrivate(printFunction, (void*)1));
-    ASSERT(!JSObjectGetPrivate(printFunction));
-
-    JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
-    JSObjectRef myConstructor = JSObjectMakeConstructor(context, NULL, myConstructor_callAsConstructor);
-    JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone, NULL);
-    JSStringRelease(myConstructorIString);
-    
-    ASSERT(!JSObjectSetPrivate(myConstructor, (void*)1));
-    ASSERT(!JSObjectGetPrivate(myConstructor));
-    
-    string = JSStringCreateWithUTF8CString("Derived");
-    JSObjectRef derivedConstructor = JSObjectMakeConstructor(context, Derived_class(context), NULL);
-    JSObjectSetProperty(context, globalObject, string, derivedConstructor, kJSPropertyAttributeNone, NULL);
-    JSStringRelease(string);
-    
-    o = JSObjectMake(context, NULL, NULL);
-    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
-    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL);
-    JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o);
-    size_t expectedCount = JSPropertyNameArrayGetCount(nameArray);
-    size_t count;
-    for (count = 0; count < expectedCount; ++count)
-        JSPropertyNameArrayGetNameAtIndex(nameArray, count);
-    JSPropertyNameArrayRelease(nameArray);
-    ASSERT(count == 1); // jsCFString should not be enumerated
-
-    JSClassDefinition nullDefinition = kJSClassDefinitionEmpty;
-    nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
-    JSClassRef nullClass = JSClassCreate(&nullDefinition);
-    JSClassRelease(nullClass);
-    
-    nullDefinition = kJSClassDefinitionEmpty;
-    nullClass = JSClassCreate(&nullDefinition);
-    JSClassRelease(nullClass);
-
-    functionBody = JSStringCreateWithUTF8CString("return this;");
-    function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL);
-    JSStringRelease(functionBody);
-    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
-    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
-    v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
-    ASSERT(JSValueIsEqual(context, v, o, NULL));
-    
-    char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
-    if (!scriptUTF8)
-        printf("FAIL: Test script could not be loaded.\n");
-    else {
-        JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
-        result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
-        if (JSValueIsUndefined(context, result))
-            printf("PASS: Test script executed successfully.\n");
-        else {
-            printf("FAIL: Test script returned unexpected value:\n");
-            JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
-            CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
-            CFShow(exceptionCF);
-            CFRelease(exceptionCF);
-            JSStringRelease(exceptionIString);
-        }
-        JSStringRelease(script);
-        free(scriptUTF8);
-    }
-
-    // Clear out local variables pointing at JSObjectRefs to allow their values to be collected
-    function = NULL;
-    v = NULL;
-    o = NULL;
-    globalObject = NULL;
-
-    JSStringRelease(jsEmptyIString);
-    JSStringRelease(jsOneIString);
-    JSStringRelease(jsCFIString);
-    JSStringRelease(jsCFEmptyIString);
-    JSStringRelease(jsCFIStringWithCharacters);
-    JSStringRelease(jsCFEmptyIStringWithCharacters);
-    JSStringRelease(goodSyntax);
-    JSStringRelease(badSyntax);
-
-    JSGlobalContextRelease(context);
-    JSGarbageCollect(context);
-    JSClassRelease(globalObjectClass);
-
-    printf("PASS: Program exited normally.\n");
-    return 0;
-}
-
-static char* createStringWithContentsOfFile(const char* fileName)
-{
-    char* buffer;
-    
-    size_t buffer_size = 0;
-    size_t buffer_capacity = 1024;
-    buffer = (char*)malloc(buffer_capacity);
-    
-    FILE* f = fopen(fileName, "r");
-    if (!f) {
-        fprintf(stderr, "Could not open file: %s\n", fileName);
-        return 0;
-    }
-    
-    while (!feof(f) && !ferror(f)) {
-        buffer_size += fread(buffer + buffer_size, 1, buffer_capacity - buffer_size, f);
-        if (buffer_size == buffer_capacity) { // guarantees space for trailing '\0'
-            buffer_capacity *= 2;
-            buffer = (char*)realloc(buffer, buffer_capacity);
-            ASSERT(buffer);
-        }
-        
-        ASSERT(buffer_size < buffer_capacity);
-    }
-    fclose(f);
-    buffer[buffer_size] = '\0';
-    
-    return buffer;
-}
diff --git a/JavaScriptCore/API/testapi.js b/JavaScriptCore/API/testapi.js
deleted file mode 100644
index 52bcb71..0000000
--- a/JavaScriptCore/API/testapi.js
+++ /dev/null
@@ -1,132 +0,0 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
-/*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-function shouldBe(a, b)
-{
-    var evalA;
-    try {
-        evalA = eval(a);
-    } catch(e) {
-        evalA = e;
-    }
-    
-    if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
-        print("PASS: " + a + " should be " + b + " and is.", "green");
-    else
-        print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
-}
-
-function shouldThrow(a)
-{
-    var result = "__FAIL__: " + a + " did not throw an exception.";
-    
-    var evalA;
-    try {
-        eval(a);
-    } catch(e) {
-        result = "PASS: " + a + " threw: " + e;
-    }
-    
-    print(result);
-}
-
-function globalStaticFunction()
-{
-    return 4;
-}
-
-shouldBe("globalStaticValue", 3);
-shouldBe("globalStaticFunction()", 4);
-
-shouldBe("typeof MyObject", "function"); // our object implements 'call'
-MyObject.cantFind = 1;
-shouldBe("MyObject.cantFind", undefined);
-MyObject.regularType = 1;
-shouldBe("MyObject.regularType", 1);
-MyObject.alwaysOne = 2;
-shouldBe("MyObject.alwaysOne", 1);
-MyObject.cantDelete = 1;
-delete MyObject.cantDelete;
-shouldBe("MyObject.cantDelete", 1);
-shouldBe("delete MyObject.throwOnDelete", 2); // deleteProperty -- should throw 2
-MyObject.cantSet = 1;
-shouldBe("MyObject.cantSet", undefined);
-
-var foundMyPropertyName = false;
-var foundRegularType = false;
-for (var p in MyObject) {
-    if (p == "myPropertyName")
-        foundMyPropertyName = true;
-    if (p == "regularType")
-        foundRegularType = true;
-}
-print(foundMyPropertyName
-      ? "PASS: MyObject.myPropertyName was enumerated"
-      : "__FAIL__: MyObject.myPropertyName was not enumerated");
-print(foundRegularType
-      ? "PASS: MyObject.regularType was enumerated"
-      : "__FAIL__: MyObject.regularType was not enumerated");
-
-myObject = new MyObject();
-
-shouldBe("delete MyObject.regularType", true);
-shouldBe("MyObject.regularType", undefined);
-shouldBe("MyObject(0)", 1);
-shouldBe("MyObject()", undefined);
-shouldBe("typeof myObject", "object");
-shouldBe("MyObject ? 1 : 0", true); // toBoolean
-shouldBe("+MyObject", 1); // toNumber
-shouldBe("(MyObject.toString())", "[object MyObject]"); // toString
-shouldBe("MyObject - 0", NaN); // toPrimitive
-
-shouldBe("typeof MyConstructor", "object");
-constructedObject = new MyConstructor(1);
-shouldBe("typeof constructedObject", "object");
-shouldBe("constructedObject.value", 1);
-shouldBe("myObject instanceof MyObject", true);
-shouldBe("(new Object()) instanceof MyObject", false);
-
-shouldThrow("MyObject.nullGetSet = 1");
-shouldThrow("MyObject.nullGetSet");
-shouldThrow("MyObject.nullCall()");
-shouldThrow("MyObject.hasPropertyLie");
-
-derived = new Derived();
-
-// base properties and functions return 1 when called/gotten; derived, 2
-shouldBe("derived.baseProtoDup()", 2);
-shouldBe("derived.baseProto()", 1);
-shouldBe("derived.baseDup", 2);
-shouldBe("derived.baseOnly", 1);
-shouldBe("derived.protoOnly()", 2);
-shouldBe("derived.protoDup", 2);
-shouldBe("derived.derivedOnly", 2)
-
-// base properties throw 1 when set; derived, 2
-shouldBe("derived.baseDup = 0", 2);
-shouldBe("derived.baseOnly = 0", 1);
-shouldBe("derived.derivedOnly = 0", 2)
-shouldBe("derived.protoDup = 0", 2);
diff --git a/JavaScriptCore/API/tests/JSNode.c b/JavaScriptCore/API/tests/JSNode.c
new file mode 100644
index 0000000..d9ac0a9
--- /dev/null
+++ b/JavaScriptCore/API/tests/JSNode.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "JSNode.h"
+#include "JSNodeList.h"
+#include "JSObjectRef.h"
+#include "JSStringRef.h"
+#include "JSValueRef.h"
+#include "Node.h"
+#include "NodeList.h"
+#include "UnusedParam.h"
+#include 
+
+static JSValueRef JSNode_appendChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(function);
+
+    /* Example of throwing a type error for invalid values */
+    if (!JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes");
+        *exception = JSValueMakeString(context, message);
+        JSStringRelease(message);
+    } else if (argumentCount < 1 || !JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node");
+        *exception = JSValueMakeString(context, message);
+        JSStringRelease(message);
+    } else {
+        Node* node = JSObjectGetPrivate(thisObject);
+        Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], NULL));
+
+        Node_appendChild(node, child);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+static JSValueRef JSNode_removeChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(function);
+
+    /* Example of ignoring invalid values */
+    if (argumentCount > 0) {
+        if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+            if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+                Node* node = JSObjectGetPrivate(thisObject);
+                Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception));
+                
+                Node_removeChild(node, child);
+            }
+        }
+    }
+    
+    return JSValueMakeUndefined(context);
+}
+
+static JSValueRef JSNode_replaceChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(function);
+    
+    if (argumentCount > 1) {
+        if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+            if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+                if (JSValueIsObjectOfClass(context, arguments[1], JSNode_class(context))) {
+                    Node* node = JSObjectGetPrivate(thisObject);
+                    Node* newChild = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception));
+                    Node* oldChild = JSObjectGetPrivate(JSValueToObject(context, arguments[1], exception));
+                    
+                    Node_replaceChild(node, newChild, oldChild);
+                }
+            }
+        }
+    }
+    
+    return JSValueMakeUndefined(context);
+}
+
+static JSStaticFunction JSNode_staticFunctions[] = {
+    { "appendChild", JSNode_appendChild, kJSPropertyAttributeDontDelete },
+    { "removeChild", JSNode_removeChild, kJSPropertyAttributeDontDelete },
+    { "replaceChild", JSNode_replaceChild, kJSPropertyAttributeDontDelete },
+    { 0, 0, 0 }
+};
+
+static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+
+    Node* node = JSObjectGetPrivate(object);
+    if (node) {
+        JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
+        JSValueRef value = JSValueMakeString(context, nodeType);
+        JSStringRelease(nodeType);
+        return value;
+    }
+    
+    return NULL;
+}
+
+static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+
+    Node* node = JSObjectGetPrivate(thisObject);
+    ASSERT(node);
+    return JSNodeList_new(context, NodeList_new(node));
+}
+
+static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+    
+    return JSValueMakeUndefined(context);
+}
+
+static JSStaticValue JSNode_staticValues[] = {
+    { "nodeType", JSNode_getNodeType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+    { "childNodes", JSNode_getChildNodes, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+    { "firstChild", JSNode_getFirstChild, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+static void JSNode_initialize(JSContextRef context, JSObjectRef object)
+{
+    UNUSED_PARAM(context);
+
+    Node* node = JSObjectGetPrivate(object);
+    ASSERT(node);
+
+    Node_ref(node);
+}
+
+static void JSNode_finalize(JSObjectRef object)
+{
+    Node* node = JSObjectGetPrivate(object);
+    ASSERT(node);
+
+    Node_deref(node);
+}
+
+JSClassRef JSNode_class(JSContextRef context)
+{
+    UNUSED_PARAM(context);
+
+    static JSClassRef jsClass;
+    if (!jsClass) {
+        JSClassDefinition definition = kJSClassDefinitionEmpty;
+        definition.staticValues = JSNode_staticValues;
+        definition.staticFunctions = JSNode_staticFunctions;
+        definition.initialize = JSNode_initialize;
+        definition.finalize = JSNode_finalize;
+
+        jsClass = JSClassCreate(&definition);
+    }
+    return jsClass;
+}
+
+JSObjectRef JSNode_new(JSContextRef context, Node* node)
+{
+    return JSObjectMake(context, JSNode_class(context), node);
+}
+
+JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(argumentCount);
+    UNUSED_PARAM(arguments);
+    UNUSED_PARAM(exception);
+
+    return JSNode_new(context, Node_new());
+}
diff --git a/JavaScriptCore/API/tests/JSNode.h b/JavaScriptCore/API/tests/JSNode.h
new file mode 100644
index 0000000..7725733
--- /dev/null
+++ b/JavaScriptCore/API/tests/JSNode.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef JSNode_h
+#define JSNode_h
+
+#include "JSBase.h"
+#include "Node.h"
+#include 
+
+extern JSObjectRef JSNode_new(JSContextRef context, Node* node);
+extern JSClassRef JSNode_class(JSContextRef context);
+extern JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+#endif /* JSNode_h */
diff --git a/JavaScriptCore/API/tests/JSNodeList.c b/JavaScriptCore/API/tests/JSNodeList.c
new file mode 100644
index 0000000..bc4a8ad
--- /dev/null
+++ b/JavaScriptCore/API/tests/JSNodeList.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "JSNode.h"
+#include "JSNodeList.h"
+#include "JSObjectRef.h"
+#include "JSValueRef.h"
+#include "UnusedParam.h"
+#include 
+
+static JSValueRef JSNodeList_item(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+
+    if (argumentCount > 0) {
+        NodeList* nodeList = JSObjectGetPrivate(thisObject);
+        ASSERT(nodeList);
+        Node* node = NodeList_item(nodeList, (unsigned)JSValueToNumber(context, arguments[0], exception));
+        if (node)
+            return JSNode_new(context, node);
+    }
+    
+    return JSValueMakeUndefined(context);
+}
+
+static JSStaticFunction JSNodeList_staticFunctions[] = {
+    { "item", JSNodeList_item, kJSPropertyAttributeDontDelete },
+    { 0, 0, 0 }
+};
+
+static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+    
+    NodeList* nodeList = JSObjectGetPrivate(thisObject);
+    ASSERT(nodeList);
+    return JSValueMakeNumber(context, NodeList_length(nodeList));
+}
+
+static JSStaticValue JSNodeList_staticValues[] = {
+    { "length", JSNodeList_length, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
+};
+
+static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+    NodeList* nodeList = JSObjectGetPrivate(thisObject);
+    ASSERT(nodeList);
+    double index = JSValueToNumber(context, JSValueMakeString(context, propertyName), exception);
+    unsigned uindex = (unsigned)index;
+    if (uindex == index) { /* false for NaN */
+        Node* node = NodeList_item(nodeList, uindex);
+        if (node)
+            return JSNode_new(context, node);
+    }
+    
+    return NULL;
+}
+
+static void JSNodeList_initialize(JSContextRef context, JSObjectRef thisObject)
+{
+    UNUSED_PARAM(context);
+
+    NodeList* nodeList = JSObjectGetPrivate(thisObject);
+    ASSERT(nodeList);
+    
+    NodeList_ref(nodeList);
+}
+
+static void JSNodeList_finalize(JSObjectRef thisObject)
+{
+    NodeList* nodeList = JSObjectGetPrivate(thisObject);
+    ASSERT(nodeList);
+
+    NodeList_deref(nodeList);
+}
+
+static JSClassRef JSNodeList_class(JSContextRef context)
+{
+    UNUSED_PARAM(context);
+
+    static JSClassRef jsClass;
+    if (!jsClass) {
+        JSClassDefinition definition = kJSClassDefinitionEmpty;
+        definition.staticValues = JSNodeList_staticValues;
+        definition.staticFunctions = JSNodeList_staticFunctions;
+        definition.getProperty = JSNodeList_getProperty;
+        definition.initialize = JSNodeList_initialize;
+        definition.finalize = JSNodeList_finalize;
+
+        jsClass = JSClassCreate(&definition);
+    }
+    
+    return jsClass;
+}
+
+JSObjectRef JSNodeList_new(JSContextRef context, NodeList* nodeList)
+{
+    return JSObjectMake(context, JSNodeList_class(context), nodeList);
+}
diff --git a/JavaScriptCore/API/tests/JSNodeList.h b/JavaScriptCore/API/tests/JSNodeList.h
new file mode 100644
index 0000000..f930914
--- /dev/null
+++ b/JavaScriptCore/API/tests/JSNodeList.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef JSNodeList_h
+#define JSNodeList_h
+
+#include "JSBase.h"
+#include "NodeList.h"
+
+extern JSObjectRef JSNodeList_new(JSContextRef, NodeList*);
+
+#endif /* JSNodeList_h */
diff --git a/JavaScriptCore/API/tests/Node.c b/JavaScriptCore/API/tests/Node.c
new file mode 100644
index 0000000..913da0a
--- /dev/null
+++ b/JavaScriptCore/API/tests/Node.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "Node.h"
+#include 
+#include 
+
+Node* Node_new(void)
+{
+    Node* node = (Node*)malloc(sizeof(Node));
+    node->refCount = 0;
+    node->nodeType = "Node";
+    node->childNodesTail = NULL;
+    
+    return node;
+}
+
+void Node_appendChild(Node* node, Node* child)
+{
+    Node_ref(child);
+    NodeLink* nodeLink = (NodeLink*)malloc(sizeof(NodeLink));
+    nodeLink->node = child;
+    nodeLink->prev = node->childNodesTail;
+    node->childNodesTail = nodeLink;
+}
+
+void Node_removeChild(Node* node, Node* child)
+{
+    /* Linear search from tail -- good enough for our purposes here */
+    NodeLink* current;
+    NodeLink** currentHandle;
+    for (currentHandle = &node->childNodesTail, current = *currentHandle; current; currentHandle = ¤t->prev, current = *currentHandle) {
+        if (current->node == child) {
+            Node_deref(current->node);
+            *currentHandle = current->prev;
+            free(current);
+            break;
+        }
+    }
+}
+
+void Node_replaceChild(Node* node, Node* newChild, Node* oldChild)
+{
+    /* Linear search from tail -- good enough for our purposes here */
+    NodeLink* current;
+    for (current = node->childNodesTail; current; current = current->prev) {
+        if (current->node == oldChild) {
+            Node_deref(current->node);
+            current->node = newChild;
+        }
+    }
+}
+
+void Node_ref(Node* node)
+{
+    ++node->refCount;
+}
+
+void Node_deref(Node* node)
+{
+    if (--node->refCount == 0)
+        free(node);
+}
diff --git a/JavaScriptCore/API/tests/Node.h b/JavaScriptCore/API/tests/Node.h
new file mode 100644
index 0000000..e9250b3
--- /dev/null
+++ b/JavaScriptCore/API/tests/Node.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef Node_h
+#define Node_h
+
+typedef struct __Node Node;
+typedef struct __NodeLink NodeLink;
+
+struct __NodeLink {
+    Node* node;
+    NodeLink* prev;
+};
+
+struct __Node {
+    unsigned refCount;
+    const char* nodeType;
+    NodeLink* childNodesTail;
+};
+
+extern Node* Node_new(void);
+extern void Node_ref(Node* node);
+extern void Node_deref(Node* node);
+extern void Node_appendChild(Node* node, Node* child);
+extern void Node_removeChild(Node* node, Node* child);
+extern void Node_replaceChild(Node* node, Node* newChild, Node* oldChild);
+
+#endif /* Node_h */
diff --git a/JavaScriptCore/API/tests/NodeList.c b/JavaScriptCore/API/tests/NodeList.c
new file mode 100644
index 0000000..ae4c170
--- /dev/null
+++ b/JavaScriptCore/API/tests/NodeList.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "NodeList.h"
+
+#include 
+
+extern NodeList* NodeList_new(Node* parentNode)
+{
+    Node_ref(parentNode);
+
+    NodeList* nodeList = (NodeList*)malloc(sizeof(NodeList));
+    nodeList->parentNode = parentNode;
+    nodeList->refCount = 0;
+    return nodeList;
+}
+
+extern unsigned NodeList_length(NodeList* nodeList)
+{
+    /* Linear count from tail -- good enough for our purposes here */
+    unsigned i = 0;
+    NodeLink* n = nodeList->parentNode->childNodesTail;
+    while (n) {
+        n = n->prev;
+        ++i;
+    }
+
+    return i;
+}
+
+extern Node* NodeList_item(NodeList* nodeList, unsigned index)
+{
+    unsigned length = NodeList_length(nodeList);
+    if (index >= length)
+        return NULL;
+
+    /* Linear search from tail -- good enough for our purposes here */
+    NodeLink* n = nodeList->parentNode->childNodesTail;
+    unsigned i = 0;
+    unsigned count = length - 1 - index;
+    while (i < count) {
+        ++i;
+        n = n->prev;
+    }
+    return n->node;
+}
+
+extern void NodeList_ref(NodeList* nodeList)
+{
+    ++nodeList->refCount;
+}
+
+extern void NodeList_deref(NodeList* nodeList)
+{
+    if (--nodeList->refCount == 0) {
+        Node_deref(nodeList->parentNode);
+        free(nodeList);
+    }
+}
diff --git a/JavaScriptCore/API/tests/NodeList.h b/JavaScriptCore/API/tests/NodeList.h
new file mode 100644
index 0000000..25b95bf
--- /dev/null
+++ b/JavaScriptCore/API/tests/NodeList.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef NodeList_h
+#define NodeList_h
+
+#include "Node.h"
+
+typedef struct {
+    unsigned refCount;
+    Node* parentNode;
+} NodeList;
+
+extern NodeList* NodeList_new(Node* parentNode);
+extern unsigned NodeList_length(NodeList*);
+extern Node* NodeList_item(NodeList*, unsigned);
+extern void NodeList_ref(NodeList*);
+extern void NodeList_deref(NodeList*);
+
+#endif /* NodeList_h */
diff --git a/JavaScriptCore/API/tests/minidom.c b/JavaScriptCore/API/tests/minidom.c
new file mode 100644
index 0000000..43ae2c1
--- /dev/null
+++ b/JavaScriptCore/API/tests/minidom.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2007 Alp Toker 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "JSContextRef.h"
+#include "JSNode.h"
+#include "JSObjectRef.h"
+#include "JSStringRef.h"
+#include 
+#include 
+#include 
+#include 
+
+static char* createStringWithContentsOfFile(const char* fileName);
+static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+int main(int argc, char* argv[])
+{
+    const char *scriptPath = "minidom.js";
+    if (argc > 1) {
+        scriptPath = argv[1];
+    }
+    
+    JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL);
+    JSObjectRef globalObject = JSContextGetGlobalObject(context);
+    
+    JSStringRef printIString = JSStringCreateWithUTF8CString("print");
+    JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunctionWithCallback(context, printIString, print), kJSPropertyAttributeNone, NULL);
+    JSStringRelease(printIString);
+    
+    JSStringRef node = JSStringCreateWithUTF8CString("Node");
+    JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_class(context), JSNode_construct), kJSPropertyAttributeNone, NULL);
+    JSStringRelease(node);
+    
+    char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
+    JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
+    JSValueRef exception;
+    JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
+    if (result)
+        printf("PASS: Test script executed successfully.\n");
+    else {
+        printf("FAIL: Test script threw exception:\n");
+        JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
+        size_t exceptionUTF8Size = JSStringGetMaximumUTF8CStringSize(exceptionIString);
+        char* exceptionUTF8 = (char*)malloc(exceptionUTF8Size);
+        JSStringGetUTF8CString(exceptionIString, exceptionUTF8, exceptionUTF8Size);
+        printf("%s\n", exceptionUTF8);
+        free(exceptionUTF8);
+        JSStringRelease(exceptionIString);
+    }
+    JSStringRelease(script);
+    free(scriptUTF8);
+
+    globalObject = 0;
+    JSGlobalContextRelease(context);
+    printf("PASS: Program exited normally.\n");
+    return 0;
+}
+
+static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(thisObject);
+
+    if (argumentCount > 0) {
+        JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
+        size_t numChars = JSStringGetMaximumUTF8CStringSize(string);
+        char stringUTF8[numChars];
+        JSStringGetUTF8CString(string, stringUTF8, numChars);
+        printf("%s\n", stringUTF8);
+    }
+    
+    return JSValueMakeUndefined(context);
+}
+
+static char* createStringWithContentsOfFile(const char* fileName)
+{
+    char* buffer;
+    
+    size_t buffer_size = 0;
+    size_t buffer_capacity = 1024;
+    buffer = (char*)malloc(buffer_capacity);
+    
+    FILE* f = fopen(fileName, "r");
+    if (!f) {
+        fprintf(stderr, "Could not open file: %s\n", fileName);
+        return 0;
+    }
+    
+    while (!feof(f) && !ferror(f)) {
+        buffer_size += fread(buffer + buffer_size, 1, buffer_capacity - buffer_size, f);
+        if (buffer_size == buffer_capacity) { /* guarantees space for trailing '\0' */
+            buffer_capacity *= 2;
+            buffer = (char*)realloc(buffer, buffer_capacity);
+            ASSERT(buffer);
+        }
+        
+        ASSERT(buffer_size < buffer_capacity);
+    }
+    fclose(f);
+    buffer[buffer_size] = '\0';
+    
+    return buffer;
+}
diff --git a/JavaScriptCore/API/tests/minidom.html b/JavaScriptCore/API/tests/minidom.html
new file mode 100644
index 0000000..7ea4747
--- /dev/null
+++ b/JavaScriptCore/API/tests/minidom.html
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+    

+
+
diff --git a/JavaScriptCore/API/tests/minidom.js b/JavaScriptCore/API/tests/minidom.js
new file mode 100644
index 0000000..4808960
--- /dev/null
+++ b/JavaScriptCore/API/tests/minidom.js
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+function shouldBe(a, b)
+{
+    var evalA;
+    try {
+        evalA = eval(a);
+    } catch(e) {
+        evalA = e;
+    }
+    
+    if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
+        print("PASS: " + a + " should be " + b + " and is.", "green");
+    else
+        print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
+}
+
+function test()
+{
+    print("Node is " + Node);
+    for (var p in Node)
+        print(p + ": " + Node[p]);
+    
+    node = new Node();
+    print("node is " + node);
+    for (var p in node)
+        print(p + ": " + node[p]);
+
+    child1 = new Node();
+    child2 = new Node();
+    child3 = new Node();
+    
+    node.appendChild(child1);
+    node.appendChild(child2);
+
+    var childNodes = node.childNodes;
+    
+    for (var i = 0; i < childNodes.length + 1; i++) {
+        print("item " + i + ": " + childNodes.item(i));
+    }
+    
+    for (var i = 0; i < childNodes.length + 1; i++) {
+        print(i + ": " + childNodes[i]);
+    }
+
+    node.removeChild(child1);
+    node.replaceChild(child3, child2);
+    
+    for (var i = 0; i < childNodes.length + 1; i++) {
+        print("item " + i + ": " + childNodes.item(i));
+    }
+
+    for (var i = 0; i < childNodes.length + 1; i++) {
+        print(i + ": " + childNodes[i]);
+    }
+
+    try {
+        node.appendChild(null);
+    } catch(e) {
+        print("caught: " + e);
+    }
+    
+    try {
+        var o = new Object();
+        o.appendChild = node.appendChild;
+        o.appendChild(node);
+    } catch(e) {
+        print("caught: " + e);
+    }
+    
+    try {
+        node.appendChild();
+    } catch(e) {
+        print("caught: " + e);
+    }
+    
+    oldNodeType = node.nodeType;
+    node.nodeType = 1;
+    shouldBe("node.nodeType", oldNodeType);
+    
+    shouldBe("node instanceof Node", true);
+    shouldBe("new Object() instanceof Node", false);
+    
+    print(Node);
+}
+
+test();
diff --git a/JavaScriptCore/API/tests/testapi.c b/JavaScriptCore/API/tests/testapi.c
new file mode 100644
index 0000000..48c8583
--- /dev/null
+++ b/JavaScriptCore/API/tests/testapi.c
@@ -0,0 +1,1026 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "JavaScriptCore.h"
+#include "JSBasePrivate.h"
+#include 
+#include 
+#include 
+
+#if COMPILER(MSVC)
+
+#include 
+
+static double nan(const char*)
+{
+    return std::numeric_limits::quiet_NaN();
+}
+
+#endif
+
+static JSGlobalContextRef context = 0;
+
+static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
+{
+    if (JSValueToBoolean(context, value) != expectedValue)
+        fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue);
+}
+
+static void assertEqualsAsNumber(JSValueRef value, double expectedValue)
+{
+    double number = JSValueToNumber(context, value, NULL);
+
+    // FIXME  - On i386 the isnan(double) macro tries to map to the isnan(float) function,
+    // causing a build break with -Wshorten-64-to-32 enabled.  The issue is known by the appropriate team.
+    // After that's resolved, we can remove these casts
+    if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue)))
+        fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue);
+}
+
+static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
+{
+    JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
+
+    size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
+    char* jsBuffer = (char*)malloc(jsSize);
+    JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
+    
+    unsigned i;
+    for (i = 0; jsBuffer[i]; i++)
+        if (jsBuffer[i] != expectedValue[i])
+            fprintf(stderr, "assertEqualsAsUTF8String failed at character %d: %c(%d) != %c(%d)\n", i, jsBuffer[i], jsBuffer[i], expectedValue[i], expectedValue[i]);
+        
+    if (jsSize < strlen(jsBuffer) + 1)
+        fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
+
+    free(jsBuffer);
+    JSStringRelease(valueAsString);
+}
+
+static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
+{
+    JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
+
+    size_t jsLength = JSStringGetLength(valueAsString);
+    const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
+
+    CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault, 
+                                                                    expectedValue,
+                                                                    kCFStringEncodingUTF8);    
+    CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
+    UniChar* cfBuffer = (UniChar*)malloc(cfLength * sizeof(UniChar));
+    CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
+    CFRelease(expectedValueAsCFString);
+
+    if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0)
+        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n");
+    
+    if (jsLength != (size_t)cfLength)
+        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
+    
+    free(cfBuffer);
+    JSStringRelease(valueAsString);
+}
+
+static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect()
+
+/* MyObject pseudo-class */
+
+static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+
+    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")
+        || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
+        || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")
+        || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")
+        || JSStringIsEqualToUTF8CString(propertyName, "0")) {
+        return true;
+    }
+    
+    return false;
+}
+
+static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+    
+    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
+        return JSValueMakeNumber(context, 1);
+    }
+    
+    if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
+        return JSValueMakeNumber(context, 1);
+    }
+
+    if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
+        return JSValueMakeUndefined(context);
+    }
+    
+    if (JSStringIsEqualToUTF8CString(propertyName, "0")) {
+        *exception = JSValueMakeNumber(context, 1);
+        return JSValueMakeNumber(context, 1);
+    }
+    
+    return NULL;
+}
+
+static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(value);
+    UNUSED_PARAM(exception);
+
+    if (JSStringIsEqualToUTF8CString(propertyName, "cantSet"))
+        return true; // pretend we set the property in order to swallow it
+    
+    return false;
+}
+
+static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+    
+    if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete"))
+        return true;
+    
+    if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) {
+        *exception = JSValueMakeNumber(context, 2);
+        return false;
+    }
+
+    return false;
+}
+
+static void MyObject_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+    
+    JSStringRef propertyName;
+    
+    propertyName = JSStringCreateWithUTF8CString("alwaysOne");
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+    
+    propertyName = JSStringCreateWithUTF8CString("myPropertyName");
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+}
+
+static JSValueRef MyObject_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(thisObject);
+    UNUSED_PARAM(exception);
+
+    if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
+        return JSValueMakeNumber(context, 1);
+    
+    return JSValueMakeUndefined(context);
+}
+
+static JSObjectRef MyObject_callAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+
+    if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
+        return JSValueToObject(context, JSValueMakeNumber(context, 1), exception);
+    
+    return JSValueToObject(context, JSValueMakeNumber(context, 0), exception);
+}
+
+static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(constructor);
+
+    JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
+    JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, exception), exception);
+    JSStringRelease(numberString);
+
+    return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, exception);
+}
+
+static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(exception);
+    
+    switch (type) {
+    case kJSTypeNumber:
+        return JSValueMakeNumber(context, 1);
+    case kJSTypeString:
+        {
+            JSStringRef string = JSStringCreateWithUTF8CString("MyObjectAsString");
+            JSValueRef result = JSValueMakeString(context, string);
+            JSStringRelease(string);
+            return result;
+        }
+    default:
+        break;
+    }
+
+    // string conversion -- forward to default object class
+    return NULL;
+}
+
+static JSStaticValue evilStaticValues[] = {
+    { "nullGetSet", 0, 0, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+static JSStaticFunction evilStaticFunctions[] = {
+    { "nullCall", 0, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+JSClassDefinition MyObject_definition = {
+    0,
+    kJSClassAttributeNone,
+    
+    "MyObject",
+    NULL,
+    
+    evilStaticValues,
+    evilStaticFunctions,
+    
+    NULL,
+    NULL,
+    MyObject_hasProperty,
+    MyObject_getProperty,
+    MyObject_setProperty,
+    MyObject_deleteProperty,
+    MyObject_getPropertyNames,
+    MyObject_callAsFunction,
+    MyObject_callAsConstructor,
+    MyObject_hasInstance,
+    MyObject_convertToType,
+};
+
+static JSClassRef MyObject_class(JSContextRef context)
+{
+    UNUSED_PARAM(context);
+
+    static JSClassRef jsClass;
+    if (!jsClass)
+        jsClass = JSClassCreate(&MyObject_definition);
+    
+    return jsClass;
+}
+
+static JSValueRef Base_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+
+    return JSValueMakeNumber(ctx, 1); // distinguish base get form derived get
+}
+
+static bool Base_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(value);
+
+    *exception = JSValueMakeNumber(ctx, 1); // distinguish base set from derived set
+    return true;
+}
+
+static JSValueRef Base_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(function);
+    UNUSED_PARAM(thisObject);
+    UNUSED_PARAM(argumentCount);
+    UNUSED_PARAM(arguments);
+    UNUSED_PARAM(exception);
+    
+    return JSValueMakeNumber(ctx, 1); // distinguish base call from derived call
+}
+
+static JSStaticFunction Base_staticFunctions[] = {
+    { "baseProtoDup", NULL, kJSPropertyAttributeNone },
+    { "baseProto", Base_callAsFunction, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+static JSStaticValue Base_staticValues[] = {
+    { "baseDup", Base_get, Base_set, kJSPropertyAttributeNone },
+    { "baseOnly", Base_get, Base_set, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+static bool TestInitializeFinalize;
+static void Base_initialize(JSContextRef context, JSObjectRef object)
+{
+    UNUSED_PARAM(context);
+
+    if (TestInitializeFinalize) {
+        ASSERT((void*)1 == JSObjectGetPrivate(object));
+        JSObjectSetPrivate(object, (void*)2);
+    }
+}
+
+static unsigned Base_didFinalize;
+static void Base_finalize(JSObjectRef object)
+{
+    UNUSED_PARAM(object);
+    if (TestInitializeFinalize) {
+        ASSERT((void*)4 == JSObjectGetPrivate(object));
+        Base_didFinalize = true;
+    }
+}
+
+static JSClassRef Base_class(JSContextRef context)
+{
+    UNUSED_PARAM(context);
+
+    static JSClassRef jsClass;
+    if (!jsClass) {
+        JSClassDefinition definition = kJSClassDefinitionEmpty;
+        definition.staticValues = Base_staticValues;
+        definition.staticFunctions = Base_staticFunctions;
+        definition.initialize = Base_initialize;
+        definition.finalize = Base_finalize;
+        jsClass = JSClassCreate(&definition);
+    }
+    return jsClass;
+}
+
+static JSValueRef Derived_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+
+    return JSValueMakeNumber(ctx, 2); // distinguish base get form derived get
+}
+
+static bool Derived_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+    UNUSED_PARAM(ctx);
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(value);
+
+    *exception = JSValueMakeNumber(ctx, 2); // distinguish base set from derived set
+    return true;
+}
+
+static JSValueRef Derived_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(function);
+    UNUSED_PARAM(thisObject);
+    UNUSED_PARAM(argumentCount);
+    UNUSED_PARAM(arguments);
+    UNUSED_PARAM(exception);
+    
+    return JSValueMakeNumber(ctx, 2); // distinguish base call from derived call
+}
+
+static JSStaticFunction Derived_staticFunctions[] = {
+    { "protoOnly", Derived_callAsFunction, kJSPropertyAttributeNone },
+    { "protoDup", NULL, kJSPropertyAttributeNone },
+    { "baseProtoDup", Derived_callAsFunction, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+static JSStaticValue Derived_staticValues[] = {
+    { "derivedOnly", Derived_get, Derived_set, kJSPropertyAttributeNone },
+    { "protoDup", Derived_get, Derived_set, kJSPropertyAttributeNone },
+    { "baseDup", Derived_get, Derived_set, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+static void Derived_initialize(JSContextRef context, JSObjectRef object)
+{
+    UNUSED_PARAM(context);
+
+    if (TestInitializeFinalize) {
+        ASSERT((void*)2 == JSObjectGetPrivate(object));
+        JSObjectSetPrivate(object, (void*)3);
+    }
+}
+
+static void Derived_finalize(JSObjectRef object)
+{
+    if (TestInitializeFinalize) {
+        ASSERT((void*)3 == JSObjectGetPrivate(object));
+        JSObjectSetPrivate(object, (void*)4);
+    }
+}
+
+static JSClassRef Derived_class(JSContextRef context)
+{
+    static JSClassRef jsClass;
+    if (!jsClass) {
+        JSClassDefinition definition = kJSClassDefinitionEmpty;
+        definition.parentClass = Base_class(context);
+        definition.staticValues = Derived_staticValues;
+        definition.staticFunctions = Derived_staticFunctions;
+        definition.initialize = Derived_initialize;
+        definition.finalize = Derived_finalize;
+        jsClass = JSClassCreate(&definition);
+    }
+    return jsClass;
+}
+
+static JSValueRef print_callAsFunction(JSContextRef context, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(functionObject);
+    UNUSED_PARAM(thisObject);
+    UNUSED_PARAM(exception);
+    
+    if (argumentCount > 0) {
+        JSStringRef string = JSValueToStringCopy(context, arguments[0], NULL);
+        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
+        char* stringUTF8 = (char*)malloc(sizeUTF8);
+        JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
+        printf("%s\n", stringUTF8);
+        free(stringUTF8);
+        JSStringRelease(string);
+    }
+    
+    return JSValueMakeUndefined(context);
+}
+
+static JSObjectRef myConstructor_callAsConstructor(JSContextRef context, JSObjectRef constructorObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(constructorObject);
+    UNUSED_PARAM(exception);
+    
+    JSObjectRef result = JSObjectMake(context, NULL, NULL);
+    if (argumentCount > 0) {
+        JSStringRef value = JSStringCreateWithUTF8CString("value");
+        JSObjectSetProperty(context, result, value, arguments[0], kJSPropertyAttributeNone, NULL);
+        JSStringRelease(value);
+    }
+    
+    return result;
+}
+
+
+static void globalObject_initialize(JSContextRef context, JSObjectRef object)
+{
+    UNUSED_PARAM(object);
+    // Ensure that an execution context is passed in
+    ASSERT(context);
+
+    // Ensure that the global object is set to the object that we were passed
+    JSObjectRef globalObject = JSContextGetGlobalObject(context);
+    ASSERT(globalObject);
+    ASSERT(object == globalObject);
+
+    // Ensure that the standard global properties have been set on the global object
+    JSStringRef array = JSStringCreateWithUTF8CString("Array");
+    JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
+    JSStringRelease(array);
+
+    UNUSED_PARAM(arrayConstructor);
+    ASSERT(arrayConstructor);
+}
+
+static JSValueRef globalObject_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(exception);
+
+    return JSValueMakeNumber(ctx, 3);
+}
+
+static bool globalObject_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(propertyName);
+    UNUSED_PARAM(value);
+
+    *exception = JSValueMakeNumber(ctx, 3);
+    return true;
+}
+
+static JSValueRef globalObject_call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    UNUSED_PARAM(function);
+    UNUSED_PARAM(thisObject);
+    UNUSED_PARAM(argumentCount);
+    UNUSED_PARAM(arguments);
+    UNUSED_PARAM(exception);
+
+    return JSValueMakeNumber(ctx, 3);
+}
+
+static JSStaticValue globalObject_staticValues[] = {
+    { "globalStaticValue", globalObject_get, globalObject_set, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+static JSStaticFunction globalObject_staticFunctions[] = {
+    { "globalStaticFunction", globalObject_call, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+static char* createStringWithContentsOfFile(const char* fileName);
+
+static void testInitializeFinalize()
+{
+    JSObjectRef o = JSObjectMake(context, Derived_class(context), (void*)1);
+    UNUSED_PARAM(o);
+    ASSERT(JSObjectGetPrivate(o) == (void*)3);
+}
+
+int main(int argc, char* argv[])
+{
+    const char *scriptPath = "testapi.js";
+    if (argc > 1) {
+        scriptPath = argv[1];
+    }
+    
+    // Test garbage collection with a fresh context
+    context = JSGlobalContextCreateInGroup(NULL, NULL);
+    TestInitializeFinalize = true;
+    testInitializeFinalize();
+    JSGlobalContextRelease(context);
+    TestInitializeFinalize = false;
+
+    ASSERT(Base_didFinalize);
+
+    JSClassDefinition globalObjectClassDefinition = kJSClassDefinitionEmpty;
+    globalObjectClassDefinition.initialize = globalObject_initialize;
+    globalObjectClassDefinition.staticValues = globalObject_staticValues;
+    globalObjectClassDefinition.staticFunctions = globalObject_staticFunctions;
+    globalObjectClassDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+    JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition);
+    context = JSGlobalContextCreateInGroup(NULL, globalObjectClass);
+
+    JSGlobalContextRetain(context);
+    JSGlobalContextRelease(context);
+    
+    JSReportExtraMemoryCost(context, 0);
+    JSReportExtraMemoryCost(context, 1);
+    JSReportExtraMemoryCost(context, 1024);
+
+    JSObjectRef globalObject = JSContextGetGlobalObject(context);
+    ASSERT(JSValueIsObject(context, globalObject));
+    
+    JSValueRef jsUndefined = JSValueMakeUndefined(context);
+    JSValueRef jsNull = JSValueMakeNull(context);
+    JSValueRef jsTrue = JSValueMakeBoolean(context, true);
+    JSValueRef jsFalse = JSValueMakeBoolean(context, false);
+    JSValueRef jsZero = JSValueMakeNumber(context, 0);
+    JSValueRef jsOne = JSValueMakeNumber(context, 1);
+    JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
+    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL);
+    JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context));
+
+    // FIXME: test funny utf8 characters
+    JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
+    JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString);
+    
+    JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
+    JSValueRef jsOneString = JSValueMakeString(context, jsOneIString);
+
+    UniChar singleUniChar = 65; // Capital A
+    CFMutableStringRef cfString = 
+        CFStringCreateMutableWithExternalCharactersNoCopy(kCFAllocatorDefault,
+                                                          &singleUniChar,
+                                                          1,
+                                                          1,
+                                                          kCFAllocatorNull);
+
+    JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
+    JSValueRef jsCFString = JSValueMakeString(context, jsCFIString);
+    
+    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
+    
+    JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
+    JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);
+
+    CFIndex cfStringLength = CFStringGetLength(cfString);
+    UniChar* buffer = (UniChar*)malloc(cfStringLength * sizeof(UniChar));
+    CFStringGetCharacters(cfString, 
+                          CFRangeMake(0, cfStringLength), 
+                          buffer);
+    JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, cfStringLength);
+    JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
+    
+    JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, CFStringGetLength(cfEmptyString));
+    free(buffer);
+    JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
+
+    ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
+    ASSERT(JSValueGetType(context, jsNull) == kJSTypeNull);
+    ASSERT(JSValueGetType(context, jsTrue) == kJSTypeBoolean);
+    ASSERT(JSValueGetType(context, jsFalse) == kJSTypeBoolean);
+    ASSERT(JSValueGetType(context, jsZero) == kJSTypeNumber);
+    ASSERT(JSValueGetType(context, jsOne) == kJSTypeNumber);
+    ASSERT(JSValueGetType(context, jsOneThird) == kJSTypeNumber);
+    ASSERT(JSValueGetType(context, jsEmptyString) == kJSTypeString);
+    ASSERT(JSValueGetType(context, jsOneString) == kJSTypeString);
+    ASSERT(JSValueGetType(context, jsCFString) == kJSTypeString);
+    ASSERT(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString);
+    ASSERT(JSValueGetType(context, jsCFEmptyString) == kJSTypeString);
+    ASSERT(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString);
+
+    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
+    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
+    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL);
+    JSStringRelease(myObjectIString);
+    
+    JSValueRef exception;
+
+    // Conversions that throw exceptions
+    exception = NULL;
+    ASSERT(NULL == JSValueToObject(context, jsNull, &exception));
+    ASSERT(exception);
+    
+    exception = NULL;
+    // FIXME  - On i386 the isnan(double) macro tries to map to the isnan(float) function,
+    // causing a build break with -Wshorten-64-to-32 enabled.  The issue is known by the appropriate team.
+    // After that's resolved, we can remove these casts
+    ASSERT(isnan((float)JSValueToNumber(context, jsObjectNoProto, &exception)));
+    ASSERT(exception);
+
+    exception = NULL;
+    ASSERT(!JSValueToStringCopy(context, jsObjectNoProto, &exception));
+    ASSERT(exception);
+    
+    ASSERT(JSValueToBoolean(context, myObject));
+    
+    exception = NULL;
+    ASSERT(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(context, 1), &exception));
+    ASSERT(exception);
+    
+    exception = NULL;
+    JSObjectGetPropertyAtIndex(context, myObject, 0, &exception);
+    ASSERT(1 == JSValueToNumber(context, exception, NULL));
+
+    assertEqualsAsBoolean(jsUndefined, false);
+    assertEqualsAsBoolean(jsNull, false);
+    assertEqualsAsBoolean(jsTrue, true);
+    assertEqualsAsBoolean(jsFalse, false);
+    assertEqualsAsBoolean(jsZero, false);
+    assertEqualsAsBoolean(jsOne, true);
+    assertEqualsAsBoolean(jsOneThird, true);
+    assertEqualsAsBoolean(jsEmptyString, false);
+    assertEqualsAsBoolean(jsOneString, true);
+    assertEqualsAsBoolean(jsCFString, true);
+    assertEqualsAsBoolean(jsCFStringWithCharacters, true);
+    assertEqualsAsBoolean(jsCFEmptyString, false);
+    assertEqualsAsBoolean(jsCFEmptyStringWithCharacters, false);
+    
+    assertEqualsAsNumber(jsUndefined, nan(""));
+    assertEqualsAsNumber(jsNull, 0);
+    assertEqualsAsNumber(jsTrue, 1);
+    assertEqualsAsNumber(jsFalse, 0);
+    assertEqualsAsNumber(jsZero, 0);
+    assertEqualsAsNumber(jsOne, 1);
+    assertEqualsAsNumber(jsOneThird, 1.0 / 3.0);
+    assertEqualsAsNumber(jsEmptyString, 0);
+    assertEqualsAsNumber(jsOneString, 1);
+    assertEqualsAsNumber(jsCFString, nan(""));
+    assertEqualsAsNumber(jsCFStringWithCharacters, nan(""));
+    assertEqualsAsNumber(jsCFEmptyString, 0);
+    assertEqualsAsNumber(jsCFEmptyStringWithCharacters, 0);
+    ASSERT(sizeof(JSChar) == sizeof(UniChar));
+    
+    assertEqualsAsCharactersPtr(jsUndefined, "undefined");
+    assertEqualsAsCharactersPtr(jsNull, "null");
+    assertEqualsAsCharactersPtr(jsTrue, "true");
+    assertEqualsAsCharactersPtr(jsFalse, "false");
+    assertEqualsAsCharactersPtr(jsZero, "0");
+    assertEqualsAsCharactersPtr(jsOne, "1");
+    assertEqualsAsCharactersPtr(jsOneThird, "0.3333333333333333");
+    assertEqualsAsCharactersPtr(jsEmptyString, "");
+    assertEqualsAsCharactersPtr(jsOneString, "1");
+    assertEqualsAsCharactersPtr(jsCFString, "A");
+    assertEqualsAsCharactersPtr(jsCFStringWithCharacters, "A");
+    assertEqualsAsCharactersPtr(jsCFEmptyString, "");
+    assertEqualsAsCharactersPtr(jsCFEmptyStringWithCharacters, "");
+    
+    assertEqualsAsUTF8String(jsUndefined, "undefined");
+    assertEqualsAsUTF8String(jsNull, "null");
+    assertEqualsAsUTF8String(jsTrue, "true");
+    assertEqualsAsUTF8String(jsFalse, "false");
+    assertEqualsAsUTF8String(jsZero, "0");
+    assertEqualsAsUTF8String(jsOne, "1");
+    assertEqualsAsUTF8String(jsOneThird, "0.3333333333333333");
+    assertEqualsAsUTF8String(jsEmptyString, "");
+    assertEqualsAsUTF8String(jsOneString, "1");
+    assertEqualsAsUTF8String(jsCFString, "A");
+    assertEqualsAsUTF8String(jsCFStringWithCharacters, "A");
+    assertEqualsAsUTF8String(jsCFEmptyString, "");
+    assertEqualsAsUTF8String(jsCFEmptyStringWithCharacters, "");
+    
+    ASSERT(JSValueIsStrictEqual(context, jsTrue, jsTrue));
+    ASSERT(!JSValueIsStrictEqual(context, jsOne, jsOneString));
+
+    ASSERT(JSValueIsEqual(context, jsOne, jsOneString, NULL));
+    ASSERT(!JSValueIsEqual(context, jsTrue, jsFalse, NULL));
+    
+    CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString);
+    CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString);
+    ASSERT(CFEqual(cfJSString, cfString));
+    ASSERT(CFEqual(cfJSEmptyString, cfEmptyString));
+    CFRelease(cfJSString);
+    CFRelease(cfJSEmptyString);
+
+    CFRelease(cfString);
+    CFRelease(cfEmptyString);
+    
+    jsGlobalValue = JSObjectMake(context, NULL, NULL);
+    JSValueProtect(context, jsGlobalValue);
+    JSGarbageCollect(context);
+    ASSERT(JSValueIsObject(context, jsGlobalValue));
+    JSValueUnprotect(context, jsGlobalValue);
+
+    JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
+    JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
+    ASSERT(JSCheckScriptSyntax(context, goodSyntax, NULL, 0, NULL));
+    ASSERT(!JSCheckScriptSyntax(context, badSyntax, NULL, 0, NULL));
+
+    JSValueRef result;
+    JSValueRef v;
+    JSObjectRef o;
+    JSStringRef string;
+
+    result = JSEvaluateScript(context, goodSyntax, NULL, NULL, 1, NULL);
+    ASSERT(result);
+    ASSERT(JSValueIsEqual(context, result, jsOne, NULL));
+
+    exception = NULL;
+    result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception);
+    ASSERT(!result);
+    ASSERT(JSValueIsObject(context, exception));
+    
+    JSStringRef array = JSStringCreateWithUTF8CString("Array");
+    JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
+    JSStringRelease(array);
+    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
+    ASSERT(result);
+    ASSERT(JSValueIsObject(context, result));
+    ASSERT(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
+    ASSERT(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(context), arrayConstructor, NULL));
+
+    o = JSValueToObject(context, result, NULL);
+    exception = NULL;
+    ASSERT(JSValueIsUndefined(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
+    ASSERT(!exception);
+    
+    JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(context, 1), &exception);
+    ASSERT(!exception);
+    
+    exception = NULL;
+    ASSERT(1 == JSValueToNumber(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception), &exception));
+    ASSERT(!exception);
+
+    JSStringRef functionBody;
+    JSObjectRef function;
+    
+    exception = NULL;
+    functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
+    JSStringRef line = JSStringCreateWithUTF8CString("line");
+    ASSERT(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception));
+    ASSERT(JSValueIsObject(context, exception));
+    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
+    assertEqualsAsNumber(v, 1);
+    JSStringRelease(functionBody);
+    JSStringRelease(line);
+
+    exception = NULL;
+    functionBody = JSStringCreateWithUTF8CString("return Array;");
+    function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception);
+    JSStringRelease(functionBody);
+    ASSERT(!exception);
+    ASSERT(JSObjectIsFunction(context, function));
+    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
+    ASSERT(v);
+    ASSERT(JSValueIsEqual(context, v, arrayConstructor, NULL));
+    
+    exception = NULL;
+    function = JSObjectMakeFunction(context, NULL, 0, NULL, jsEmptyIString, NULL, 0, &exception);
+    ASSERT(!exception);
+    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, &exception);
+    ASSERT(v && !exception);
+    ASSERT(JSValueIsUndefined(context, v));
+    
+    exception = NULL;
+    v = NULL;
+    JSStringRef foo = JSStringCreateWithUTF8CString("foo");
+    JSStringRef argumentNames[] = { foo };
+    functionBody = JSStringCreateWithUTF8CString("return foo;");
+    function = JSObjectMakeFunction(context, foo, 1, argumentNames, functionBody, NULL, 1, &exception);
+    ASSERT(function && !exception);
+    JSValueRef arguments[] = { JSValueMakeNumber(context, 2) };
+    v = JSObjectCallAsFunction(context, function, NULL, 1, arguments, &exception);
+    JSStringRelease(foo);
+    JSStringRelease(functionBody);
+    
+    string = JSValueToStringCopy(context, function, NULL);
+    assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) {return foo;}");
+    JSStringRelease(string);
+
+    JSStringRef print = JSStringCreateWithUTF8CString("print");
+    JSObjectRef printFunction = JSObjectMakeFunctionWithCallback(context, print, print_callAsFunction);
+    JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone, NULL); 
+    JSStringRelease(print);
+    
+    ASSERT(!JSObjectSetPrivate(printFunction, (void*)1));
+    ASSERT(!JSObjectGetPrivate(printFunction));
+
+    JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
+    JSObjectRef myConstructor = JSObjectMakeConstructor(context, NULL, myConstructor_callAsConstructor);
+    JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone, NULL);
+    JSStringRelease(myConstructorIString);
+    
+    ASSERT(!JSObjectSetPrivate(myConstructor, (void*)1));
+    ASSERT(!JSObjectGetPrivate(myConstructor));
+    
+    string = JSStringCreateWithUTF8CString("Derived");
+    JSObjectRef derivedConstructor = JSObjectMakeConstructor(context, Derived_class(context), NULL);
+    JSObjectSetProperty(context, globalObject, string, derivedConstructor, kJSPropertyAttributeNone, NULL);
+    JSStringRelease(string);
+    
+    o = JSObjectMake(context, NULL, NULL);
+    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
+    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL);
+    JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o);
+    size_t expectedCount = JSPropertyNameArrayGetCount(nameArray);
+    size_t count;
+    for (count = 0; count < expectedCount; ++count)
+        JSPropertyNameArrayGetNameAtIndex(nameArray, count);
+    JSPropertyNameArrayRelease(nameArray);
+    ASSERT(count == 1); // jsCFString should not be enumerated
+
+    JSValueRef argumentsArrayValues[] = { JSValueMakeNumber(context, 10), JSValueMakeNumber(context, 20) };
+    o = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, NULL);
+    string = JSStringCreateWithUTF8CString("length");
+    v = JSObjectGetProperty(context, o, string, NULL);
+    assertEqualsAsNumber(v, 2);
+    v = JSObjectGetPropertyAtIndex(context, o, 0, NULL);
+    assertEqualsAsNumber(v, 10);
+    v = JSObjectGetPropertyAtIndex(context, o, 1, NULL);
+    assertEqualsAsNumber(v, 20);
+
+    o = JSObjectMakeArray(context, 0, NULL, NULL);
+    v = JSObjectGetProperty(context, o, string, NULL);
+    assertEqualsAsNumber(v, 0);
+    JSStringRelease(string);
+
+    JSValueRef argumentsDateValues[] = { JSValueMakeNumber(context, 0) };
+    o = JSObjectMakeDate(context, 1, argumentsDateValues, NULL);
+    assertEqualsAsUTF8String(o, "Wed Dec 31 1969 16:00:00 GMT-0800 (PST)");
+
+    string = JSStringCreateWithUTF8CString("an error message");
+    JSValueRef argumentsErrorValues[] = { JSValueMakeString(context, string) };
+    o = JSObjectMakeError(context, 1, argumentsErrorValues, NULL);
+    assertEqualsAsUTF8String(o, "Error: an error message");
+    JSStringRelease(string);
+
+    string = JSStringCreateWithUTF8CString("foo");
+    JSStringRef string2 = JSStringCreateWithUTF8CString("gi");
+    JSValueRef argumentsRegExpValues[] = { JSValueMakeString(context, string), JSValueMakeString(context, string2) };
+    o = JSObjectMakeRegExp(context, 2, argumentsRegExpValues, NULL);
+    assertEqualsAsUTF8String(o, "/foo/gi");
+    JSStringRelease(string);
+    JSStringRelease(string2);
+
+    JSClassDefinition nullDefinition = kJSClassDefinitionEmpty;
+    nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+    JSClassRef nullClass = JSClassCreate(&nullDefinition);
+    JSClassRelease(nullClass);
+    
+    nullDefinition = kJSClassDefinitionEmpty;
+    nullClass = JSClassCreate(&nullDefinition);
+    JSClassRelease(nullClass);
+
+    functionBody = JSStringCreateWithUTF8CString("return this;");
+    function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL);
+    JSStringRelease(functionBody);
+    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
+    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+    v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
+    ASSERT(JSValueIsEqual(context, v, o, NULL));
+
+    functionBody = JSStringCreateWithUTF8CString("return eval(\"this\");");
+    function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL);
+    JSStringRelease(functionBody);
+    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
+    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+    v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
+    ASSERT(JSValueIsEqual(context, v, o, NULL));
+
+    JSStringRef script = JSStringCreateWithUTF8CString("this;");
+    v = JSEvaluateScript(context, script, NULL, NULL, 1, NULL);
+    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+    v = JSEvaluateScript(context, script, o, NULL, 1, NULL);
+    ASSERT(JSValueIsEqual(context, v, o, NULL));
+    JSStringRelease(script);
+
+    script = JSStringCreateWithUTF8CString("eval(this);");
+    v = JSEvaluateScript(context, script, NULL, NULL, 1, NULL);
+    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+    v = JSEvaluateScript(context, script, o, NULL, 1, NULL);
+    ASSERT(JSValueIsEqual(context, v, o, NULL));
+    JSStringRelease(script);
+
+    char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
+    if (!scriptUTF8)
+        printf("FAIL: Test script could not be loaded.\n");
+    else {
+        script = JSStringCreateWithUTF8CString(scriptUTF8);
+        result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
+        if (JSValueIsUndefined(context, result))
+            printf("PASS: Test script executed successfully.\n");
+        else {
+            printf("FAIL: Test script returned unexpected value:\n");
+            JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
+            CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
+            CFShow(exceptionCF);
+            CFRelease(exceptionCF);
+            JSStringRelease(exceptionIString);
+        }
+        JSStringRelease(script);
+        free(scriptUTF8);
+    }
+
+    // Clear out local variables pointing at JSObjectRefs to allow their values to be collected
+    function = NULL;
+    v = NULL;
+    o = NULL;
+    globalObject = NULL;
+
+    JSStringRelease(jsEmptyIString);
+    JSStringRelease(jsOneIString);
+    JSStringRelease(jsCFIString);
+    JSStringRelease(jsCFEmptyIString);
+    JSStringRelease(jsCFIStringWithCharacters);
+    JSStringRelease(jsCFEmptyIStringWithCharacters);
+    JSStringRelease(goodSyntax);
+    JSStringRelease(badSyntax);
+
+    JSGlobalContextRelease(context);
+    JSClassRelease(globalObjectClass);
+
+    printf("PASS: Program exited normally.\n");
+    return 0;
+}
+
+static char* createStringWithContentsOfFile(const char* fileName)
+{
+    char* buffer;
+    
+    size_t buffer_size = 0;
+    size_t buffer_capacity = 1024;
+    buffer = (char*)malloc(buffer_capacity);
+    
+    FILE* f = fopen(fileName, "r");
+    if (!f) {
+        fprintf(stderr, "Could not open file: %s\n", fileName);
+        return 0;
+    }
+    
+    while (!feof(f) && !ferror(f)) {
+        buffer_size += fread(buffer + buffer_size, 1, buffer_capacity - buffer_size, f);
+        if (buffer_size == buffer_capacity) { // guarantees space for trailing '\0'
+            buffer_capacity *= 2;
+            buffer = (char*)realloc(buffer, buffer_capacity);
+            ASSERT(buffer);
+        }
+        
+        ASSERT(buffer_size < buffer_capacity);
+    }
+    fclose(f);
+    buffer[buffer_size] = '\0';
+    
+    return buffer;
+}
diff --git a/JavaScriptCore/API/tests/testapi.js b/JavaScriptCore/API/tests/testapi.js
new file mode 100644
index 0000000..9c8ca9e
--- /dev/null
+++ b/JavaScriptCore/API/tests/testapi.js
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+function shouldBe(a, b)
+{
+    var evalA;
+    try {
+        evalA = eval(a);
+    } catch(e) {
+        evalA = e;
+    }
+    
+    if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
+        print("PASS: " + a + " should be " + b + " and is.", "green");
+    else
+        print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
+}
+
+function shouldThrow(a)
+{
+    var result = "__FAIL__: " + a + " did not throw an exception.";
+    
+    var evalA;
+    try {
+        eval(a);
+    } catch(e) {
+        result = "PASS: " + a + " threw: " + e;
+    }
+    
+    print(result);
+}
+
+function globalStaticFunction()
+{
+    return 4;
+}
+
+shouldBe("globalStaticValue", 3);
+shouldBe("globalStaticFunction()", 4);
+
+shouldBe("typeof MyObject", "function"); // our object implements 'call'
+MyObject.cantFind = 1;
+shouldBe("MyObject.cantFind", undefined);
+MyObject.regularType = 1;
+shouldBe("MyObject.regularType", 1);
+MyObject.alwaysOne = 2;
+shouldBe("MyObject.alwaysOne", 1);
+MyObject.cantDelete = 1;
+delete MyObject.cantDelete;
+shouldBe("MyObject.cantDelete", 1);
+shouldBe("delete MyObject.throwOnDelete", 2); // deleteProperty -- should throw 2
+MyObject.cantSet = 1;
+shouldBe("MyObject.cantSet", undefined);
+
+var foundMyPropertyName = false;
+var foundRegularType = false;
+for (var p in MyObject) {
+    if (p == "myPropertyName")
+        foundMyPropertyName = true;
+    if (p == "regularType")
+        foundRegularType = true;
+}
+print(foundMyPropertyName
+      ? "PASS: MyObject.myPropertyName was enumerated"
+      : "__FAIL__: MyObject.myPropertyName was not enumerated");
+print(foundRegularType
+      ? "PASS: MyObject.regularType was enumerated"
+      : "__FAIL__: MyObject.regularType was not enumerated");
+
+myObject = new MyObject();
+
+shouldBe("delete MyObject.regularType", true);
+shouldBe("MyObject.regularType", undefined);
+shouldBe("MyObject(0)", 1);
+shouldBe("MyObject()", undefined);
+shouldBe("typeof myObject", "object");
+shouldBe("MyObject ? 1 : 0", true); // toBoolean
+shouldBe("+MyObject", 1); // toNumber
+shouldBe("(MyObject.toString())", "[object MyObject]"); // toString
+shouldBe("String(MyObject)", "MyObjectAsString"); // type conversion to string
+shouldBe("MyObject - 0", NaN); // toPrimitive
+
+shouldBe("typeof MyConstructor", "object");
+constructedObject = new MyConstructor(1);
+shouldBe("typeof constructedObject", "object");
+shouldBe("constructedObject.value", 1);
+shouldBe("myObject instanceof MyObject", true);
+shouldBe("(new Object()) instanceof MyObject", false);
+
+shouldThrow("MyObject.nullGetSet = 1");
+shouldThrow("MyObject.nullGetSet");
+shouldThrow("MyObject.nullCall()");
+shouldThrow("MyObject.hasPropertyLie");
+
+derived = new Derived();
+
+// base properties and functions return 1 when called/gotten; derived, 2
+shouldBe("derived.baseProtoDup()", 2);
+shouldBe("derived.baseProto()", 1);
+shouldBe("derived.baseDup", 2);
+shouldBe("derived.baseOnly", 1);
+shouldBe("derived.protoOnly()", 2);
+shouldBe("derived.protoDup", 2);
+shouldBe("derived.derivedOnly", 2)
+
+// base properties throw 1 when set; derived, 2
+shouldBe("derived.baseDup = 0", 2);
+shouldBe("derived.baseOnly = 0", 1);
+shouldBe("derived.derivedOnly = 0", 2)
+shouldBe("derived.protoDup = 0", 2);
-- 
cgit v1.1