Reviewed by Maciej.
- Implemented a vast number of renames and comment clarifications
suggested during API review.
JSInternalString -> JSString
JS*Make -> JSValueMake*, JSObjectMake*
JSTypeCode -> JSType
JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code)
JSGC*Protect -> JSValue*Protect
JS*Callback -> JSObject*Callback
JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback
JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName
JSString* ->
JSStringCreateWithUTF8CString, JSStringGetUTF8CString,
JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString,
JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters.
- Changed functions taking a JSValue out arg and returning a bool indicating
whether it was set to simply return a JSValue or NULL.
- Removed JSStringGetCharacters because it's more documentation than code,
and it's just a glorified memcpy built on existing API functionality.
- Moved standard library includes into the headers that actually require them.
- Standardized use of the phrase "Create Rule."
- Removed JSLock from make functions that don't allocate.
- Added exception handling to JSValueToBoolean, since we now allow
callback objects to throw exceptions upon converting to boolean.
- Renamed JSGCCollect to JSGarbageCollect.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@15376 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/API/APICast.h b/JavaScriptCore/API/APICast.h
index 3949aa9..a509371 100644
--- a/JavaScriptCore/API/APICast.h
+++ b/JavaScriptCore/API/APICast.h
@@ -49,7 +49,7 @@
return reinterpret_cast<KJS::JSValue*>(const_cast<__JSValue*>(v));
}
-inline KJS::UString::Rep* toJS(JSInternalStringRef b)
+inline KJS::UString::Rep* toJS(JSStringRef b)
{
return reinterpret_cast<KJS::UString::Rep*>(b);
}
@@ -74,9 +74,9 @@
return reinterpret_cast<JSValueRef*>(const_cast<const KJS::JSValue**>(v));
}
-inline JSInternalStringRef toRef(KJS::UString::Rep* s)
+inline JSStringRef toRef(KJS::UString::Rep* s)
{
- return reinterpret_cast<JSInternalStringRef>(s);
+ return reinterpret_cast<JSStringRef>(s);
}
inline JSObjectRef toRef(KJS::JSObject* o)
diff --git a/JavaScriptCore/API/JSBase.h b/JavaScriptCore/API/JSBase.h
index 3c3926b..cc77384 100644
--- a/JavaScriptCore/API/JSBase.h
+++ b/JavaScriptCore/API/JSBase.h
@@ -31,8 +31,8 @@
/*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */
typedef struct __JSContext* JSContextRef;
-/*! @typedef JSInternalString A UTF16 character buffer. The fundamental string representation in JavaScript. */
-typedef struct __JSInternalString* JSInternalStringRef;
+/*! @typedef JSString A UTF16 character buffer. The fundamental string representation in JavaScript. */
+typedef struct __JSString* JSStringRef;
/*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */
typedef struct __JSClass* JSClassRef;
/*! @typedef JSPropertyListRef A JavaScript property list. Used for listing the properties in an object so they can be enumerated. */
@@ -45,7 +45,6 @@
/*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */
typedef const struct __JSValue* JSValueRef;
-
/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
typedef struct __JSValue* JSObjectRef;
diff --git a/JavaScriptCore/API/JSCallbackConstructor.cpp b/JavaScriptCore/API/JSCallbackConstructor.cpp
index d0a8646..dfdb295 100644
--- a/JavaScriptCore/API/JSCallbackConstructor.cpp
+++ b/JavaScriptCore/API/JSCallbackConstructor.cpp
@@ -31,7 +31,7 @@
const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
-JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSCallAsConstructorCallback callback)
+JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback)
: JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())
, m_callback(callback)
{
diff --git a/JavaScriptCore/API/JSCallbackConstructor.h b/JavaScriptCore/API/JSCallbackConstructor.h
index f336694..1cce808 100644
--- a/JavaScriptCore/API/JSCallbackConstructor.h
+++ b/JavaScriptCore/API/JSCallbackConstructor.h
@@ -35,7 +35,7 @@
class JSCallbackConstructor : public JSObject
{
public:
- JSCallbackConstructor(ExecState* exec, JSCallAsConstructorCallback callback);
+ JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback);
virtual bool implementsConstruct() const;
virtual JSObject* construct(ExecState*, const List &args);
@@ -51,7 +51,7 @@
JSCallbackConstructor(const JSCallbackConstructor&);
void* m_privateData;
- JSCallAsConstructorCallback m_callback;
+ JSObjectCallAsConstructorCallback m_callback;
};
} // namespace KJS
diff --git a/JavaScriptCore/API/JSCallbackFunction.cpp b/JavaScriptCore/API/JSCallbackFunction.cpp
index 935718a..5cc2620 100644
--- a/JavaScriptCore/API/JSCallbackFunction.cpp
+++ b/JavaScriptCore/API/JSCallbackFunction.cpp
@@ -33,7 +33,7 @@
const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0, 0 };
-JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSCallAsFunctionCallback callback)
+JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback)
: InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()))
, m_callback(callback)
{
diff --git a/JavaScriptCore/API/JSCallbackFunction.h b/JavaScriptCore/API/JSCallbackFunction.h
index 63c2f08..fa46047 100644
--- a/JavaScriptCore/API/JSCallbackFunction.h
+++ b/JavaScriptCore/API/JSCallbackFunction.h
@@ -36,7 +36,7 @@
class JSCallbackFunction : public InternalFunctionImp
{
public:
- JSCallbackFunction(ExecState* exec, JSCallAsFunctionCallback callback);
+ JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback);
virtual bool implementsCall() const;
virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args);
@@ -52,7 +52,7 @@
JSCallbackFunction(const JSCallbackFunction&);
void* m_privateData;
- JSCallAsFunctionCallback m_callback;
+ JSObjectCallAsFunctionCallback m_callback;
};
} // namespace KJS
diff --git a/JavaScriptCore/API/JSCallbackObject.cpp b/JavaScriptCore/API/JSCallbackObject.cpp
index 2c2457e..d05efc8 100644
--- a/JavaScriptCore/API/JSCallbackObject.cpp
+++ b/JavaScriptCore/API/JSCallbackObject.cpp
@@ -59,7 +59,7 @@
JSObjectRef thisRef = toRef(this);
do {
- if (JSInitializeCallback initialize = jsClass->callbacks.initialize)
+ if (JSObjectInitializeCallback initialize = jsClass->callbacks.initialize)
initialize(context, thisRef, toRef(exec->exceptionSlot()));
} while ((jsClass = jsClass->parent));
}
@@ -69,7 +69,7 @@
JSObjectRef thisRef = toRef(this);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
- if (JSFinalizeCallback finalize = jsClass->callbacks.finalize)
+ if (JSObjectFinalizeCallback finalize = jsClass->callbacks.finalize)
finalize(thisRef);
JSClassRelease(m_class);
@@ -84,22 +84,21 @@
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
- JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
// optional optimization to bypass getProperty in cases when we only need to know if the property exists
- if (JSHasPropertyCallback hasPropertyCallback = jsClass->callbacks.hasProperty) {
- if (hasPropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
+ if (JSObjectHasPropertyCallback hasProperty = jsClass->callbacks.hasProperty) {
+ if (hasProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
slot.setCustom(this, callbackGetter);
return true;
}
- } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) {
- JSValueRef returnValue;
- if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) {
+ } else if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty) {
+ if (JSValueRef value = getProperty(context, thisRef, propertyNameRef, 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<JSObject*>(toJS(returnValue)), cachedValueGetter);
+ slot.setCustom(reinterpret_cast<JSObject*>(toJS(value)), cachedValueGetter);
return true;
}
}
@@ -133,12 +132,12 @@
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
- JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
JSValueRef valueRef = toRef(value);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) {
- if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
+ if (JSObjectSetPropertyCallback setProperty = jsClass->callbacks.setProperty) {
+ if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
return;
}
@@ -146,8 +145,8 @@
if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
if (entry->attributes & kJSPropertyAttributeReadOnly)
return;
- if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) {
- if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
+ if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
+ if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
return;
}
}
@@ -162,6 +161,7 @@
}
}
}
+
return JSObject::put(exec, propertyName, value, attr);
}
@@ -174,11 +174,11 @@
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
- JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) {
- if (deletePropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ if (JSObjectDeletePropertyCallback deleteProperty = jsClass->callbacks.deleteProperty) {
+ if (deleteProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
return true;
}
@@ -198,6 +198,7 @@
}
}
}
+
return JSObject::deleteProperty(exec, propertyName);
}
@@ -221,12 +222,12 @@
JSObjectRef thisRef = toRef(this);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSCallAsConstructorCallback callAsConstructorCallback = jsClass->callbacks.callAsConstructor) {
+ if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callbacks.callAsConstructor) {
size_t argc = args.size();
JSValueRef argv[argc];
for (size_t i = 0; i < argc; i++)
argv[i] = toRef(args[i]);
- return toJS(callAsConstructorCallback(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
+ return toJS(callAsConstructor(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
}
}
@@ -250,12 +251,12 @@
JSObjectRef thisObjRef = toRef(thisObj);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSCallAsFunctionCallback callAsFunctionCallback = jsClass->callbacks.callAsFunction) {
+ if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callbacks.callAsFunction) {
size_t argc = args.size();
JSValueRef argv[argc];
for (size_t i = 0; i < argc; i++)
argv[i] = toRef(args[i]);
- return toJS(callAsFunctionCallback(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
+ return toJS(callAsFunction(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
}
}
@@ -269,8 +270,8 @@
JSObjectRef thisRef = toRef(this);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)
- getPropertyListCallback(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
+ if (JSObjectAddPropertiesToListCallback addPropertiesToList = jsClass->callbacks.addPropertiesToList)
+ addPropertiesToList(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
typedef __JSClass::StaticValuesTable::const_iterator iterator;
@@ -303,13 +304,11 @@
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
- JSValueRef returnValue;
- if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue, toRef(exec->exceptionSlot())))
- return toJS(returnValue)->getBoolean();
- }
- }
+ for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
+ if (JSValueRef value = convertToType(context, thisRef, kJSTypeBoolean, toRef(exec->exceptionSlot())))
+ return toJS(value)->getBoolean();
+
return JSObject::toBoolean(exec);
}
@@ -318,13 +317,11 @@
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
- JSValueRef returnValue;
- if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue, toRef(exec->exceptionSlot())))
- return toJS(returnValue)->getNumber();
- }
- }
+ for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
+ if (JSValueRef value = convertToType(context, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
+ return toJS(value)->getNumber();
+
return JSObject::toNumber(exec);
}
@@ -333,13 +330,11 @@
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
- if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
- JSValueRef returnValue;
- if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue, toRef(exec->exceptionSlot())))
- return toJS(returnValue)->getString();
- }
- }
+ for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
+ if (JSValueRef value = convertToType(context, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
+ return toJS(value)->getString();
+
return JSObject::toString(exec);
}
@@ -358,6 +353,7 @@
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
if (jsClass == c)
return true;
+
return false;
}
@@ -374,17 +370,14 @@
JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
JSObjectRef thisRef = toRef(thisObj);
- JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
- for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
- JSValueRef returnValue;
-
+ for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent)
if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues)
if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
- if (JSGetPropertyCallback getPropertyCallback = entry->getProperty)
- if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
- return toJS(returnValue);
- }
+ if (JSObjectGetPropertyCallback getProperty = entry->getProperty)
+ if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ return toJS(value);
return jsUndefined();
}
@@ -400,7 +393,7 @@
for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
- JSValue* v = toJS(JSFunctionMake(toRef(exec), entry->callAsFunction));
+ JSValue* v = toJS(JSObjectMakeFunction(toRef(exec), entry->callAsFunction));
thisObj->putDirect(propertyName, v, entry->attributes);
return v;
}
@@ -416,15 +409,12 @@
JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
JSObjectRef thisRef = toRef(thisObj);
- JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
- for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
- JSValueRef returnValue;
-
- if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty)
- if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
- return toJS(returnValue);
- }
+ for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent)
+ if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty)
+ if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ return toJS(value);
return jsUndefined();
}
diff --git a/JavaScriptCore/API/JSClassRef.h b/JavaScriptCore/API/JSClassRef.h
index 2452843..e2a9151 100644
--- a/JavaScriptCore/API/JSClassRef.h
+++ b/JavaScriptCore/API/JSClassRef.h
@@ -32,28 +32,29 @@
#include "ustring.h"
struct StaticValueEntry {
- StaticValueEntry(JSGetPropertyCallback _getProperty, JSSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
+ StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
: getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes)
{
}
- JSGetPropertyCallback getProperty;
- JSSetPropertyCallback setProperty;
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
JSPropertyAttributes attributes;
};
struct StaticFunctionEntry {
- StaticFunctionEntry(JSCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)
- : callAsFunction(_callAsFunction), attributes(_attributes)
+ StaticFunctionEntry(JSObjectCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)
+ : callAsFunction(_callAsFunction), attributes(_attributes)
{
}
- JSCallAsFunctionCallback callAsFunction;
+ JSObjectCallAsFunctionCallback callAsFunction;
JSPropertyAttributes attributes;
};
struct __JSClass {
- __JSClass() : refCount(0), staticValues(0), staticFunctions(0)
+ __JSClass()
+ : refCount(0), staticValues(0), staticFunctions(0)
{
}
diff --git a/JavaScriptCore/API/JSContextRef.cpp b/JavaScriptCore/API/JSContextRef.cpp
index 16d03f2..d3a128e 100644
--- a/JavaScriptCore/API/JSContextRef.cpp
+++ b/JavaScriptCore/API/JSContextRef.cpp
@@ -62,7 +62,7 @@
return toRef(exec->dynamicInterpreter()->globalObject());
}
-JSValueRef JSEvaluate(JSContextRef context, JSInternalStringRef script, JSObjectRef thisObject, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+JSValueRef JSEvaluate(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
ExecState* exec = toJS(context);
@@ -85,7 +85,7 @@
return toRef(jsUndefined());
}
-bool JSCheckSyntax(JSContextRef context, JSInternalStringRef script, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+bool JSCheckSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
diff --git a/JavaScriptCore/API/JSContextRef.h b/JavaScriptCore/API/JSContextRef.h
index 455770d..7f2d1de 100644
--- a/JavaScriptCore/API/JSContextRef.h
+++ b/JavaScriptCore/API/JSContextRef.h
@@ -30,6 +30,8 @@
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSValueRef.h>
+#include <stdbool.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -54,8 +56,8 @@
/*!
@function
-@abstract Returns the global object of a JavaScript execution context.
-@param context The JSContext whose global object you want to retrieve.
+@abstract Gets the global object of a JavaScript execution context.
+@param context The JSContext whose global object you want to get.
@result context's global object.
*/
JSObjectRef JSContextGetGlobalObject(JSContextRef context);
@@ -65,26 +67,26 @@
@function
@abstract Evaluates a string of JavaScript.
@param context The execution context to use.
-@param script A JSInternalString containing the script to evaluate.
+@param script A JSString containing the script to evaluate.
@param thisObject The object to use as "this," or NULL to use the global object as "this."
-@param sourceURL A JSInternalString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
@param exception A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception.
@result The JSValue that results from evaluating script, or NULL if an uncaught exception is thrown.
*/
-JSValueRef JSEvaluate(JSContextRef context, JSInternalStringRef script, JSObjectRef thisObject, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+JSValueRef JSEvaluate(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
@function JSCheckSyntax
@abstract Checks for syntax errors in a string of JavaScript.
@param context The execution context to use.
-@param script A JSInternalString containing the JavaScript to check for syntax errors.
-@param sourceURL A JSInternalString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param script A JSString containing the script to check for syntax errors.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
@result true if the script is syntactically correct, otherwise false.
*/
-bool JSCheckSyntax(JSContextRef context, JSInternalStringRef script, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+bool JSCheckSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
#ifdef __cplusplus
}
diff --git a/JavaScriptCore/API/JSInternalStringRef.cpp b/JavaScriptCore/API/JSInternalStringRef.cpp
index 468ac9d..acdc5c4 100644
--- a/JavaScriptCore/API/JSInternalStringRef.cpp
+++ b/JavaScriptCore/API/JSInternalStringRef.cpp
@@ -36,20 +36,20 @@
using namespace KJS;
-JSValueRef JSStringMake(JSInternalStringRef string)
+JSValueRef JSValueMakeString(JSStringRef string)
{
JSLock lock;
UString::Rep* rep = toJS(string);
return toRef(jsString(UString(rep)));
}
-JSInternalStringRef JSInternalStringCreate(const JSChar* chars, size_t numChars)
+JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
{
JSLock lock;
return toRef(UString(reinterpret_cast<const UChar*>(chars), numChars).rep()->ref());
}
-JSInternalStringRef JSInternalStringCreateUTF8(const char* string)
+JSStringRef JSStringCreateWithUTF8CString(const char* string)
{
JSLock lock;
// FIXME: Only works with ASCII
@@ -57,52 +57,44 @@
return toRef(UString(string).rep()->ref());
}
-JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string)
+JSStringRef JSStringRetain(JSStringRef string)
{
UString::Rep* rep = toJS(string);
return toRef(rep->ref());
}
-void JSInternalStringRelease(JSInternalStringRef string)
+void JSStringRelease(JSStringRef string)
{
JSLock lock;
UString::Rep* rep = toJS(string);
rep->deref();
}
-JSInternalStringRef JSValueCopyStringValue(JSContextRef context, JSValueRef value)
+JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value)
{
JSLock lock;
JSValue* jsValue = toJS(value);
ExecState* exec = toJS(context);
- JSInternalStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
+ JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
if (exec->hadException())
exec->clearException();
return stringRef;
}
-size_t JSInternalStringGetLength(JSInternalStringRef string)
+size_t JSStringGetLength(JSStringRef string)
{
UString::Rep* rep = toJS(string);
return rep->size();
}
-const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string)
+const JSChar* JSStringGetCharactersPtr(JSStringRef string)
{
UString::Rep* rep = toJS(string);
return reinterpret_cast<const JSChar*>(rep->data());
}
-void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars)
-{
- UString::Rep* rep = toJS(string);
- const JSChar* data = reinterpret_cast<const JSChar*>(rep->data());
-
- memcpy(buffer, data, numChars * sizeof(JSChar));
-}
-
-size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string)
+size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)
{
UString::Rep* rep = toJS(string);
@@ -110,7 +102,7 @@
return rep->size() * 3 + 1; // + 1 for terminating '\0'
}
-size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize)
+size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize)
{
JSLock lock;
UString::Rep* rep = toJS(string);
@@ -121,7 +113,7 @@
return length;
}
-bool JSInternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b)
+bool JSStringIsEqual(JSStringRef a, JSStringRef b)
{
UString::Rep* aRep = toJS(a);
UString::Rep* bRep = toJS(b);
@@ -129,17 +121,17 @@
return UString(aRep) == UString(bRep);
}
-bool JSInternalStringIsEqualUTF8(JSInternalStringRef a, const char* b)
+bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b)
{
- JSInternalStringRef bBuf = JSInternalStringCreateUTF8(b);
- bool result = JSInternalStringIsEqual(a, bBuf);
- JSInternalStringRelease(bBuf);
+ JSStringRef bBuf = JSStringCreateWithUTF8CString(b);
+ bool result = JSStringIsEqual(a, bBuf);
+ JSStringRelease(bBuf);
return result;
}
#if defined(__APPLE__)
-JSInternalStringRef JSInternalStringCreateCF(CFStringRef string)
+JSStringRef JSStringCreateWithCFString(CFStringRef string)
{
JSLock lock;
CFIndex length = CFStringGetLength(string);
@@ -156,7 +148,7 @@
return toRef(rep);
}
-CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string)
+CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)
{
UString::Rep* rep = toJS(string);
return CFStringCreateWithCharacters(alloc, reinterpret_cast<const JSChar*>(rep->data()), rep->size());
diff --git a/JavaScriptCore/API/JSInternalStringRef.h b/JavaScriptCore/API/JSInternalStringRef.h
index b3ece93..a994e6e 100644
--- a/JavaScriptCore/API/JSInternalStringRef.h
+++ b/JavaScriptCore/API/JSInternalStringRef.h
@@ -28,6 +28,10 @@
#define JSInternalStringRef_h
#include <JavaScriptCore/JSValueRef.h>
+
+#include <stdbool.h>
+#include <stddef.h> // for size_t
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -45,102 +49,91 @@
/*!
@function
@abstract Creates a JavaScript string from a buffer of Unicode characters.
-@param chars The buffer of Unicode characters to copy into the new JSInternalString.
+@param chars The buffer of Unicode characters to copy into the new JSString.
@param numChars The number of characters to copy from the buffer pointed to by chars.
-@result A JSInternalString containing chars. Ownership follows the create rule.
+@result A JSString containing chars. Ownership follows the Create Rule.
*/
-JSInternalStringRef JSInternalStringCreate(const JSChar* chars, size_t numChars);
+JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
/*!
@function
@abstract Creates a JavaScript string from a null-terminated UTF8 string.
-@param string The null-terminated UTF8 string to copy into the new JSInternalString.
-@result A JSInternalString containing string. Ownership follows the create rule.
+@param string The null-terminated UTF8 string to copy into the new JSString.
+@result A JSString containing string. Ownership follows the Create Rule.
*/
-JSInternalStringRef JSInternalStringCreateUTF8(const char* string);
+JSStringRef JSStringCreateWithUTF8CString(const char* string);
/*!
@function
@abstract Retains a JavaScript string.
-@param string The JSInternalString to retain.
-@result A JSInternalString that is the same as buffer.
+@param string The JSString to retain.
+@result A JSString that is the same as string.
*/
-JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string);
+JSStringRef JSStringRetain(JSStringRef string);
/*!
@function
@abstract Releases a JavaScript string.
-@param string The JSInternalString to release.
+@param string The JSString to release.
*/
-void JSInternalStringRelease(JSInternalStringRef string);
+void JSStringRelease(JSStringRef string);
/*!
@function
@abstract Returns the number of Unicode characters in a JavaScript string.
-@param string The JSInternalString whose length (in Unicode characters) you want to know.
+@param string The JSString whose length (in Unicode characters) you want to know.
@result The number of Unicode characters stored in string.
*/
-size_t JSInternalStringGetLength(JSInternalStringRef string);
+size_t JSStringGetLength(JSStringRef string);
/*!
@function
-@abstract Quickly obtains a pointer to the Unicode character buffer that
+@abstract Returns a pointer to the Unicode character buffer that
serves as the backing store for a JavaScript string.
-@param string The JSInternalString whose backing store you want to access.
+@param string The JSString whose backing store you want to access.
@result A pointer to the Unicode character buffer that serves as string's
backing store, which will be deallocated when string is deallocated.
*/
-const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string);
-/*!
-@function
-@abstract Copies a JavaScript string's Unicode characters into an
- external character buffer.
-@param string The source JSInternalString.
-@param buffer The destination JSChar buffer into which to copy string's
- characters. On return, buffer contains the requested Unicode characters.
-@param numChars The number of Unicode characters to copy. This number must not
- exceed the length of the string.
-*/
-void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars);
+const JSChar* JSStringGetCharactersPtr(JSStringRef string);
/*!
@function
-@abstract Returns the maximum number of bytes required to encode the
- contents of a JavaScript string as a null-terminated UTF8 string.
-@param string The JSInternalString whose maximum encoded length (in bytes) you
+@abstract Returns the maximum number of bytes a JavaScript string will
+ take up if converted into a null-terminated UTF8 string.
+@param string The JSString whose maximum converted size (in bytes) you
want to know.
-@result The maximum number of bytes required to encode string's contents
- as a null-terminated UTF8 string.
+@result The maximum number of bytes that could be required to convert string into a
+ null-terminated UTF8 string. The number of bytes that the conversion actually ends
+ up requiring could be less than this, but never more.
*/
-size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string);
+size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
/*!
@function
-@abstract Converts a JavaScript string's contents into a
- null-terminated UTF8 string, and copies the result into an external byte buffer.
-@param string The source JSInternalString.
-@param buffer The destination byte buffer into which to copy a UTF8 string
- representation of string. The buffer must be at least bufferSize bytes in length.
- On return, buffer contains a UTF8 string representation of string.
+@abstract Converts a JavaScript string into a null-terminated UTF8 string,
+ and copies the result into an external byte buffer.
+@param string The source JSString.
+@param buffer The destination byte buffer into which to copy a null-terminated
+ UTF8 string representation of string. The buffer must be at least bufferSize
+ bytes in size. On return, buffer contains a UTF8 string representation of string.
If bufferSize is too small, buffer will contain only partial results.
-@param bufferSize The length of the external buffer in bytes.
-@result The number of bytes written into buffer (including the null-terminator byte).
+@param bufferSize The size of the external buffer in bytes.
+@result The number of bytes written into buffer (including the null-terminator byte).
*/
-size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize);
+size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
/*!
@function
-@abstract Tests whether the characters in two JavaScript strings match.
-@param a The first JSInternalString to test.
-@param b The second JSInternalString to test.
-@result true if the characters in the two strings match, otherwise false.
+@abstract Tests whether two JavaScript strings match.
+@param a The first JSString to test.
+@param b The second JSString to test.
+@result true if the two strings match, otherwise false.
*/
-bool JSInternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b);
+bool JSStringIsEqual(JSStringRef a, JSStringRef b);
/*!
@function
-@abstract Tests whether the characters in a JavaScript string match
- the characters in a null-terminated UTF8 string.
-@param a The JSInternalString to test.
+@abstract Tests whether a JavaScript string matches a null-terminated UTF8 string.
+@param a The JSString to test.
@param b The null-terminated UTF8 string to test.
-@result true if the characters in the two strings match, otherwise false.
+@result true if the two strings match, otherwise false.
*/
-bool JSInternalStringIsEqualUTF8(JSInternalStringRef a, const char* b);
+bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
#if defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>
@@ -150,18 +143,18 @@
@abstract Creates a JavaScript string from a CFString.
@discussion This function is optimized to take advantage of cases when
CFStringGetCharactersPtr returns a valid pointer.
-@param string The CFString to copy into the new JSInternalString.
-@result A JSInternalString containing string. Ownership follows the create rule.
+@param string The CFString to copy into the new JSString.
+@result A JSString containing string. Ownership follows the Create Rule.
*/
-JSInternalStringRef JSInternalStringCreateCF(CFStringRef string);
+JSStringRef JSStringCreateWithCFString(CFStringRef string);
/*!
@function
@abstract Creates a CFString form a JavaScript string.
@param alloc The alloc parameter to pass to CFStringCreate.
-@param string The JSInternalString to copy into the new CFString.
-@result A CFString containing string. Ownership follows the create rule.
+@param string The JSString to copy into the new CFString.
+@result A CFString containing string. Ownership follows the Create Rule.
*/
-CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string);
+CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string);
#endif // __APPLE__
#ifdef __cplusplus
diff --git a/JavaScriptCore/API/JSNode.c b/JavaScriptCore/API/JSNode.c
index 64ac941..60e9080 100644
--- a/JavaScriptCore/API/JSNode.c
+++ b/JavaScriptCore/API/JSNode.c
@@ -39,13 +39,13 @@
// Example of throwing a type error for invalid values
if (!JSValueIsObjectOfClass(thisObject, JSNode_class(context))) {
- JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes");
- *exception = JSStringMake(message);
- JSInternalStringRelease(message);
+ JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes");
+ *exception = JSValueMakeString(message);
+ JSStringRelease(message);
} else if (argc < 1 || !JSValueIsObjectOfClass(argv[0], JSNode_class(context))) {
- JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node");
- *exception = JSStringMake(message);
- JSInternalStringRelease(message);
+ JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node");
+ *exception = JSValueMakeString(message);
+ JSStringRelease(message);
} else {
Node* node = JSObjectGetPrivate(thisObject);
Node* child = JSObjectGetPrivate(JSValueToObject(context, argv[0]));
@@ -53,7 +53,7 @@
Node_appendChild(node, child);
}
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static JSValueRef JSNodePrototype_removeChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception)
@@ -73,7 +73,7 @@
}
}
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static JSValueRef JSNodePrototype_replaceChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception)
@@ -95,7 +95,7 @@
}
}
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static JSStaticFunction JSNodePrototype_staticFunctions[] = {
@@ -113,38 +113,37 @@
return nodePrototypeClass;
}
-static bool JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(propertyName);
Node* node = JSObjectGetPrivate(object);
if (node) {
- JSInternalStringRef nodeType = JSInternalStringCreateUTF8(node->nodeType);
- *returnValue = JSStringMake(nodeType);
- JSInternalStringRelease(nodeType);
- return true;
+ JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
+ JSValueRef value = JSValueMakeString(nodeType);
+ JSStringRelease(nodeType);
+ return value;
}
- return false;
+
+ return NULL;
}
-static bool JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(propertyName);
Node* node = JSObjectGetPrivate(thisObject);
assert(node);
- *returnValue = JSNodeList_new(context, NodeList_new(node));
- return true;
+ return JSNodeList_new(context, NodeList_new(node));
}
-static bool JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(propertyName);
UNUSED_PARAM(object);
- *returnValue = JSUndefinedMake();
- return true;
+ return JSValueMakeUndefined();
}
static JSStaticValue JSNode_staticValues[] = {
@@ -179,7 +178,7 @@
static JSObjectRef prototype;
if (!prototype) {
prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL);
- JSGCProtect(prototype);
+ JSValueProtect(prototype);
}
return prototype;
}
diff --git a/JavaScriptCore/API/JSNodeList.c b/JavaScriptCore/API/JSNodeList.c
index 8e720b5..f278791 100644
--- a/JavaScriptCore/API/JSNodeList.c
+++ b/JavaScriptCore/API/JSNodeList.c
@@ -38,7 +38,7 @@
return JSNode_new(context, node);
}
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static JSStaticFunction JSNodeListPrototype_staticFunctions[] = {
@@ -56,14 +56,13 @@
return jsClass;
}
-static bool JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(context);
NodeList* nodeList = JSObjectGetPrivate(thisObject);
assert(nodeList);
- *returnValue = JSNumberMake(NodeList_length(nodeList));
- return true;
+ return JSValueMakeNumber(NodeList_length(nodeList));
}
static JSStaticValue JSNodeList_staticValues[] = {
@@ -71,21 +70,20 @@
{ 0, 0, 0, 0 }
};
-static bool JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
NodeList* nodeList = JSObjectGetPrivate(thisObject);
assert(nodeList);
- double index = JSValueToNumber(context, JSStringMake(propertyName));
+ double index = JSValueToNumber(context, JSValueMakeString(propertyName));
unsigned uindex = index;
if (uindex == index) { // false for NaN
Node* node = NodeList_item(nodeList, uindex);
if (node) {
- *returnValue = JSNode_new(context, node);
- return true;
+ return JSNode_new(context, node);
}
}
- return false;
+ return NULL;
}
static void JSNodeList_finalize(JSObjectRef thisObject)
@@ -114,7 +112,7 @@
static JSObjectRef prototype;
if (!prototype) {
prototype = JSObjectMake(context, JSNodeListPrototype_class(context), NULL);
- JSGCProtect(prototype);
+ JSValueProtect(prototype);
}
return prototype;
}
diff --git a/JavaScriptCore/API/JSObjectRef.cpp b/JavaScriptCore/API/JSObjectRef.cpp
index 505cf19..8592fd3 100644
--- a/JavaScriptCore/API/JSObjectRef.cpp
+++ b/JavaScriptCore/API/JSObjectRef.cpp
@@ -56,21 +56,21 @@
return toRef(new JSCallbackObject(context, jsClass, jsPrototype));
}
-JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction)
+JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction)
{
JSLock lock;
ExecState* exec = toJS(context);
return toRef(new JSCallbackFunction(exec, callAsFunction));
}
-JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor)
+JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor)
{
JSLock lock;
ExecState* exec = toJS(context);
return toRef(new JSCallbackConstructor(exec, callAsConstructor));
}
-JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
@@ -96,7 +96,7 @@
return toRef(static_cast<JSObject*>(new DeclaredFunctionImp(exec, "anonymous", bodyNode.get(), scopeChain)));
}
-JSInternalStringRef JSObjectGetDescription(JSObjectRef object)
+JSStringRef JSObjectGetDescription(JSObjectRef object)
{
JSLock lock;
JSObject* jsObject = toJS(object);
@@ -117,7 +117,7 @@
jsObject->setPrototype(jsValue);
}
-bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName)
+bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
{
JSLock lock;
ExecState* exec = toJS(context);
@@ -127,7 +127,7 @@
return jsObject->hasProperty(exec, Identifier(nameRep));
}
-JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName)
+JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
{
JSLock lock;
ExecState* exec = toJS(context);
@@ -140,7 +140,7 @@
return toRef(jsValue);
}
-bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes)
+bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes)
{
JSLock lock;
ExecState* exec = toJS(context);
@@ -156,7 +156,7 @@
return false;
}
-bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName)
+bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
{
JSLock lock;
ExecState* exec = toJS(context);
@@ -284,11 +284,11 @@
return JSPropertyEnumeratorRetain(enumerator);
}
-JSInternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator)
+JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator)
{
ReferenceListIterator& iterator = enumerator->iterator;
if (iterator != enumerator->list.end()) {
- JSInternalStringRef result = toRef(iterator->getPropertyName().ustring().rep());
+ JSStringRef result = toRef(iterator->getPropertyName().ustring().rep());
iterator++;
return result;
}
@@ -307,7 +307,7 @@
delete enumerator;
}
-void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSInternalStringRef propertyName)
+void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName)
{
JSLock lock;
ReferenceList* jsPropertyList = toJS(propertyList);
diff --git a/JavaScriptCore/API/JSObjectRef.h b/JavaScriptCore/API/JSObjectRef.h
index 3f75ac6..f8532ba 100644
--- a/JavaScriptCore/API/JSObjectRef.h
+++ b/JavaScriptCore/API/JSObjectRef.h
@@ -30,6 +30,9 @@
#include <JavaScriptCore/JSBase.h>
#include <JavaScriptCore/JSValueRef.h>
+#include <stdbool.h>
+#include <stddef.h> // for size_t
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -55,7 +58,7 @@
typedef unsigned JSPropertyAttributes;
/*!
-@typedef JSInitializeCallback
+@typedef JSObjectInitializeCallback
@abstract The callback invoked when an object is first created.
@param context The execution context to use.
@param object The JSObject being created.
@@ -65,10 +68,10 @@
void Initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception);
*/
typedef void
-(*JSInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);
+(*JSObjectInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);
/*!
-@typedef JSFinalizeCallback
+@typedef JSObjectFinalizeCallback
@abstract The callback invoked when an object is finalized (prepared for garbage collection).
@param object The JSObject being finalized.
@discussion If you named your function Finalize, you would declare it like this:
@@ -76,80 +79,81 @@
void Finalize(JSObjectRef object);
*/
typedef void
-(*JSFinalizeCallback) (JSObjectRef object);
+(*JSObjectFinalizeCallback) (JSObjectRef object);
/*!
-@typedef JSHasPropertyCallback
+@typedef JSObjectHasPropertyCallback
@abstract The callback invoked when determining whether an object has a given property.
@param context The current execution context.
@param object The JSObject to search for the property.
-@param propertyName A JSInternalString containing the name of the property look up.
+@param propertyName A JSString containing the name of the property look up.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
@result true if object has the property, otherwise false.
@discussion If you named your function HasProperty, you would declare it like this:
-bool HasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
+bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive. If this callback is NULL, the getProperty callback will be used to service hasProperty calls.
+If this function returns false, the hasProperty request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
+
+This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive. If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
*/
typedef bool
-(*JSHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
+(*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
-@typedef JSGetPropertyCallback
+@typedef JSObjectGetPropertyCallback
@abstract The callback invoked when getting a property from an object.
@param context The current execution context.
@param object The JSObject to search for the property.
-@param propertyName A JSInternalString containing the name of the property to get.
-@param returnValue A pointer to a JSValue in which to store the property's value.
+@param propertyName A JSString containing the name of the property to get.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
-@result true if object has the property in question, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue.
+@result The property's value if object has the property, otherwise NULL.
@discussion If you named your function GetProperty, you would declare it like this:
-bool GetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception);
+JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-If this function returns false, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
+If this function returns NULL, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
*/
-typedef bool
-(*JSGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception);
+typedef JSValueRef
+(*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
-@typedef JSSetPropertyCallback
+@typedef JSObjectSetPropertyCallback
@abstract The callback invoked when setting the value of a given property.
@param context The current execution context.
@param object The JSObject on which to set the property's value.
-@param propertyName A JSInternalString containing the name of the property to set.
+@param propertyName A JSString containing the name of the property to set.
@param value A JSValue to use as the property's value.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
-@result true if the property was successfully set, otherwise false.
+@result true if the property was set, otherwise false.
@discussion If you named your function SetProperty, you would declare it like this:
-bool SetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception);
+bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class).
*/
typedef bool
-(*JSSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception);
+(*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
/*!
-@typedef JSDeletePropertyCallback
+@typedef JSObjectDeletePropertyCallback
@abstract The callback invoked when deleting a given property.
@param context The current execution context.
@param object The JSObject in which to delete the property.
-@param propertyName A JSInternalString containing the name of the property to delete.
+@param propertyName A JSString containing the name of the property to delete.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
@result true if propertyName was successfully deleted, otherwise false.
@discussion If you named your function DeleteProperty, you would declare it like this:
-bool DeleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
+bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
If this function returns false, the delete request forwards to object's static property table, then its parent class chain (which includes the default object class).
*/
typedef bool
-(*JSDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
+(*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
-@typedef JSGetPropertyListCallback
+@typedef JSObjectAddPropertiesToListCallback
@abstract The callback invoked when adding an object's properties to a property list.
@param context The current execution context.
@param object The JSObject whose properties need to be added to propertyList.
@@ -157,17 +161,17 @@
@param exception A pointer to a JSValueRef in which to return an exception, if any.
@discussion If you named your function GetPropertyList, you would declare it like this:
-void GetPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
+void AddPropertiesToList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
Use JSPropertyListAdd to add properties to propertyList.
Property lists are used by JSPropertyEnumerators and JavaScript for...in loops.
*/
typedef void
-(*JSGetPropertyListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
+(*JSObjectAddPropertiesToListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
/*!
-@typedef JSCallAsFunctionCallback
+@typedef JSObjectCallAsFunctionCallback
@abstract The callback invoked when an object is called as a function.
@param context The current execution context.
@param function A JSObject that is the function being called.
@@ -185,10 +189,10 @@
If this callback is NULL, calling your object as a function will throw an exception.
*/
typedef JSValueRef
-(*JSCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
+(*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
/*!
-@typedef JSCallAsConstructorCallback
+@typedef JSObjectCallAsConstructorCallback
@abstract The callback invoked when an object is used as a constructor in a 'new' statement.
@param context The current execution context.
@param constructor A JSObject that is the constructor being called.
@@ -205,25 +209,24 @@
If this callback is NULL, using your object as a constructor in a 'new' statement will throw an exception.
*/
typedef JSObjectRef
-(*JSCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
+(*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
/*!
-@typedef JSConvertToTypeCallback
+@typedef JSObjectConvertToTypeCallback
@abstract The callback invoked when converting an object to a particular JavaScript type.
@param context The current execution context.
@param object The JSObject to convert.
-@param typeCode A JSTypeCode specifying the JavaScript type to convert to.
-@param returnValue A pointer to a JSValue in which to store the converted value.
+@param type A JSType specifying the JavaScript type to convert to.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
-@result true if the value was converted, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue.
+@result The objects's converted value, or NULL if the object was not converted.
@discussion If you named your function ConvertToType, you would declare it like this:
-bool ConvertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);
+JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
*/
-typedef bool
-(*JSConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);
+typedef JSValueRef
+(*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
/*!
@struct JSObjectCallbacks
@@ -241,17 +244,17 @@
@field convertToType The callback invoked when converting an object to a particular JavaScript type.
*/
typedef struct {
- int version; // current (and only) version is 0
- JSInitializeCallback initialize;
- JSFinalizeCallback finalize;
- JSHasPropertyCallback hasProperty;
- JSGetPropertyCallback getProperty;
- JSSetPropertyCallback setProperty;
- JSDeletePropertyCallback deleteProperty;
- JSGetPropertyListCallback getPropertyList;
- JSCallAsFunctionCallback callAsFunction;
- JSCallAsConstructorCallback callAsConstructor;
- JSConvertToTypeCallback convertToType;
+ int version; // current (and only) version is 0
+ JSObjectInitializeCallback initialize;
+ JSObjectFinalizeCallback finalize;
+ JSObjectHasPropertyCallback hasProperty;
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
+ JSObjectDeletePropertyCallback deleteProperty;
+ JSObjectAddPropertiesToListCallback addPropertiesToList;
+ JSObjectCallAsFunctionCallback callAsFunction;
+ JSObjectCallAsConstructorCallback callAsConstructor;
+ JSObjectConvertToTypeCallback convertToType;
} JSObjectCallbacks;
/*!
@@ -269,14 +272,14 @@
@struct JSStaticValue
@abstract This structure describes a static value property.
@field name A null-terminated UTF8 string containing the property's name.
-@field getProperty A JSGetPropertyCallback to invoke when getting the property's value.
-@field setProperty A JSSetPropertyCallback to invoke when setting the property's value.
+@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
+@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value.
@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
*/
typedef struct {
const char* const name; // FIXME: convert UTF8
- JSGetPropertyCallback getProperty;
- JSSetPropertyCallback setProperty;
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
JSPropertyAttributes attributes;
} JSStaticValue;
@@ -284,22 +287,23 @@
@struct JSStaticFunction
@abstract This structure describes a static function property.
@field name A null-terminated UTF8 string containing the property's name.
-@field callAsFunction A JSCallAsFunctionCallback to invoke when the property is called as a function.
+@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
*/
typedef struct {
const char* const name; // FIXME: convert UTF8
- JSCallAsFunctionCallback callAsFunction;
+ JSObjectCallAsFunctionCallback callAsFunction;
JSPropertyAttributes attributes;
} JSStaticFunction;
/*!
@function
-@abstract Creates a JavaScript class suitable for use with JSObjectMake. Ownership follows the create rule.
+@abstract Creates a JavaScript class suitable for use with JSObjectMake
@param staticValues A JSStaticValue array representing the class's static value properties. Pass NULL to specify no static value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
@param staticFunctions A JSStaticFunction array representing the class's static function properties. Pass NULL to specify no static function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
@param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior.
@param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
+@result A JSClass with the given properties, callbacks, and parent class. Ownership follows the Create Rule.
@discussion The simplest and most efficient way to add custom properties to a class is by specifying static values and functions. Standard JavaScript practice calls for functions to be placed in prototype objects, so that they can be shared among objects.
*/
JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass);
@@ -331,40 +335,40 @@
@function
@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
@param context The execution context to use.
-@param callAsFunction The JSCallAsFunctionCallback to invoke when the function is called.
+@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
@result A JSObject that is an anonymous function. The object's prototype will be the default function prototype.
*/
-JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction);
+JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction);
/*!
@function
@abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation.
@param context The execution context to use.
-@param callAsConstructor The JSCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.
+@param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.
@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
*/
-JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor);
+JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor);
/*!
@function
@abstract Creates a function with a given script as its body.
@param context The execution context to use.
-@param body A JSInternalString containing the script to use as the function's body.
-@param sourceURL A JSInternalString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param body A JSString containing the script to use as the function's body.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
@result A JSObject that is an anonymous function, or NULL if body contains a syntax error. The returned object's prototype will be the default function prototype.
@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
*/
-JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
@function
@abstract Gets a short description of a JavaScript object.
@param context The execution context to use.
@param object The object whose description you want to get.
-@result A JSInternalString containing the object's description. This is usually the object's class name.
+@result A JSString containing the object's description. This is usually the object's class name.
*/
-JSInternalStringRef JSObjectGetDescription(JSObjectRef object);
+JSStringRef JSObjectGetDescription(JSObjectRef object);
/*!
@function
@@ -385,46 +389,46 @@
@function
@abstract Tests whether an object has a certain property.
@param object The JSObject to test.
-@param propertyName A JSInternalString containing the property's name.
+@param propertyName A JSString containing the property's name.
@result true if the object has a property whose name matches propertyName, otherwise false.
*/
-bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName);
+bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
/*!
@function
@abstract Gets a property from an object.
@param context The execution context to use.
@param object The JSObject whose property you want to get.
-@param propertyName A JSInternalString containing the property's name.
-@result The property's value, or NULL if the object does not have a property whose name matches propertyName.
+@param propertyName A JSString containing the property's name.
+@result The property's value if object has the property, otherwise NULL.
*/
-JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName);
+JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
/*!
@function
@abstract Sets a property on an object.
@param context The execution context to use.
@param object The JSObject whose property you want to set.
-@param propertyName A JSInternalString containing the property's name.
+@param propertyName A JSString containing the property's name.
@param value A JSValue to use as the property's value.
@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
@result true if the set operation succeeds, otherwise false (for example, if the object already has a property of the given name with the kJSPropertyAttributeReadOnly attribute set).
*/
-bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);
+bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);
/*!
@function
@abstract Deletes a property from an object.
@param context The execution context to use.
@param object The JSObject whose property you want to delete.
-@param propertyName A JSInternalString containing the property's name.
+@param propertyName A JSString containing the property's name.
@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
*/
-bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName);
+bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
/*!
@function
@abstract Gets a pointer to private data from an object.
@param object A JSObject whose private data you want to get.
-@result A void* that points to the object's private data, or NULL if the object has no private data.
-@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake.
+@result A void* that points to the object's private data, if the object has private data, otherwise NULL.
+@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.
*/
void* JSObjectGetPrivate(JSObjectRef object);
/*!
@@ -433,7 +437,7 @@
@param object A JSObject whose private data you want to set.
@param data A void* that points to the object's private data.
@result true if the set operation succeeds, otherwise false.
-@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake.
+@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.
*/
bool JSObjectSetPrivate(JSObjectRef object, void* data);
@@ -480,7 +484,7 @@
@abstract Creates an enumerator for an object's properties.
@param context The execution context to use.
@param object The object whose properties you want to enumerate.
-@result A JSPropertyEnumerator with a list of object's properties. Ownership follows the create rule.
+@result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule.
*/
JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object);
/*!
@@ -500,19 +504,19 @@
@function
@abstract Gets a property enumerator's next property.
@param enumerator The JSPropertyEnumerator whose next property you want to get.
-@result A JSInternalString containing the property's name, or NULL if all properties have been enumerated.
+@result A JSString containing the property's name, or NULL if all properties have been enumerated.
*/
-JSInternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator);
+JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator);
/*!
@function
@abstract Adds a property to a property list.
-@discussion Use this method inside a JSGetPropertyListCallback to add a custom property to an object's property list.
+@discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a custom property to an object's property list.
@param propertyList The JSPropertyList to which you want to add a property.
@param thisObject The JSObject to which the property belongs.
-@param propertyName A JSInternalString specifying the property's name.
+@param propertyName A JSString specifying the property's name.
*/
-void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSInternalStringRef propertyName);
+void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName);
#ifdef __cplusplus
}
diff --git a/JavaScriptCore/API/JSValueRef.cpp b/JavaScriptCore/API/JSValueRef.cpp
index 9779a8a..68d8ba1 100644
--- a/JavaScriptCore/API/JSValueRef.cpp
+++ b/JavaScriptCore/API/JSValueRef.cpp
@@ -39,23 +39,21 @@
#include <algorithm> // for std::min
-using namespace KJS;
-
-JSTypeCode JSValueGetType(JSValueRef value)
+JSType JSValueGetType(JSValueRef value)
{
- JSValue* jsValue = toJS(value);
+ KJS::JSValue* jsValue = toJS(value);
switch (jsValue->type()) {
- case UndefinedType:
+ case KJS::UndefinedType:
return kJSTypeUndefined;
- case NullType:
+ case KJS::NullType:
return kJSTypeNull;
- case BooleanType:
+ case KJS::BooleanType:
return kJSTypeBoolean;
- case NumberType:
+ case KJS::NumberType:
return kJSTypeNumber;
- case StringType:
+ case KJS::StringType:
return kJSTypeString;
- case ObjectType:
+ case KJS::ObjectType:
return kJSTypeObject;
default:
ASSERT(!"JSValueGetType: unknown type code.\n");
@@ -63,6 +61,8 @@
}
}
+using namespace KJS; // placed here to avoid conflict between KJS::JSType and JSType, above.
+
bool JSValueIsUndefined(JSValueRef value)
{
JSValue* jsValue = toJS(value);
@@ -135,7 +135,7 @@
return result;
}
-bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor)
+bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor)
{
ExecState* exec = toJS(context);
JSValue* jsValue = toJS(value);
@@ -148,25 +148,22 @@
return result;
}
-JSValueRef JSUndefinedMake()
+JSValueRef JSValueMakeUndefined()
{
- JSLock lock;
return toRef(jsUndefined());
}
-JSValueRef JSNullMake()
+JSValueRef JSValueMakeNull()
{
- JSLock lock;
return toRef(jsNull());
}
-JSValueRef JSBooleanMake(bool value)
+JSValueRef JSValueMakeBoolean(bool value)
{
- JSLock lock;
return toRef(jsBoolean(value));
}
-JSValueRef JSNumberMake(double value)
+JSValueRef JSValueMakeNumber(double value)
{
JSLock lock;
return toRef(jsNumber(value));
@@ -178,7 +175,12 @@
ExecState* exec = toJS(context);
JSValue* jsValue = toJS(value);
- return jsValue->toBoolean(exec);
+ bool boolean = jsValue->toBoolean(exec);
+ if (exec->hadException()) {
+ exec->clearException();
+ boolean = false;
+ }
+ return boolean;
}
double JSValueToNumber(JSContextRef context, JSValueRef value)
@@ -209,21 +211,21 @@
return objectRef;
}
-void JSGCProtect(JSValueRef value)
+void JSValueProtect(JSValueRef value)
{
JSLock lock;
JSValue* jsValue = toJS(value);
gcProtect(jsValue);
}
-void JSGCUnprotect(JSValueRef value)
+void JSValueUnprotect(JSValueRef value)
{
JSLock lock;
JSValue* jsValue = toJS(value);
gcUnprotect(jsValue);
}
-void JSGCCollect()
+void JSGarbageCollect()
{
JSLock lock;
Collector::collect();
diff --git a/JavaScriptCore/API/JSValueRef.h b/JavaScriptCore/API/JSValueRef.h
index d3bfc06..7ff06a9 100644
--- a/JavaScriptCore/API/JSValueRef.h
+++ b/JavaScriptCore/API/JSValueRef.h
@@ -29,8 +29,10 @@
#include <JavaScriptCore/JSBase.h>
+#include <stdbool.h>
+
/*!
-@enum JSTypeCode
+@enum JSType
@abstract A constant identifying the type of a JSValue.
@constant kJSTypeUndefined The unique undefined value.
@constant kJSTypeNull The unique null value.
@@ -46,7 +48,7 @@
kJSTypeNumber,
kJSTypeString,
kJSTypeObject
-} JSTypeCode;
+} JSType;
#ifdef __cplusplus
extern "C" {
@@ -54,11 +56,11 @@
/*!
@function
-@abstract Returns a JavaScript value's type code.
+@abstract Returns a JavaScript value's type.
@param value The JSValue whose type you want to obtain.
-@result A value of type JSTypeCode that identifies value's type.
+@result A value of type JSType that identifies value's type.
*/
-JSTypeCode JSValueGetType(JSValueRef value);
+JSType JSValueGetType(JSValueRef value);
/*!
@function
@@ -150,7 +152,7 @@
@result true if value is an object constructed by constructor, as compared
by the JS instanceof operator, otherwise false.
*/
-bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor);
+bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor);
// Creating values
@@ -159,40 +161,40 @@
@abstract Creates a JavaScript value of the undefined type.
@result The unique undefined value.
*/
-JSValueRef JSUndefinedMake(void);
+JSValueRef JSValueMakeUndefined(void);
/*!
@function
@abstract Creates a JavaScript value of the null type.
@result The unique null value.
*/
-JSValueRef JSNullMake(void);
+JSValueRef JSValueMakeNull(void);
/*!
@function
@abstract Creates a JavaScript value of the boolean type.
-@param value The boolean value to assign to the newly created JSValue.
-@result A JSValue of the boolean type, representing the boolean value of value.
+@param boolean The bool to assign to the newly created JSValue.
+@result A JSValue of the boolean type, representing the value of boolean.
*/
-JSValueRef JSBooleanMake(bool value);
+JSValueRef JSValueMakeBoolean(bool boolean);
/*!
@function
@abstract Creates a JavaScript value of the number type.
-@param value The numeric value to assign to the newly created JSValue.
-@result A JSValue of the number type, representing the numeric value of value.
+@param number The double to assign to the newly created JSValue.
+@result A JSValue of the number type, representing the value of number.
*/
-JSValueRef JSNumberMake(double value);
+JSValueRef JSValueMakeNumber(double number);
/*!
@function
@abstract Creates a JavaScript value of the string type.
-@param string The JSInternalString to assign to the newly created JSValue. The
+@param string The JSString to assign to the newly created JSValue. The
newly created JSValue retains string, and releases it upon garbage collection.
-@result A JSValue of the string type, representing the string value of string.
+@result A JSValue of the string type, representing the value of string.
*/
-JSValueRef JSStringMake(JSInternalStringRef string);
+JSValueRef JSValueMakeString(JSStringRef string);
// Converting to primitive values
@@ -216,14 +218,12 @@
/*!
@function
-@abstract Converts a JavaScript value to string and copies the resulting
- string into a newly allocated JavaScript string.
+@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
@param context The execution context to use.
@param value The JSValue to convert.
-@result A JSInternalString containing the result of conversion, or an empty
- string if conversion fails. Ownership follows the copy rule.
+@result A JSString with the result of conversion, or an empty string if conversion fails. Ownership follows the Create Rule.
*/
-JSInternalStringRef JSValueCopyStringValue(JSContextRef context, JSValueRef value);
+JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value);
/*!
@function
@@ -242,7 +242,7 @@
@discussion A value may be protected multiple times and must be unprotected an
equal number of times before becoming eligible for garbage collection.
*/
-void JSGCProtect(JSValueRef value);
+void JSValueProtect(JSValueRef value);
/*!
@function
@@ -251,17 +251,19 @@
@discussion A value may be protected multiple times and must be unprotected an
equal number of times before becoming eligible for garbage collection.
*/
-void JSGCUnprotect(JSValueRef value);
+void JSValueUnprotect(JSValueRef value);
/*!
@function
@abstract Performs a JavaScript garbage collection.
@discussion JavaScript values that are on the machine stack, in a register,
- protected by JSGCProtect, set as the global object of an execution context, or reachable from any such
- value will not be collected. It is not normally necessary to call this function
- directly; the JS runtime will garbage collect as needed.
+ protected by JSValueProtect, set as the global object of an execution context,
+ or reachable from any such value will not be collected.
+
+ You are not required to call this function; the JavaScript engine will garbage
+ collect as needed.
*/
-void JSGCCollect(void);
+void JSGarbageCollect(void);
#ifdef __cplusplus
}
diff --git a/JavaScriptCore/API/JavaScriptCore.h b/JavaScriptCore/API/JavaScriptCore.h
index 8830a0c..4cbc779 100644
--- a/JavaScriptCore/API/JavaScriptCore.h
+++ b/JavaScriptCore/API/JavaScriptCore.h
@@ -27,12 +27,9 @@
#ifndef JavaScriptCore_h
#define JavaScriptCore_h
-#include <stdbool.h>
-#include <stddef.h> // for size_t
-
#include <JavaScriptCore/JSBase.h>
-#include <JavaScriptCore/JSInternalStringRef.h>
#include <JavaScriptCore/JSContextRef.h>
+#include <JavaScriptCore/JSInternalStringRef.h>
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSValueRef.h>
diff --git a/JavaScriptCore/API/minidom.c b/JavaScriptCore/API/minidom.c
index 57d8ec9..0f262f3 100644
--- a/JavaScriptCore/API/minidom.c
+++ b/JavaScriptCore/API/minidom.c
@@ -39,29 +39,29 @@
JSContextRef context = JSContextCreate(NULL);
JSObjectRef globalObject = JSContextGetGlobalObject(context);
- JSInternalStringRef printIString = JSInternalStringCreateUTF8("print");
- JSObjectSetProperty(context, globalObject, printIString, JSFunctionMake(context, print), kJSPropertyAttributeNone);
- JSInternalStringRelease(printIString);
+ JSStringRef printIString = JSStringCreateWithUTF8CString("print");
+ JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunction(context, print), kJSPropertyAttributeNone);
+ JSStringRelease(printIString);
- JSInternalStringRef node = JSInternalStringCreateUTF8("Node");
- JSObjectSetProperty(context, globalObject, node, JSConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone);
- JSInternalStringRelease(node);
+ JSStringRef node = JSStringCreateWithUTF8CString("Node");
+ JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_construct), kJSPropertyAttributeNone);
+ JSStringRelease(node);
char* scriptUTF8 = createStringWithContentsOfFile("minidom.js");
- JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
+ JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
JSValueRef exception;
JSValueRef result = JSEvaluate(context, script, NULL, NULL, 0, &exception);
if (result)
printf("PASS: Test script executed successfully.\n");
else {
printf("FAIL: Test script threw exception:\n");
- JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
- CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
+ JSStringRef exceptionIString = JSValueToStringCopy(context, exception);
+ CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
CFShow(exceptionCF);
CFRelease(exceptionCF);
- JSInternalStringRelease(exceptionIString);
+ JSStringRelease(exceptionIString);
}
- JSInternalStringRelease(script);
+ JSStringRelease(script);
free(scriptUTF8);
#if 0 // used for leak/finalize debugging
@@ -70,7 +70,7 @@
JSObjectRef o = JSObjectMake(context, NULL, NULL);
(void)o;
}
- JSGCCollect();
+ JSGarbageCollect();
#endif
JSContextDestroy(context);
@@ -81,14 +81,14 @@
static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception)
{
if (argc > 0) {
- JSInternalStringRef string = JSValueCopyStringValue(context, argv[0]);
- size_t numChars = JSInternalStringGetMaxLengthUTF8(string);
+ JSStringRef string = JSValueToStringCopy(context, argv[0]);
+ size_t numChars = JSStringGetMaximumUTF8CStringSize(string);
char stringUTF8[numChars];
- JSInternalStringGetCharactersUTF8(string, stringUTF8, numChars);
+ JSStringGetUTF8CString(string, stringUTF8, numChars);
printf("%s\n", stringUTF8);
}
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static char* createStringWithContentsOfFile(const char* fileName)
diff --git a/JavaScriptCore/API/testapi.c b/JavaScriptCore/API/testapi.c
index 023126d..27f42bc 100644
--- a/JavaScriptCore/API/testapi.c
+++ b/JavaScriptCore/API/testapi.c
@@ -51,11 +51,11 @@
static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
{
- JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
+ JSStringRef valueAsString = JSValueToStringCopy(context, value);
- size_t jsSize = JSInternalStringGetMaxLengthUTF8(valueAsString);
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
char jsBuffer[jsSize];
- JSInternalStringGetCharactersUTF8(valueAsString, jsBuffer, jsSize);
+ JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
if (strcmp(jsBuffer, expectedValue) != 0)
fprintf(stderr, "assertEqualsAsUTF8String strcmp failed: %s != %s\n", jsBuffer, expectedValue);
@@ -63,16 +63,16 @@
if (jsSize < strlen(jsBuffer) + 1)
fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
- JSInternalStringRelease(valueAsString);
+ JSStringRelease(valueAsString);
}
#if defined(__APPLE__)
static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
{
- JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
+ JSStringRef valueAsString = JSValueToStringCopy(context, value);
- size_t jsLength = JSInternalStringGetLength(valueAsString);
- const JSChar* jsBuffer = JSInternalStringGetCharactersPtr(valueAsString);
+ size_t jsLength = JSStringGetLength(valueAsString);
+ const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
expectedValue,
@@ -88,36 +88,12 @@
if (jsLength != (size_t)cfLength)
fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
- JSInternalStringRelease(valueAsString);
+ JSStringRelease(valueAsString);
}
-static void assertEqualsAsCharacters(JSValueRef value, const char* expectedValue)
-{
- JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
-
- size_t jsLength = JSInternalStringGetLength(valueAsString);
- JSChar jsBuffer[jsLength];
- JSInternalStringGetCharacters(valueAsString, jsBuffer, jsLength);
-
- 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, "assertEqualsAsCharacters failed: jsBuffer != cfBuffer\n");
-
- if (jsLength != (size_t)cfLength)
- fprintf(stderr, "assertEqualsAsCharacters failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
-
- JSInternalStringRelease(valueAsString);
-}
#endif // __APPLE__
-static JSValueRef jsGlobalValue; // non-stack value for testing JSGCProtect()
+static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect()
/* MyObject pseudo-class */
@@ -129,61 +105,58 @@
didInitialize = true;
}
-static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception)
+static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(object);
- if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")
- || JSInternalStringIsEqualUTF8(propertyName, "cantFind")
- || JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {
+ if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")
+ || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
+ || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
return true;
}
return false;
}
-static bool MyObject_getProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(object);
- if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")) {
- *returnValue = JSNumberMake(1);
- return true;
+ if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
+ return JSValueMakeNumber(1);
}
- if (JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {
- *returnValue = JSNumberMake(1);
- return true;
+ if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
+ return JSValueMakeNumber(1);
}
- if (JSInternalStringIsEqualUTF8(propertyName, "cantFind")) {
- *returnValue = JSUndefinedMake();
- return true;
+ if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
+ return JSValueMakeUndefined();
}
- return false;
+ return NULL;
}
-static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception)
+static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(object);
UNUSED_PARAM(value);
- if (JSInternalStringIsEqualUTF8(propertyName, "cantSet"))
+ 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, JSInternalStringRef propertyName, JSValueRef* exception)
+static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(object);
- if (JSInternalStringIsEqualUTF8(propertyName, "cantDelete"))
+ if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete"))
return true;
return false;
@@ -193,15 +166,15 @@
{
UNUSED_PARAM(context);
- JSInternalStringRef propertyName;
+ JSStringRef propertyName;
- propertyName = JSInternalStringCreateUTF8("alwaysOne");
+ propertyName = JSStringCreateWithUTF8CString("alwaysOne");
JSPropertyListAdd(propertyList, object, propertyName);
- JSInternalStringRelease(propertyName);
+ JSStringRelease(propertyName);
- propertyName = JSInternalStringCreateUTF8("myPropertyName");
+ propertyName = JSStringCreateWithUTF8CString("myPropertyName");
JSPropertyListAdd(propertyList, object, propertyName);
- JSInternalStringRelease(propertyName);
+ JSStringRelease(propertyName);
}
static JSValueRef MyObject_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception)
@@ -210,10 +183,10 @@
UNUSED_PARAM(object);
UNUSED_PARAM(thisObject);
- if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSNumberMake(0)))
- return JSNumberMake(1);
+ if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0)))
+ return JSValueMakeNumber(1);
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static JSObjectRef MyObject_callAsConstructor(JSContextRef context, JSObjectRef object, size_t argc, JSValueRef argv[], JSValueRef* exception)
@@ -221,30 +194,28 @@
UNUSED_PARAM(context);
UNUSED_PARAM(object);
- if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSNumberMake(0)))
- return JSValueToObject(context, JSNumberMake(1));
+ if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0)))
+ return JSValueToObject(context, JSValueMakeNumber(1));
- return JSValueToObject(context, JSNumberMake(0));
+ return JSValueToObject(context, JSValueMakeNumber(0));
}
-static bool MyObject_convertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception)
+static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
{
UNUSED_PARAM(context);
UNUSED_PARAM(object);
- switch (typeCode) {
+ switch (type) {
case kJSTypeBoolean:
- *returnValue = JSBooleanMake(false); // default object conversion is 'true'
- return true;
+ return JSValueMakeBoolean(false); // default object conversion is 'true'
case kJSTypeNumber:
- *returnValue = JSNumberMake(1);
- return true;
+ return JSValueMakeNumber(1);
default:
break;
}
- // string
- return false;
+ // string conversion -- forward to default object class
+ return NULL;
}
static bool didFinalize = false;
@@ -285,15 +256,15 @@
UNUSED_PARAM(thisObject);
if (argc > 0) {
- JSInternalStringRef string = JSValueCopyStringValue(context, argv[0]);
- size_t sizeUTF8 = JSInternalStringGetMaxLengthUTF8(string);
+ JSStringRef string = JSValueToStringCopy(context, argv[0]);
+ size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
char stringUTF8[sizeUTF8];
- JSInternalStringGetCharactersUTF8(string, stringUTF8, sizeUTF8);
+ JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
printf("%s\n", stringUTF8);
- JSInternalStringRelease(string);
+ JSStringRelease(string);
}
- return JSUndefinedMake();
+ return JSValueMakeUndefined();
}
static JSObjectRef myConstructor_callAsConstructor(JSContextRef context, JSObjectRef constructorObject, size_t argc, JSValueRef argv[], JSValueRef* exception)
@@ -302,9 +273,9 @@
JSObjectRef result = JSObjectMake(context, NULL, 0);
if (argc > 0) {
- JSInternalStringRef value = JSInternalStringCreateUTF8("value");
+ JSStringRef value = JSStringCreateWithUTF8CString("value");
JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone);
- JSInternalStringRelease(value);
+ JSStringRelease(value);
}
return result;
@@ -319,21 +290,21 @@
context = JSContextCreate(NULL);
- JSValueRef jsUndefined = JSUndefinedMake();
- JSValueRef jsNull = JSNullMake();
- JSValueRef jsTrue = JSBooleanMake(true);
- JSValueRef jsFalse = JSBooleanMake(false);
- JSValueRef jsZero = JSNumberMake(0);
- JSValueRef jsOne = JSNumberMake(1);
- JSValueRef jsOneThird = JSNumberMake(1.0 / 3.0);
- JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSNullMake());
+ JSValueRef jsUndefined = JSValueMakeUndefined();
+ JSValueRef jsNull = JSValueMakeNull();
+ JSValueRef jsTrue = JSValueMakeBoolean(true);
+ JSValueRef jsFalse = JSValueMakeBoolean(false);
+ JSValueRef jsZero = JSValueMakeNumber(0);
+ JSValueRef jsOne = JSValueMakeNumber(1);
+ JSValueRef jsOneThird = JSValueMakeNumber(1.0 / 3.0);
+ JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull());
// FIXME: test funny utf8 characters
- JSInternalStringRef jsEmptyIString = JSInternalStringCreateUTF8("");
- JSValueRef jsEmptyString = JSStringMake(jsEmptyIString);
+ JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
+ JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString);
- JSInternalStringRef jsOneIString = JSInternalStringCreateUTF8("1");
- JSValueRef jsOneString = JSStringMake(jsOneIString);
+ JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
+ JSValueRef jsOneString = JSValueMakeString(jsOneIString);
#if defined(__APPLE__)
UniChar singleUniChar = 65; // Capital A
@@ -344,24 +315,24 @@
1,
kCFAllocatorNull);
- JSInternalStringRef jsCFIString = JSInternalStringCreateCF(cfString);
- JSValueRef jsCFString = JSStringMake(jsCFIString);
+ JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
+ JSValueRef jsCFString = JSValueMakeString(jsCFIString);
CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
- JSInternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString);
- JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyIString);
+ JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
+ JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString);
CFIndex cfStringLength = CFStringGetLength(cfString);
UniChar buffer[cfStringLength];
CFStringGetCharacters(cfString,
CFRangeMake(0, cfStringLength),
buffer);
- JSInternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength);
- JSValueRef jsCFStringWithCharacters = JSStringMake(jsCFIStringWithCharacters);
+ JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
+ JSValueRef jsCFStringWithCharacters = JSValueMakeString(jsCFIStringWithCharacters);
- JSInternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));
- JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmptyIStringWithCharacters);
+ JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
+ JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(jsCFEmptyIStringWithCharacters);
#endif // __APPLE__
assert(JSValueGetType(jsUndefined) == kJSTypeUndefined);
@@ -434,22 +405,6 @@
assertEqualsAsCharactersPtr(jsCFEmptyStringWithCharacters, "");
#endif // __APPLE__
- assertEqualsAsCharacters(jsUndefined, "undefined");
- assertEqualsAsCharacters(jsNull, "null");
- assertEqualsAsCharacters(jsTrue, "true");
- assertEqualsAsCharacters(jsFalse, "false");
- assertEqualsAsCharacters(jsZero, "0");
- assertEqualsAsCharacters(jsOne, "1");
- assertEqualsAsCharacters(jsOneThird, "0.3333333333333333");
- assertEqualsAsCharacters(jsEmptyString, "");
- assertEqualsAsCharacters(jsOneString, "1");
-#if defined(__APPLE__)
- assertEqualsAsCharacters(jsCFString, "A");
- assertEqualsAsCharacters(jsCFStringWithCharacters, "A");
- assertEqualsAsCharacters(jsCFEmptyString, "");
- assertEqualsAsCharacters(jsCFEmptyStringWithCharacters, "");
-#endif // __APPLE__
-
assertEqualsAsUTF8String(jsUndefined, "undefined");
assertEqualsAsUTF8String(jsNull, "null");
assertEqualsAsUTF8String(jsTrue, "true");
@@ -473,8 +428,8 @@
assert(!JSValueIsEqual(context, jsTrue, jsFalse));
#if defined(__APPLE__)
- CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFIString);
- CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyIString);
+ CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString);
+ CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString);
assert(CFEqual(cfJSString, cfString));
assert(CFEqual(cfJSEmptyString, cfEmptyString));
CFRelease(cfJSString);
@@ -485,18 +440,18 @@
#endif // __APPLE__
jsGlobalValue = JSObjectMake(context, NULL, NULL);
- JSGCProtect(jsGlobalValue);
- JSGCCollect();
+ JSValueProtect(jsGlobalValue);
+ JSGarbageCollect();
assert(JSValueIsObject(jsGlobalValue));
- JSGCUnprotect(jsGlobalValue);
+ JSValueUnprotect(jsGlobalValue);
/* JSInterpreter.h */
JSObjectRef globalObject = JSContextGetGlobalObject(context);
assert(JSValueIsObject(globalObject));
- JSInternalStringRef goodSyntax = JSInternalStringCreateUTF8("x = 1;");
- JSInternalStringRef badSyntax = JSInternalStringCreateUTF8("x := 1;");
+ JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
+ JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
assert(JSCheckSyntax(context, goodSyntax, NULL, 0, NULL));
assert(!JSCheckSyntax(context, badSyntax, NULL, 0, NULL));
@@ -514,32 +469,32 @@
assert(!result);
assert(JSValueIsObject(exception));
- JSInternalStringRef array = JSInternalStringCreateUTF8("Array");
+ JSStringRef array = JSStringCreateWithUTF8CString("Array");
v = JSObjectGetProperty(context, globalObject, array);
assert(v);
JSObjectRef arrayConstructor = JSValueToObject(context, v);
- JSInternalStringRelease(array);
+ JSStringRelease(array);
result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
assert(result);
- assert(JSValueIsInstanceOf(context, result, arrayConstructor));
- assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor));
+ assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor));
+ assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor));
- JSInternalStringRef functionBody;
+ JSStringRef functionBody;
exception = NULL;
- functionBody = JSInternalStringCreateUTF8("rreturn Array;");
- JSInternalStringRef line = JSInternalStringCreateUTF8("line");
- assert(!JSFunctionMakeWithBody(context, functionBody, NULL, 1, &exception));
+ functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
+ JSStringRef line = JSStringCreateWithUTF8CString("line");
+ assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception));
assert(JSValueIsObject(exception));
v = JSObjectGetProperty(context, JSValueToObject(context, exception), line);
assert(v);
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)
- JSInternalStringRelease(functionBody);
- JSInternalStringRelease(line);
+ JSStringRelease(functionBody);
+ JSStringRelease(line);
- functionBody = JSInternalStringCreateUTF8("return Array;");
- JSObjectRef function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
- JSInternalStringRelease(functionBody);
+ functionBody = JSStringCreateWithUTF8CString("return Array;");
+ JSObjectRef function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL);
+ JSStringRelease(functionBody);
assert(JSObjectIsFunction(function));
v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
@@ -547,32 +502,32 @@
JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
assert(didInitialize);
- JSInternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject");
+ JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone);
- JSInternalStringRelease(myObjectIString);
+ JSStringRelease(myObjectIString);
- JSInternalStringRef print = JSInternalStringCreateUTF8("print");
- JSObjectRef printFunction = JSFunctionMake(context, print_callAsFunction);
+ JSStringRef print = JSStringCreateWithUTF8CString("print");
+ JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction);
JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone);
- JSInternalStringRelease(print);
+ JSStringRelease(print);
assert(JSObjectSetPrivate(printFunction, (void*)1));
assert(JSObjectGetPrivate(printFunction) == (void*)1);
- JSInternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor");
- JSObjectRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor);
+ JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
+ JSObjectRef myConstructor = JSObjectMakeConstructor(context, myConstructor_callAsConstructor);
JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone);
- JSInternalStringRelease(myConstructorIString);
+ JSStringRelease(myConstructorIString);
assert(JSObjectSetPrivate(myConstructor, (void*)1));
assert(JSObjectGetPrivate(myConstructor) == (void*)1);
o = JSObjectMake(context, NULL, NULL);
- JSObjectSetProperty(context, o, jsOneIString, JSNumberMake(1), kJSPropertyAttributeNone);
- JSObjectSetProperty(context, o, jsCFIString, JSNumberMake(1), kJSPropertyAttributeDontEnum);
+ JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone);
+ JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(1), kJSPropertyAttributeDontEnum);
JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o);
int count = 0;
- while (JSPropertyEnumeratorGetNext(enumerator))
+ while (JSPropertyEnumeratorGetNextName(enumerator))
++count;
JSPropertyEnumeratorRelease(enumerator);
assert(count == 1); // jsCFString should not be enumerated
@@ -580,46 +535,46 @@
JSClassRef nullCallbacksClass = JSClassCreate(NULL, NULL, NULL, NULL);
JSClassRelease(nullCallbacksClass);
- functionBody = JSInternalStringCreateUTF8("return this;");
- function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
- JSInternalStringRelease(functionBody);
+ functionBody = JSStringCreateWithUTF8CString("return this;");
+ function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL);
+ JSStringRelease(functionBody);
v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
assert(JSValueIsEqual(context, v, globalObject));
v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
assert(JSValueIsEqual(context, v, o));
char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
- JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
+ JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
result = JSEvaluate(context, script, NULL, NULL, 1, &exception);
if (JSValueIsUndefined(result))
printf("PASS: Test script executed successfully.\n");
else {
printf("FAIL: Test script returned unexcpected value:\n");
- JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
- CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
+ JSStringRef exceptionIString = JSValueToStringCopy(context, exception);
+ CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
CFShow(exceptionCF);
CFRelease(exceptionCF);
- JSInternalStringRelease(exceptionIString);
+ JSStringRelease(exceptionIString);
}
- JSInternalStringRelease(script);
+ JSStringRelease(script);
free(scriptUTF8);
// Allocate a few dummies so that at least one will be collected
JSObjectMake(context, MyObject_class(context), 0);
JSObjectMake(context, MyObject_class(context), 0);
- JSGCCollect();
+ JSGarbageCollect();
assert(didFinalize);
- JSInternalStringRelease(jsEmptyIString);
- JSInternalStringRelease(jsOneIString);
+ JSStringRelease(jsEmptyIString);
+ JSStringRelease(jsOneIString);
#if defined(__APPLE__)
- JSInternalStringRelease(jsCFIString);
- JSInternalStringRelease(jsCFEmptyIString);
- JSInternalStringRelease(jsCFIStringWithCharacters);
- JSInternalStringRelease(jsCFEmptyIStringWithCharacters);
+ JSStringRelease(jsCFIString);
+ JSStringRelease(jsCFEmptyIString);
+ JSStringRelease(jsCFIStringWithCharacters);
+ JSStringRelease(jsCFEmptyIStringWithCharacters);
#endif // __APPLE__
- JSInternalStringRelease(goodSyntax);
- JSInternalStringRelease(badSyntax);
+ JSStringRelease(goodSyntax);
+ JSStringRelease(badSyntax);
JSContextDestroy(context);
printf("PASS: Program exited normally.\n");
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index bff0b16..b7db2fe 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,40 @@
+2006-07-11 Geoffrey Garen <ggaren@apple.com>
+
+ Reviewed by Maciej.
+
+ - Implemented a vast number of renames and comment clarifications
+ suggested during API review.
+
+ JSInternalString -> JSString
+ JS*Make -> JSValueMake*, JSObjectMake*
+ JSTypeCode -> JSType
+ JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code)
+ JSGC*Protect -> JSValue*Protect
+ JS*Callback -> JSObject*Callback
+ JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback
+ JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName
+ JSString* ->
+ JSStringCreateWithUTF8CString, JSStringGetUTF8CString,
+ JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString,
+ JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters.
+
+ - Changed functions taking a JSValue out arg and returning a bool indicating
+ whether it was set to simply return a JSValue or NULL.
+
+ - Removed JSStringGetCharacters because it's more documentation than code,
+ and it's just a glorified memcpy built on existing API functionality.
+
+ - Moved standard library includes into the headers that actually require them.
+
+ - Standardized use of the phrase "Create Rule."
+
+ - Removed JSLock from make functions that don't allocate.
+
+ - Added exception handling to JSValueToBoolean, since we now allow
+ callback objects to throw exceptions upon converting to boolean.
+
+ - Renamed JSGCCollect to JSGarbageCollect.
+
2006-07-10 Geoffrey Garen <ggaren@apple.com>
Reviewed by Darin.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index 437da3d..620bb19 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -1,36 +1,15 @@
.objc_class_name_WebScriptObject
.objc_class_name_WebScriptObjectPrivate
.objc_class_name_WebUndefined
-_CFStringCreateWithJSInternalString
-_JSBooleanMake
_JSCheckSyntax
_JSClassCreate
_JSClassRelease
_JSClassRetain
-_JSConstructorMake
_JSContextCreate
_JSContextDestroy
_JSContextGetGlobalObject
_JSEvaluate
-_JSFunctionMake
-_JSFunctionMakeWithBody
-_JSGCCollect
-_JSGCProtect
-_JSGCUnprotect
-_JSInternalStringCreate
-_JSInternalStringCreateCF
-_JSInternalStringCreateUTF8
-_JSInternalStringGetCharacters
-_JSInternalStringGetCharactersPtr
-_JSInternalStringGetCharactersUTF8
-_JSInternalStringGetLength
-_JSInternalStringGetMaxLengthUTF8
-_JSInternalStringIsEqual
-_JSInternalStringIsEqualUTF8
-_JSInternalStringRelease
-_JSInternalStringRetain
-_JSNullMake
-_JSNumberMake
+_JSGarbageCollect
_JSObjectCallAsConstructor
_JSObjectCallAsFunction
_JSObjectCreatePropertyEnumerator
@@ -43,20 +22,32 @@
_JSObjectIsConstructor
_JSObjectIsFunction
_JSObjectMake
+_JSObjectMakeConstructor
+_JSObjectMakeFunction
+_JSObjectMakeFunctionWithBody
_JSObjectSetPrivate
_JSObjectSetProperty
_JSObjectSetPrototype
-_JSPropertyEnumeratorGetNext
+_JSPropertyEnumeratorGetNextName
_JSPropertyEnumeratorRelease
_JSPropertyEnumeratorRetain
_JSPropertyListAdd
-_JSStringMake
-_JSUndefinedMake
-_JSValueCopyStringValue
+_JSStringCopyCFString
+_JSStringCreateWithCFString
+_JSStringCreateWithCharacters
+_JSStringCreateWithUTF8CString
+_JSStringGetCharactersPtr
+_JSStringGetLength
+_JSStringGetMaximumUTF8CStringSize
+_JSStringGetUTF8CString
+_JSStringIsEqual
+_JSStringIsEqualToUTF8CString
+_JSStringRelease
+_JSStringRetain
_JSValueGetType
_JSValueIsBoolean
_JSValueIsEqual
-_JSValueIsInstanceOf
+_JSValueIsInstanceOfConstructor
_JSValueIsNull
_JSValueIsNumber
_JSValueIsObject
@@ -64,9 +55,17 @@
_JSValueIsStrictEqual
_JSValueIsString
_JSValueIsUndefined
+_JSValueMakeBoolean
+_JSValueMakeNull
+_JSValueMakeNumber
+_JSValueMakeString
+_JSValueMakeUndefined
+_JSValueProtect
_JSValueToBoolean
_JSValueToNumber
_JSValueToObject
+_JSValueToStringCopy
+_JSValueUnprotect
_KJS_JSCreateNativeJSObject
_KJS_JSObject_JSFinalize
_KJS_JSObject_JSObjectCall