using namespace KJS;
-JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsThisObject = toJS(thisObject);
UString::Rep* scriptRep = toJS(script);
UString::Rep* sourceURLRep = toJS(sourceURL);
return toRef(jsUndefined());
}
-bool JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
UString::Rep* scriptRep = toJS(script);
UString::Rep* sourceURLRep = toJS(sourceURL);
Completion completion = exec->dynamicInterpreter()->checkSyntax(UString(sourceURLRep), startingLineNumber, UString(scriptRep));
return true;
}
-void JSGarbageCollect()
+void JSGarbageCollect(JSContextRef)
{
JSLock lock;
Collector::collect();
/*!
@function
@abstract Evaluates a string of JavaScript.
-@param context The execution context to use.
+@param ctx The execution context to use.
@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 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 exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The JSValue that results from evaluating script, or NULL if an exception is thrown.
*/
-JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
@function JSCheckScriptSyntax
@abstract Checks for syntax errors in a string of JavaScript.
-@param context The execution context to use.
+@param ctx The execution context to use.
@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 JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
@function
@abstract Performs a JavaScript garbage collection.
+@param ctx The execution context to use.
@discussion JavaScript values that are on the machine stack, in a register,
protected by JSValueProtect, set as the global object of an execution context,
or reachable from any such value will not be collected.
You are not required to call this function; the JavaScript engine will garbage
collect as needed.
*/
-void JSGarbageCollect(void);
+void JSGarbageCollect(JSContextRef ctx);
#ifdef __cplusplus
}
const ClassInfo JSCallbackObject::info = { "CallbackObject", 0, 0, 0 };
-JSCallbackObject::JSCallbackObject(JSContextRef context, JSClassRef jsClass)
+JSCallbackObject::JSCallbackObject(JSContextRef ctx, JSClassRef jsClass)
: JSObject()
{
- init(context, jsClass);
+ init(ctx, jsClass);
}
-JSCallbackObject::JSCallbackObject(JSContextRef context, JSClassRef jsClass, JSValue* prototype)
+JSCallbackObject::JSCallbackObject(JSContextRef ctx, JSClassRef jsClass, JSValue* prototype)
: JSObject(prototype)
{
- init(context, jsClass);
+ init(ctx, jsClass);
}
-void JSCallbackObject::init(JSContextRef context, JSClassRef jsClass)
+void JSCallbackObject::init(JSContextRef ctx, JSClassRef jsClass)
{
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
m_privateData = 0;
m_class = JSClassRetain(jsClass);
do {
if (JSObjectInitializeCallback initialize = jsClass->initialize)
- initialize(context, thisRef, toRef(exec->exceptionSlot()));
+ initialize(ctx, thisRef, toRef(exec->exceptionSlot()));
} while ((jsClass = jsClass->parentClass));
}
bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- JSContextRef context = toRef(exec);
+ JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
// optional optimization to bypass getProperty in cases when we only need to know if the property exists
if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
- if (hasProperty(context, thisRef, propertyNameRef)) {
+ if (hasProperty(ctx, thisRef, propertyNameRef)) {
slot.setCustom(this, callbackGetter);
return true;
}
} else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
- if (JSValueRef value = getProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
+ if (JSValueRef value = getProperty(ctx, 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.
void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
- JSContextRef context = toRef(exec);
+ JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
JSValueRef valueRef = toRef(value);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
- if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
+ if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
return;
}
if (entry->attributes & kJSPropertyAttributeReadOnly)
return;
if (JSObjectSetPropertyCallback setProperty = entry->setProperty)
- setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()));
+ setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()));
else
throwError(exec, ReferenceError, "Writable static value property defined with NULL setProperty callback.");
}
bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
- JSContextRef context = toRef(exec);
+ JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
- if (deleteProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
return true;
}
double JSCallbackObject::toNumber(ExecState* exec) const
{
- JSContextRef context = toRef(exec);
+ JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType)
- if (JSValueRef value = convertToType(context, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
+ if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
return toJS(value)->getNumber();
return JSObject::toNumber(exec);
UString JSCallbackObject::toString(ExecState* exec) const
{
- JSContextRef context = toRef(exec);
+ JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType)
- if (JSValueRef value = convertToType(context, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
+ if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
return toJS(value)->getString();
return JSObject::toString(exec);
globalObject = new JSObject();
Interpreter* interpreter = new Interpreter(globalObject); // adds the built-in object prototype to the global object
- JSGlobalContextRef context = reinterpret_cast<JSGlobalContextRef>(interpreter->globalExec());
- return JSGlobalContextRetain(context);
+ JSGlobalContextRef ctx = reinterpret_cast<JSGlobalContextRef>(interpreter->globalExec());
+ return JSGlobalContextRetain(ctx);
}
-JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef context)
+JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
exec->dynamicInterpreter()->ref();
- return context;
+ return ctx;
}
-void JSGlobalContextRelease(JSGlobalContextRef context)
+void JSGlobalContextRelease(JSGlobalContextRef ctx)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
exec->dynamicInterpreter()->deref();
}
-JSObjectRef JSContextGetGlobalObject(JSContextRef context)
+JSObjectRef JSContextGetGlobalObject(JSContextRef ctx)
{
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
return toRef(exec->dynamicInterpreter()->globalObject());
}
/*!
@function
@abstract Retains a global JavaScript execution context.
-@param context The JSGlobalContext to retain.
-@result A JSGlobalContext that is the same as context.
+@param ctx The JSGlobalContext to retain.
+@result A JSGlobalContext that is the same as ctx.
*/
-JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef context);
+JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx);
/*!
@function
@abstract Releases a global JavaScript execution context.
-@param context The JSGlobalContext to release.
+@param ctx The JSGlobalContext to release.
*/
-void JSGlobalContextRelease(JSGlobalContextRef context);
+void JSGlobalContextRelease(JSGlobalContextRef ctx);
/*!
@function
@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.
+@param ctx The JSContext whose global object you want to get.
+@result ctx's global object.
*/
-JSObjectRef JSContextGetGlobalObject(JSContextRef context);
+JSObjectRef JSContextGetGlobalObject(JSContextRef ctx);
#ifdef __cplusplus
}
UNUSED_PARAM(function);
// Example of throwing a type error for invalid values
- if (!JSValueIsObjectOfClass(thisObject, JSNode_class(context))) {
+ if (!JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes");
- *exception = JSValueMakeString(message);
+ *exception = JSValueMakeString(context, message);
JSStringRelease(message);
- } else if (argumentCount < 1 || !JSValueIsObjectOfClass(arguments[0], JSNode_class(context))) {
+ } else if (argumentCount < 1 || !JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node");
- *exception = JSValueMakeString(message);
+ *exception = JSValueMakeString(context, message);
JSStringRelease(message);
} else {
Node* node = JSObjectGetPrivate(thisObject);
Node_appendChild(node, child);
}
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSValueRef JSNodePrototype_removeChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
// Example of ignoring invalid values
if (argumentCount > 0) {
- if (JSValueIsObjectOfClass(thisObject, JSNode_class(context))) {
- if (JSValueIsObjectOfClass(arguments[0], JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
Node* node = JSObjectGetPrivate(thisObject);
Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], NULL));
}
}
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSValueRef JSNodePrototype_replaceChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
UNUSED_PARAM(function);
if (argumentCount > 1) {
- if (JSValueIsObjectOfClass(thisObject, JSNode_class(context))) {
- if (JSValueIsObjectOfClass(arguments[0], JSNode_class(context))) {
- if (JSValueIsObjectOfClass(arguments[1], JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, arguments[1], JSNode_class(context))) {
Node* node = JSObjectGetPrivate(thisObject);
Node* newChild = JSObjectGetPrivate(JSValueToObject(context, arguments[0], NULL));
Node* oldChild = JSObjectGetPrivate(JSValueToObject(context, arguments[1], NULL));
}
}
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSStaticFunction JSNodePrototype_staticFunctions[] = {
Node* node = JSObjectGetPrivate(object);
if (node) {
JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
- JSValueRef value = JSValueMakeString(nodeType);
+ JSValueRef value = JSValueMakeString(context, nodeType);
JSStringRelease(nodeType);
return value;
}
UNUSED_PARAM(propertyName);
UNUSED_PARAM(object);
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSStaticValue JSNode_staticValues[] = {
static JSObjectRef prototype;
if (!prototype) {
prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL);
- JSValueProtect(prototype);
+ JSValueProtect(context, prototype);
}
return prototype;
}
return JSNode_new(context, node);
}
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSStaticFunction JSNodeListPrototype_staticFunctions[] = {
NodeList* nodeList = JSObjectGetPrivate(thisObject);
assert(nodeList);
- return JSValueMakeNumber(NodeList_length(nodeList));
+ return JSValueMakeNumber(context, NodeList_length(nodeList));
}
static JSStaticValue JSNodeList_staticValues[] = {
{
NodeList* nodeList = JSObjectGetPrivate(thisObject);
assert(nodeList);
- double index = JSValueToNumber(context, JSValueMakeString(propertyName), exception);
+ double index = JSValueToNumber(context, JSValueMakeString(context, propertyName), exception);
unsigned uindex = index;
if (uindex == index) { // false for NaN
Node* node = NodeList_item(nodeList, uindex);
static JSObjectRef prototype;
if (!prototype) {
prototype = JSObjectMake(context, JSNodeListPrototype_class(context), NULL);
- JSValueProtect(prototype);
+ JSValueProtect(context, prototype);
}
return prototype;
}
delete jsClass;
}
-JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSValueRef prototype)
+JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSValue* jsPrototype = toJS(prototype);
if (!prototype)
if (!jsClass)
return toRef(new JSObject(jsPrototype)); // slightly more efficient
else
- return toRef(new JSCallbackObject(context, jsClass, jsPrototype));
+ return toRef(new JSCallbackObject(ctx, jsClass, jsPrototype));
}
-JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef context, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
+JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous");
return toRef(new JSCallbackFunction(exec, callAsFunction, nameID));
}
-JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor)
+JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSObjectCallAsConstructorCallback callAsConstructor)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
return toRef(new JSCallbackConstructor(exec, callAsConstructor));
}
-JSObjectRef JSObjectMakeFunction(JSContextRef context, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
UString::Rep* bodyRep = toJS(body);
UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
return toRef(result);
}
-JSValueRef JSObjectGetPrototype(JSObjectRef object)
+JSValueRef JSObjectGetPrototype(JSContextRef, JSObjectRef object)
{
JSObject* jsObject = toJS(object);
return toRef(jsObject->prototype());
}
-void JSObjectSetPrototype(JSObjectRef object, JSValueRef value)
+void JSObjectSetPrototype(JSContextRef, JSObjectRef object, JSValueRef value)
{
JSObject* jsObject = toJS(object);
JSValue* jsValue = toJS(value);
jsObject->setPrototype(jsValue);
}
-bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
UString::Rep* nameRep = toJS(propertyName);
return jsObject->hasProperty(exec, Identifier(nameRep));
}
-JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
UString::Rep* nameRep = toJS(propertyName);
return toRef(jsValue);
}
-void JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
+void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
UString::Rep* nameRep = toJS(propertyName);
JSValue* jsValue = toJS(value);
}
}
-JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
+JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
JSValue* jsValue = jsObject->get(exec, propertyIndex);
}
-void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
+void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
JSValue* jsValue = toJS(value);
}
}
-bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
UString::Rep* nameRep = toJS(propertyName);
return false;
}
-bool JSObjectIsFunction(JSObjectRef object)
+bool JSObjectIsFunction(JSContextRef, JSObjectRef object)
{
JSObject* jsObject = toJS(object);
return jsObject->implementsCall();
}
-JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
JSObject* jsThisObject = toJS(thisObject);
return result;
}
-bool JSObjectIsConstructor(JSObjectRef object)
+bool JSObjectIsConstructor(JSContextRef, JSObjectRef object)
{
JSObject* jsObject = toJS(object);
return jsObject->implementsConstruct();
}
-JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSObject* jsObject = toJS(object);
List argList;
PropertyNameArray array;
};
-JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef context, JSObjectRef object)
+JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object)
{
JSLock lock;
JSObject* jsObject = toJS(object);
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray();
jsObject->getPropertyNames(exec, propertyNames->array);
/*!
@typedef JSObjectInitializeCallback
@abstract The callback invoked when an object is first created.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject being created.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
@discussion If you named your function Initialize, you would declare it like this:
-void Initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception);
+void Initialize(JSContextRef ctx, JSObjectRef object, JSValueRef* exception);
*/
typedef void
-(*JSObjectInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);
+(*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object, JSValueRef* exception);
/*!
@typedef JSObjectFinalizeCallback
/*!
@typedef JSObjectHasPropertyCallback
@abstract The callback invoked when determining whether an object has a property.
-@param context The current execution context.
+@param ctx The execution context to use.
@param object The JSObject to search for the property.
@param propertyName A JSString containing the name of the property look up.
@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, JSStringRef propertyName);
+bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
*/
typedef bool
-(*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+(*JSObjectHasPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
/*!
@typedef JSObjectGetPropertyCallback
@abstract The callback invoked when getting a property's value.
-@param context The current execution context.
+@param ctx The execution context to use.
@param object The JSObject to search for the property.
@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 The property's value if object has the property, otherwise NULL.
@discussion If you named your function GetProperty, you would declare it like this:
-JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
*/
typedef JSValueRef
-(*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+(*JSObjectGetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
@typedef JSObjectSetPropertyCallback
@abstract The callback invoked when setting a property's value.
-@param context The current execution context.
+@param ctx The execution context to use.
@param object The JSObject on which to set the property's value.
@param propertyName A JSString containing the name of the property to set.
@param value A JSValue to use as the property's value.
@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, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
+bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
*/
typedef bool
-(*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
+(*JSObjectSetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
/*!
@typedef JSObjectDeletePropertyCallback
@abstract The callback invoked when deleting a property.
-@param context The current execution context.
+@param ctx The execution context to use.
@param object The JSObject in which to delete the property.
@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, JSStringRef propertyName, JSValueRef* exception);
+bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
*/
typedef bool
-(*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+(*JSObjectDeletePropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
@typedef JSObjectGetPropertyNamesCallback
@abstract The callback invoked to get the names of an object's properties.
-@param context The current execution context.
+@param ctx The execution context to use.
@param object The JSObject whose property names need to be appended to propertyNames.
@param accumulator A JavaScript property name accumulator, to which the object should add the names of its properties.
@discussion If you named your function GetPropertyNames, you would declare it like this:
-void GetPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator);
+void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator);
Use JSPropertyNameAccumulatorAddName to add property names to accumulator.
will be added automatically.
*/
typedef void
-(*JSObjectGetPropertyNamesCallback) (JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
+(*JSObjectGetPropertyNamesCallback) (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
/*!
@typedef JSObjectCallAsFunctionCallback
@abstract The callback invoked when an object is called as a function.
-@param context The current execution context.
+@param ctx The execution context to use.
@param function A JSObject that is the function being called.
@param thisObject A JSObject that is the 'this' variable in the function's scope.
@param argumentCount An integer count of the number of arguments in arguments.
@result A JSValue that is the function's return value.
@discussion If you named your function CallAsFunction, you would declare it like this:
-JSValueRef CallAsFunction(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
If your callback were invoked by the JavaScript expression 'myObject.myMemberFunction()', function would be set to myMemberFunction, and thisObject would be set to myObject.
If this callback is NULL, calling your object as a function will throw an exception.
*/
typedef JSValueRef
-(*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+(*JSObjectCallAsFunctionCallback) (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
/*!
@typedef JSObjectCallAsConstructorCallback
@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
-@param context The current execution context.
+@param ctx The execution context to use.
@param constructor A JSObject that is the constructor being called.
@param argumentCount An integer count of the number of arguments in arguments.
@param arguments A JSValue array of the arguments passed to the function.
@result A JSObject that is the constructor's return value.
@discussion If you named your function CallAsConstructor, you would declare it like this:
-JSObjectRef CallAsConstructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
If your callback were invoked by the JavaScript expression 'new myConstructorFunction()', constructor would be set to myConstructorFunction.
If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
*/
typedef JSObjectRef
-(*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+(*JSObjectCallAsConstructorCallback) (JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
/*!
@typedef JSObjectHasInstanceCallback
@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
-@param context The current execution context.
+@param ctx The execution context to use.
@param constructor The JSObject that is the target of the 'instanceof' expression.
@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
@param exception A pointer to a JSValueRef in which to return an exception, if any.
@discussion If you named your function HasInstance, you would declare it like this:
-bool HasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
+bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
*/
typedef bool
-(*JSObjectHasInstanceCallback) (JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
+(*JSObjectHasInstanceCallback) (JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
/*!
@typedef JSObjectConvertToTypeCallback
@abstract The callback invoked when converting an object to a particular JavaScript type.
-@param context The current execution context.
+@param ctx The execution context to use.
@param object The JSObject to convert.
@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 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:
-JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
+JSValueRef ConvertToType(JSContextRef ctx, 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).
This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.
*/
typedef JSValueRef
-(*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
+(*JSObjectConvertToTypeCallback) (JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
/*!
@struct JSStaticValue
/*!
@function
@abstract Creates a JavaScript object with a given class and prototype.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
@param prototype The prototype to assign to the object. Pass NULL to use the default object prototype.
@result A JSObject with the given class and prototype.
*/
-JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSValueRef prototype);
+JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype);
/*!
@function
@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
@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 JSObjectMakeFunctionWithCallback(JSContextRef context, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);
+JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, 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 ctx The execution context to use.
@param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' expression.
@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
*/
-JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor);
+JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSObjectCallAsConstructorCallback callAsConstructor);
/*!
@function
@abstract Creates a function with a given script as its body.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
@param parameterCount An integer count of the number of parameter names in parameterNames.
@param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
@result A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The 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 JSObjectMakeFunction(JSContextRef context, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
@function
@abstract Gets an object's prototype.
+@param ctx The execution context to use.
@param object A JSObject whose prototype you want to get.
@result A JSValue containing the object's prototype.
*/
-JSValueRef JSObjectGetPrototype(JSObjectRef object);
+JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object);
+
/*!
@function
@abstract Sets an object's prototype.
+@param ctx The execution context to use.
@param object The JSObject whose prototype you want to set.
@param value A JSValue to set as the object's prototype.
*/
-void JSObjectSetPrototype(JSObjectRef object, JSValueRef value);
+void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value);
/*!
@function
@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, JSStringRef propertyName);
+bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
/*!
@function
@abstract Gets a property from an object.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject whose property you want to get.
@param propertyName A JSString containing the property's name.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The property's value if object has the property, otherwise the undefined value.
*/
-JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
@function
@abstract Sets a property on an object.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject whose property you want to set.
@param propertyName A JSString containing the property's name.
@param value A JSValue to use as the property's value.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
*/
-void JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
+void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
/*!
@function
@abstract Deletes a property from an object.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject whose property you want to delete.
@param propertyName A JSString containing the property's name.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
*/
-bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
/*!
@function
@abstract Gets a property from an object by numeric index.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject whose property you want to get.
@param propertyIndex The property's name as a number
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The property's value if object has the property, otherwise the undefined value.
@discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but it enables optimized access to JavaScript arrays.
*/
-JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
+JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
/*!
@function
@abstract Sets a property on an object by numeric index.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject whose property you want to set.
@param propertyIndex The property's name as a number
@param value A JSValue to use as the property's value.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but it enables optimized access to JavaScript arrays.
*/
-void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
+void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
/*!
@function
/*!
@function
@abstract Tests whether an object can be called as a function.
+@param ctx The execution context to use.
@param object The JSObject to test.
@result true if the object can be called as a function, otherwise false.
*/
-bool JSObjectIsFunction(JSObjectRef object);
+bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object);
+
/*!
@function
@abstract Calls an object as a function.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject to call as a function.
@param thisObject The object to use as "this," or NULL to use the global object as "this."
@param argumentCount An integer count of the number of arguments in arguments.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
*/
-JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
/*!
@function
@abstract Tests whether an object can be called as a constructor.
+@param ctx The execution context to use.
@param object The JSObject to test.
@result true if the object can be called as a constructor, otherwise false.
*/
-bool JSObjectIsConstructor(JSObjectRef object);
+bool JSObjectIsConstructor(JSContextRef ctx, JSObjectRef object);
+
/*!
@function
@abstract Calls an object as a constructor.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The JSObject to call as a constructor.
@param argumentCount An integer count of the number of arguments in arguments.
@param arguments A JSValue array of the arguments to pass to the function. Pass NULL if argumentCount is 0.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
*/
-JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
/*!
@function
@abstract Get the names of all enumerable properties of an object.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param object The object from which to get property names.
@result A JSPropertyNameArray containing the names of all the object's enumerable properties.
*/
-JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef context, JSObjectRef object);
+JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object);
/*!
@function
using namespace KJS;
-JSValueRef JSValueMakeString(JSStringRef string)
-{
- JSLock lock;
- UString::Rep* rep = toJS(string);
- return toRef(jsString(UString(rep)));
-}
-
JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
{
JSLock lock;
#include <algorithm> // for std::min
-JSType JSValueGetType(JSValueRef value)
+JSType JSValueGetType(JSContextRef, JSValueRef value)
{
KJS::JSValue* jsValue = toJS(value);
switch (jsValue->type()) {
using namespace KJS; // placed here to avoid conflict between KJS::JSType and JSType, above.
-bool JSValueIsUndefined(JSValueRef value)
+bool JSValueIsUndefined(JSContextRef, JSValueRef value)
{
JSValue* jsValue = toJS(value);
return jsValue->isUndefined();
}
-bool JSValueIsNull(JSValueRef value)
+bool JSValueIsNull(JSContextRef, JSValueRef value)
{
JSValue* jsValue = toJS(value);
return jsValue->isNull();
}
-bool JSValueIsBoolean(JSValueRef value)
+bool JSValueIsBoolean(JSContextRef, JSValueRef value)
{
JSValue* jsValue = toJS(value);
return jsValue->isBoolean();
}
-bool JSValueIsNumber(JSValueRef value)
+bool JSValueIsNumber(JSContextRef, JSValueRef value)
{
JSValue* jsValue = toJS(value);
return jsValue->isNumber();
}
-bool JSValueIsString(JSValueRef value)
+bool JSValueIsString(JSContextRef, JSValueRef value)
{
JSValue* jsValue = toJS(value);
return jsValue->isString();
}
-bool JSValueIsObject(JSValueRef value)
+bool JSValueIsObject(JSContextRef, JSValueRef value)
{
JSValue* jsValue = toJS(value);
return jsValue->isObject();
}
-bool JSValueIsObjectOfClass(JSValueRef value, JSClassRef jsClass)
+bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass)
{
JSValue* jsValue = toJS(value);
return false;
}
-bool JSValueIsEqual(JSContextRef context, JSValueRef a, JSValueRef b, JSValueRef* exception)
+bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSValue* jsA = toJS(a);
JSValue* jsB = toJS(b);
return result;
}
-bool JSValueIsStrictEqual(JSContextRef context, JSValueRef a, JSValueRef b)
+bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSValue* jsA = toJS(a);
JSValue* jsB = toJS(b);
return result;
}
-bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
+bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
{
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSValue* jsValue = toJS(value);
JSObject* jsConstructor = toJS(constructor);
if (!jsConstructor->implementsHasInstance())
return result;
}
-JSValueRef JSValueMakeUndefined()
+JSValueRef JSValueMakeUndefined(JSContextRef)
{
return toRef(jsUndefined());
}
-JSValueRef JSValueMakeNull()
+JSValueRef JSValueMakeNull(JSContextRef)
{
return toRef(jsNull());
}
-JSValueRef JSValueMakeBoolean(bool value)
+JSValueRef JSValueMakeBoolean(JSContextRef, bool value)
{
return toRef(jsBoolean(value));
}
-JSValueRef JSValueMakeNumber(double value)
+JSValueRef JSValueMakeNumber(JSContextRef, double value)
{
JSLock lock;
return toRef(jsNumber(value));
}
-bool JSValueToBoolean(JSContextRef context, JSValueRef value)
+JSValueRef JSValueMakeString(JSContextRef, JSStringRef string)
{
- ExecState* exec = toJS(context);
+ JSLock lock;
+ UString::Rep* rep = toJS(string);
+ return toRef(jsString(UString(rep)));
+}
+
+bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
JSValue* jsValue = toJS(value);
return jsValue->toBoolean(exec);
}
-double JSValueToNumber(JSContextRef context, JSValueRef value, JSValueRef* exception)
+double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
JSLock lock;
JSValue* jsValue = toJS(value);
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
double number = jsValue->toNumber(exec);
if (exec->hadException()) {
return number;
}
-JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value, JSValueRef* exception)
+JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
JSLock lock;
JSValue* jsValue = toJS(value);
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
if (exec->hadException()) {
return stringRef;
}
-JSObjectRef JSValueToObject(JSContextRef context, JSValueRef value, JSValueRef* exception)
+JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
JSLock lock;
- ExecState* exec = toJS(context);
+ ExecState* exec = toJS(ctx);
JSValue* jsValue = toJS(value);
JSObjectRef objectRef = toRef(jsValue->toObject(exec));
return objectRef;
}
-void JSValueProtect(JSValueRef value)
+void JSValueProtect(JSContextRef, JSValueRef value)
{
JSLock lock;
JSValue* jsValue = toJS(value);
gcProtect(jsValue);
}
-void JSValueUnprotect(JSValueRef value)
+void JSValueUnprotect(JSContextRef, JSValueRef value)
{
JSLock lock;
JSValue* jsValue = toJS(value);
/*!
@function
@abstract Returns a JavaScript value's type.
+@param ctx The execution context to use.
@param value The JSValue whose type you want to obtain.
@result A value of type JSType that identifies value's type.
*/
-JSType JSValueGetType(JSValueRef value);
+JSType JSValueGetType(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value's type is the undefined type.
+@param ctx The execution context to use.
@param value The JSValue to test.
@result true if value's type is the undefined type, otherwise false.
*/
-bool JSValueIsUndefined(JSValueRef value);
+bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value's type is the null type.
+@param ctx The execution context to use.
@param value The JSValue to test.
@result true if value's type is the null type, otherwise false.
*/
-bool JSValueIsNull(JSValueRef value);
+bool JSValueIsNull(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value's type is the boolean type.
+@param ctx The execution context to use.
@param value The JSValue to test.
@result true if value's type is the boolean type, otherwise false.
*/
-bool JSValueIsBoolean(JSValueRef value);
+bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value's type is the number type.
+@param ctx The execution context to use.
@param value The JSValue to test.
@result true if value's type is the number type, otherwise false.
*/
-bool JSValueIsNumber(JSValueRef value);
+bool JSValueIsNumber(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value's type is the string type.
+@param ctx The execution context to use.
@param value The JSValue to test.
@result true if value's type is the string type, otherwise false.
*/
-bool JSValueIsString(JSValueRef value);
+bool JSValueIsString(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value's type is the object type.
+@param ctx The execution context to use.
@param value The JSValue to test.
@result true if value's type is the object type, otherwise false.
*/
-bool JSValueIsObject(JSValueRef value);
+bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Tests whether a JavaScript value is an object with a given
+@param ctx The execution context to use.
class in its class chain.
@param value The JSValue to test.
@result true if value is an object and has jsClass in its class chain,
otherwise false.
*/
-bool JSValueIsObjectOfClass(JSValueRef value, JSClassRef jsClass);
+bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass);
// Comparing values
/*!
@function
@abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param a The first value to test.
@param b The second value to test.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result true if the two values are equal, false if they are not equal or an exception is thrown.
*/
-bool JSValueIsEqual(JSContextRef context, JSValueRef a, JSValueRef b, JSValueRef* exception);
+bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception);
/*!
@function
@abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param a The first value to test.
@param b The second value to test.
@result true if the two values are strict equal, otherwise false.
*/
-bool JSValueIsStrictEqual(JSContextRef context, JSValueRef a, JSValueRef b);
+bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b);
/*!
@function
@abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param value The JSValue to test.
@param object The constructor to test against.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
*/
-bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor, JSValueRef* exception);
+bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception);
// Creating values
/*!
@function
-@abstract Creates a JavaScript value of the undefined type.
-@result The unique undefined value.
+@abstract Creates a JavaScript value of the undefined type.
+@param ctx The execution context to use.
+@result The unique undefined value.
*/
-JSValueRef JSValueMakeUndefined(void);
+JSValueRef JSValueMakeUndefined(JSContextRef ctx);
/*!
@function
-@abstract Creates a JavaScript value of the null type.
-@result The unique null value.
+@abstract Creates a JavaScript value of the null type.
+@param ctx The execution context to use.
+@result The unique null value.
*/
-JSValueRef JSValueMakeNull(void);
+JSValueRef JSValueMakeNull(JSContextRef ctx);
/*!
@function
@abstract Creates a JavaScript value of the boolean type.
+@param ctx The execution context to use.
@param boolean The bool to assign to the newly created JSValue.
@result A JSValue of the boolean type, representing the value of boolean.
*/
-
-JSValueRef JSValueMakeBoolean(bool boolean);
+JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool boolean);
/*!
@function
@abstract Creates a JavaScript value of the number type.
+@param ctx The execution context to use.
@param number The double to assign to the newly created JSValue.
@result A JSValue of the number type, representing the value of number.
*/
-JSValueRef JSValueMakeNumber(double number);
+JSValueRef JSValueMakeNumber(JSContextRef ctx, double number);
/*!
@function
@abstract Creates a JavaScript value of the string type.
+@param ctx The execution context to use.
@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 value of string.
*/
-JSValueRef JSValueMakeString(JSStringRef string);
+JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string);
// Converting to primitive values
/*!
@function
@abstract Converts a JavaScript value to boolean and returns the resulting boolean.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param value The JSValue to convert.
@result The boolean result of conversion.
*/
-bool JSValueToBoolean(JSContextRef context, JSValueRef value);
+bool JSValueToBoolean(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Converts a JavaScript value to number and returns the resulting number.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param value The JSValue to convert.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The numeric result of conversion, or NaN if an exception is thrown.
*/
-double JSValueToNumber(JSContextRef context, JSValueRef value, JSValueRef* exception);
+double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
/*!
@function
@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param value The JSValue to convert.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
*/
-JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value, JSValueRef* exception);
+JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
/*!
@function
@abstract Converts a JavaScript value to object and returns the resulting object.
-@param context The execution context to use.
+@param ctx The execution context to use.
@param value The JSValue to convert.
@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
@result The JSObject result of conversion, or NULL if an exception is thrown.
*/
-JSObjectRef JSValueToObject(JSContextRef context, JSValueRef value, JSValueRef* exception);
+JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
// Garbage collection
/*!
@function
@abstract Protects a JavaScript value from garbage collection.
+@param ctx The execution context to use.
@param value The JSValue to protect.
@discussion A value may be protected multiple times and must be unprotected an
equal number of times before becoming eligible for garbage collection.
*/
-void JSValueProtect(JSValueRef value);
+void JSValueProtect(JSContextRef ctx, JSValueRef value);
/*!
@function
@abstract Unprotects a JavaScript value from garbage collection.
+@param ctx The execution context to use.
@param value The JSValue to unprotect.
@discussion A value may be protected multiple times and must be unprotected an
equal number of times before becoming eligible for garbage collection.
*/
-void JSValueUnprotect(JSValueRef value);
+void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
#ifdef __cplusplus
}
printf("%s\n", stringUTF8);
}
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static char* createStringWithContentsOfFile(const char* fileName)
UNUSED_PARAM(object);
if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
- return JSValueMakeNumber(1);
+ return JSValueMakeNumber(context, 1);
}
if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
- return JSValueMakeNumber(1);
+ return JSValueMakeNumber(context, 1);
}
if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
if (JSStringIsEqualToUTF8CString(propertyName, "0")) {
- *exception = JSValueMakeNumber(1);
- return JSValueMakeNumber(1);
+ *exception = JSValueMakeNumber(context, 1);
+ return JSValueMakeNumber(context, 1);
}
return NULL;
return true;
if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) {
- *exception = JSValueMakeNumber(2);
+ *exception = JSValueMakeNumber(context, 2);
return false;
}
UNUSED_PARAM(object);
UNUSED_PARAM(thisObject);
- if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(0)))
- return JSValueMakeNumber(1);
+ if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
+ return JSValueMakeNumber(context, 1);
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSObjectRef MyObject_callAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
UNUSED_PARAM(context);
UNUSED_PARAM(object);
- if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(0)))
- return JSValueToObject(context, JSValueMakeNumber(1), NULL);
+ if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
+ return JSValueToObject(context, JSValueMakeNumber(context, 1), NULL);
- return JSValueToObject(context, JSValueMakeNumber(0), NULL);
+ return JSValueToObject(context, JSValueMakeNumber(context, 0), NULL);
}
static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
switch (type) {
case kJSTypeNumber:
- return JSValueMakeNumber(1);
+ return JSValueMakeNumber(context, 1);
default:
break;
}
JSStringRelease(string);
}
- return JSValueMakeUndefined();
+ return JSValueMakeUndefined(context);
}
static JSObjectRef myConstructor_callAsConstructor(JSContextRef context, JSObjectRef constructorObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
context = JSGlobalContextCreate(NULL);
JSObjectRef globalObject = JSContextGetGlobalObject(context);
- assert(JSValueIsObject(globalObject));
+ assert(JSValueIsObject(context, globalObject));
- 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());
+ JSValueRef jsUndefined = JSValueMakeUndefined(context);
+ JSValueRef jsNull = JSValueMakeNull(context);
+ JSValueRef jsTrue = JSValueMakeBoolean(context, true);
+ JSValueRef jsFalse = JSValueMakeBoolean(context, false);
+ JSValueRef jsZero = JSValueMakeNumber(context, 0);
+ JSValueRef jsOne = JSValueMakeNumber(context, 1);
+ JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
+ JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull(context));
// FIXME: test funny utf8 characters
JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
- JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString);
+ JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString);
JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
- JSValueRef jsOneString = JSValueMakeString(jsOneIString);
+ JSValueRef jsOneString = JSValueMakeString(context, jsOneIString);
#if defined(__APPLE__)
UniChar singleUniChar = 65; // Capital A
kCFAllocatorNull);
JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
- JSValueRef jsCFString = JSValueMakeString(jsCFIString);
+ JSValueRef jsCFString = JSValueMakeString(context, jsCFIString);
CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
- JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString);
+ JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);
CFIndex cfStringLength = CFStringGetLength(cfString);
UniChar buffer[cfStringLength];
CFRangeMake(0, cfStringLength),
buffer);
JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
- JSValueRef jsCFStringWithCharacters = JSValueMakeString(jsCFIStringWithCharacters);
+ JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
- JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(jsCFEmptyIStringWithCharacters);
+ JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
#endif // __APPLE__
- assert(JSValueGetType(jsUndefined) == kJSTypeUndefined);
- assert(JSValueGetType(jsNull) == kJSTypeNull);
- assert(JSValueGetType(jsTrue) == kJSTypeBoolean);
- assert(JSValueGetType(jsFalse) == kJSTypeBoolean);
- assert(JSValueGetType(jsZero) == kJSTypeNumber);
- assert(JSValueGetType(jsOne) == kJSTypeNumber);
- assert(JSValueGetType(jsOneThird) == kJSTypeNumber);
- assert(JSValueGetType(jsEmptyString) == kJSTypeString);
- assert(JSValueGetType(jsOneString) == kJSTypeString);
+ assert(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
+ assert(JSValueGetType(context, jsNull) == kJSTypeNull);
+ assert(JSValueGetType(context, jsTrue) == kJSTypeBoolean);
+ assert(JSValueGetType(context, jsFalse) == kJSTypeBoolean);
+ assert(JSValueGetType(context, jsZero) == kJSTypeNumber);
+ assert(JSValueGetType(context, jsOne) == kJSTypeNumber);
+ assert(JSValueGetType(context, jsOneThird) == kJSTypeNumber);
+ assert(JSValueGetType(context, jsEmptyString) == kJSTypeString);
+ assert(JSValueGetType(context, jsOneString) == kJSTypeString);
#if defined(__APPLE__)
- assert(JSValueGetType(jsCFString) == kJSTypeString);
- assert(JSValueGetType(jsCFStringWithCharacters) == kJSTypeString);
- assert(JSValueGetType(jsCFEmptyString) == kJSTypeString);
- assert(JSValueGetType(jsCFEmptyStringWithCharacters) == kJSTypeString);
+ assert(JSValueGetType(context, jsCFString) == kJSTypeString);
+ assert(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString);
+ assert(JSValueGetType(context, jsCFEmptyString) == kJSTypeString);
+ assert(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString);
#endif // __APPLE__
JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
assert(JSValueToBoolean(context, myObject));
exception = NULL;
- assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(1), &exception));
+ assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(context, 1), &exception));
assert(exception);
exception = NULL;
#endif // __APPLE__
jsGlobalValue = JSObjectMake(context, NULL, NULL);
- JSValueProtect(jsGlobalValue);
- JSGarbageCollect();
- assert(JSValueIsObject(jsGlobalValue));
- JSValueUnprotect(jsGlobalValue);
+ JSValueProtect(context, jsGlobalValue);
+ JSGarbageCollect(context);
+ assert(JSValueIsObject(context, jsGlobalValue));
+ JSValueUnprotect(context, jsGlobalValue);
JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
exception = NULL;
result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception);
assert(!result);
- assert(JSValueIsObject(exception));
+ assert(JSValueIsObject(context, exception));
JSStringRef array = JSStringCreateWithUTF8CString("Array");
JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
JSStringRelease(array);
result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
assert(result);
- assert(JSValueIsObject(result));
+ assert(JSValueIsObject(context, result));
assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
- assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor, NULL));
+ assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(context), arrayConstructor, NULL));
o = JSValueToObject(context, result, NULL);
exception = NULL;
- assert(JSValueIsUndefined(JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
+ assert(JSValueIsUndefined(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
assert(!exception);
- JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(1), &exception);
+ JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(context, 1), &exception);
assert(!exception);
exception = NULL;
functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
JSStringRef line = JSStringCreateWithUTF8CString("line");
assert(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception));
- assert(JSValueIsObject(exception));
+ assert(JSValueIsObject(context, exception));
v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact)
JSStringRelease(functionBody);
function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception);
JSStringRelease(functionBody);
assert(!exception);
- assert(JSObjectIsFunction(function));
+ assert(JSObjectIsFunction(context, function));
v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
assert(v);
assert(JSValueIsEqual(context, v, arrayConstructor, NULL));
assert(!exception);
v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, &exception);
assert(v && !exception);
- assert(JSValueIsUndefined(v));
+ assert(JSValueIsUndefined(context, v));
exception = NULL;
v = NULL;
functionBody = JSStringCreateWithUTF8CString("return foo;");
function = JSObjectMakeFunction(context, foo, 1, argumentNames, functionBody, NULL, 1, &exception);
assert(function && !exception);
- JSValueRef arguments[] = { JSValueMakeNumber(2) };
+ JSValueRef arguments[] = { JSValueMakeNumber(context, 2) };
v = JSObjectCallAsFunction(context, function, NULL, 1, arguments, &exception);
JSStringRelease(foo);
JSStringRelease(functionBody);
string = JSValueToStringCopy(context, function, NULL);
- assertEqualsAsUTF8String(JSValueMakeString(string), "function foo(foo) \n{\n return foo;\n}");
+ assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) \n{\n return foo;\n}");
JSStringRelease(string);
JSStringRef print = JSStringCreateWithUTF8CString("print");
assert(!JSObjectGetPrivate(myConstructor));
o = JSObjectMake(context, NULL, NULL);
- JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(1), kJSPropertyAttributeDontEnum, NULL);
+ JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
+ JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL);
JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o);
size_t expectedCount = JSPropertyNameArrayGetCount(nameArray);
size_t count;
char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
- if (JSValueIsUndefined(result))
+ if (JSValueIsUndefined(context, result))
printf("PASS: Test script executed successfully.\n");
else {
printf("FAIL: Test script returned unexcpected value:\n");
// Allocate a few dummies so that at least one will be collected
JSObjectMake(context, MyObject_class(context), 0);
JSObjectMake(context, MyObject_class(context), 0);
- JSGarbageCollect();
+ JSGarbageCollect(context);
assert(didFinalize);
JSStringRelease(jsEmptyIString);
+2006-07-17 Maciej Stachowiak <mjs@apple.com>
+
+ Reviewed by Geoff.
+
+ - add a JSContextRef parameter to all JSValueRef, JSObjectRef, and JSContextRef operations;
+ except JSObject{Get,Set}PrivateData which can be assumed to be simple pure accessors.
+
+ Also renamed the parameter "context" to "ctx" because it makes the code read better with this pervasive
+ but usually uninteresting parameter.
+
+ * API/JSBase.cpp:
+ (JSEvaluateScript):
+ (JSCheckScriptSyntax):
+ (JSGarbageCollect):
+ * API/JSBase.h:
+ * API/JSCallbackObject.cpp:
+ (KJS::JSCallbackObject::JSCallbackObject):
+ (KJS::JSCallbackObject::init):
+ (KJS::JSCallbackObject::getOwnPropertySlot):
+ (KJS::JSCallbackObject::put):
+ (KJS::JSCallbackObject::deleteProperty):
+ (KJS::JSCallbackObject::toNumber):
+ (KJS::JSCallbackObject::toString):
+ * API/JSContextRef.cpp:
+ (JSGlobalContextCreate):
+ (JSGlobalContextRetain):
+ (JSGlobalContextRelease):
+ (JSContextGetGlobalObject):
+ * API/JSContextRef.h:
+ * API/JSNode.c:
+ (JSNodePrototype_appendChild):
+ (JSNodePrototype_removeChild):
+ (JSNodePrototype_replaceChild):
+ (JSNode_getNodeType):
+ (JSNode_getFirstChild):
+ (JSNode_prototype):
+ * API/JSNodeList.c:
+ (JSNodeListPrototype_item):
+ (JSNodeList_length):
+ (JSNodeList_getProperty):
+ (JSNodeList_prototype):
+ * API/JSObjectRef.cpp:
+ (JSObjectMake):
+ (JSObjectMakeFunctionWithCallback):
+ (JSObjectMakeConstructor):
+ (JSObjectMakeFunction):
+ (JSObjectGetPrototype):
+ (JSObjectSetPrototype):
+ (JSObjectHasProperty):
+ (JSObjectGetProperty):
+ (JSObjectSetProperty):
+ (JSObjectGetPropertyAtIndex):
+ (JSObjectSetPropertyAtIndex):
+ (JSObjectDeleteProperty):
+ (JSObjectIsFunction):
+ (JSObjectCallAsFunction):
+ (JSObjectIsConstructor):
+ (JSObjectCallAsConstructor):
+ (JSObjectCopyPropertyNames):
+ * API/JSObjectRef.h:
+ * API/JSStringRef.cpp:
+ * API/JSValueRef.cpp:
+ (JSValueGetType):
+ (JSValueIsUndefined):
+ (JSValueIsNull):
+ (JSValueIsBoolean):
+ (JSValueIsNumber):
+ (JSValueIsString):
+ (JSValueIsObject):
+ (JSValueIsObjectOfClass):
+ (JSValueIsEqual):
+ (JSValueIsStrictEqual):
+ (JSValueIsInstanceOfConstructor):
+ (JSValueMakeUndefined):
+ (JSValueMakeNull):
+ (JSValueMakeBoolean):
+ (JSValueMakeNumber):
+ (JSValueMakeString):
+ (JSValueToBoolean):
+ (JSValueToNumber):
+ (JSValueToStringCopy):
+ (JSValueToObject):
+ (JSValueProtect):
+ (JSValueUnprotect):
+ * API/JSValueRef.h:
+ * API/minidom.c:
+ (print):
+ * API/testapi.c:
+ (MyObject_getProperty):
+ (MyObject_deleteProperty):
+ (MyObject_callAsFunction):
+ (MyObject_callAsConstructor):
+ (MyObject_convertToType):
+ (print_callAsFunction):
+ (main):
+
2006-07-16 Geoffrey Garen <ggaren@apple.com>
Approved by Maciej, RS by Beth.