Commit 554ad6fb authored by ggaren's avatar ggaren
Browse files

Reviewed by Maciej.

        
        More API action.
        
        - Headerdoc finished

        Semantic Changes:
        - Added a JSContextRef argument to many functions, because you need a 
        JSContextRef for doing virtually anything. I expect to add this argument
        to even more functions in a future patch.
        
        - Removed the globalObjectPrototype argument to JSContextCreate because
        you can't create an object until you have a context, so it's impossible
        to pass a prototype object to JSContextCreate. That's OK because (1) there's
        no reason to give the global object a prototype and (2) if you really want
        to, you can just use a separate call to JSObjectSetPrototype.
        
        - Removed the JSClassRef argument to JSClassCreate because it was unnecessary,
        and you need to be able to make the global object's class before you've
        created a JSContext.
        
        - Added an optional exception parameter to JSFunctionMakeWithBody because anything
        less would be uncivilized.
        
        - Made the return value parameter to JSObjectGetProperty optional to match
        all other return value parameters in the API.
        
        - Made JSObjectSetPrivate/JSObjectGetPrivate work on JSCallbackFunctions
        and JSCallbackConstructors. You could use an abstract base class or strategic
        placement of m_privateData in the class structure to implement this, but 
        the former seemed like overkill, and the latter seemed too dangerous.
        
        - Fixed a bug where JSPropertyEnumeratorGetNext would skip the first property.

        Cosmetic Changes:
        - Reversed the logic of the JSChar #ifdef to avoid confusing headerdoc
        
        - Removed function names from @function declarations because headeroc
        can parse them automatically, and I wanted to rule out manual mismatch.

        - Changed Error::create to take a const UString& instead of a UString*
        because it was looking at me funny.
        
        - Renamed JSStringBufferCreateWithCFString to JSStringBufferCreateCF
        because the latter is more concise and it matches JSStringBufferCreateUTF8.
        
        * API/JSCallbackObject.cpp:
        (KJS::JSCallbackObject::getOwnPropertySlot):
        (KJS::JSCallbackObject::put):
        (KJS::JSCallbackObject::deleteProperty):
        (KJS::JSCallbackObject::getPropertyList):
        (KJS::JSCallbackObject::toBoolean):
        (KJS::JSCallbackObject::toNumber):
        (KJS::JSCallbackObject::toString):
        * API/JSClassRef.cpp:
        (JSClassCreate):
        * API/JSContextRef.cpp:
        (JSContextCreate):
        (JSContextSetException):
        * API/JSContextRef.h:
        * API/JSNode.c:
        (JSNodePrototype_class):
        (JSNode_class):
        * API/JSNodeList.c:
        (JSNodeListPrototype_class):
        (JSNodeList_class):
        * API/JSObjectRef.cpp:
        (JSObjectGetProperty):
        (JSObjectGetPrivate):
        (JSObjectSetPrivate):
        (JSObjectCallAsFunction):
        (JSObjectCallAsConstructor):
        (JSPropertyEnumeratorGetNext):
        * API/JSObjectRef.h:
        * API/JSStringBufferRef.cpp:
        (JSStringBufferCreateCF):
        * API/JSStringBufferRef.h:
        * API/JSValueRef.cpp:
        (JSValueIsInstanceOf):
        * API/JSValueRef.h:
        * API/minidom.c:
        (main):
        * API/minidom.js:
        * API/testapi.c:
        (MyObject_hasProperty):
        (MyObject_setProperty):
        (MyObject_deleteProperty):
        (MyObject_getPropertyList):
        (MyObject_convertToType):
        (MyObject_class):
        (main):
        * JavaScriptCore.exp:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@15224 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bec59b8c
......@@ -80,19 +80,20 @@ UString JSCallbackObject::className() const
bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
JSStringBufferRef 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(thisRef, propertyNameRef)) {
if (hasPropertyCallback(context, thisRef, propertyNameRef)) {
slot.setCustom(this, callbackGetter);
return true;
}
} else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) {
JSValueRef returnValue;
if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue)) {
if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue)) {
// 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.
......@@ -128,12 +129,13 @@ bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName
void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep());
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) {
if (setPropertyCallback(thisRef, propertyNameRef, value))
if (setPropertyCallback(context, thisRef, propertyNameRef, value))
return;
}
......@@ -142,7 +144,7 @@ void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSVa
if (entry->attributes & kJSPropertyAttributeReadOnly)
return;
if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) {
if (setPropertyCallback(thisRef, propertyNameRef, value))
if (setPropertyCallback(context, thisRef, propertyNameRef, value))
return;
}
}
......@@ -167,12 +169,13 @@ void JSCallbackObject::put(ExecState* exec, unsigned propertyName, JSValue* valu
bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep());
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) {
if (deletePropertyCallback(thisRef, propertyNameRef))
if (deletePropertyCallback(context, thisRef, propertyNameRef))
return true;
}
......@@ -259,11 +262,12 @@ JSValue* JSCallbackObject::callAsFunction(ExecState* exec, JSObject* thisObj, co
void JSCallbackObject::getPropertyList(ExecState* exec, ReferenceList& propertyList, bool recursive)
{
JSContextRef context = toRef(exec);
JSObjectRef thisRef = toRef(this);
for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)
getPropertyListCallback(thisRef, toRef(&propertyList));
getPropertyListCallback(context, thisRef, toRef(&propertyList));
if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
typedef __JSClass::StaticValuesTable::const_iterator iterator;
......@@ -293,12 +297,13 @@ void JSCallbackObject::getPropertyList(ExecState* exec, ReferenceList& propertyL
bool JSCallbackObject::toBoolean(ExecState* exec) const
{
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(thisRef, kJSTypeBoolean, &returnValue))
if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue))
return toJS(returnValue)->getBoolean();
}
}
......@@ -307,12 +312,13 @@ bool JSCallbackObject::toBoolean(ExecState* exec) const
double JSCallbackObject::toNumber(ExecState* exec) const
{
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(thisRef, kJSTypeNumber, &returnValue))
if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue))
return toJS(returnValue)->getNumber();
}
}
......@@ -321,12 +327,13 @@ double JSCallbackObject::toNumber(ExecState* exec) const
UString JSCallbackObject::toString(ExecState* exec) const
{
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(thisRef, kJSTypeString, &returnValue))
if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue))
return toJS(returnValue)->getString();
}
}
......
......@@ -32,7 +32,7 @@ using namespace KJS;
const JSObjectCallbacks kJSObjectCallbacksNone = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
JSClassRef JSClassCreate(JSContextRef, JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass)
JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass)
{
JSClassRef jsClass = new __JSClass;
if (staticValues) {
......
......@@ -34,25 +34,15 @@
using namespace KJS;
JSContextRef JSContextCreate(JSClassRef globalObjectClass, JSObjectRef globalObjectPrototype)
JSContextRef JSContextCreate(JSClassRef globalObjectClass)
{
JSLock lock;
JSObject* jsPrototype = toJS(globalObjectPrototype);
JSObject* globalObject;
if (globalObjectClass) {
if (jsPrototype)
globalObject = new JSCallbackObject(globalObjectClass, jsPrototype);
else
globalObject = new JSCallbackObject(globalObjectClass);
} else {
// creates a slightly more efficient object
if (jsPrototype)
globalObject = new JSObject(jsPrototype);
else
globalObject = new JSObject();
}
if (globalObjectClass)
globalObject = new JSCallbackObject(globalObjectClass);
else
globalObject = new JSObject();
Interpreter* interpreter = new Interpreter(globalObject); // adds the built-in object prototype to the global object
return toRef(interpreter->globalExec());
......@@ -130,4 +120,3 @@ void JSContextSetException(JSContextRef context, JSValueRef value)
JSValue* jsValue = toJS(value);
exec->setException(jsValue);
}
......@@ -34,39 +34,76 @@
extern "C" {
#endif
JSContextRef JSContextCreate(JSClassRef globalObjectClass, JSObjectRef globalObjectPrototype);
/*!
@function
@abstract Creates a JavaScript execution context.
@discussion JSContextCreate allocates a global object and populates it with all the
built-in JavaScript objects, such as Object, Function, String, and Array.
@param globalObjectClass The class to use when creating the JSContext's global object.
Pass NULL to use the default object class.
@result A JSContext with a global object of class globalObjectClass.
*/
JSContextRef JSContextCreate(JSClassRef globalObjectClass);
/*!
@function
@abstract Destroys a JavaScript execution context, freeing its resources.
@param context The JSContext to destroy.
*/
void JSContextDestroy(JSContextRef context);
/*!
@function
@abstract Returns the global object of a JavaScript execution context.
@param context The JSContext whose global object you want to retrieve.
@result context's global object.
*/
JSObjectRef JSContextGetGlobalObject(JSContextRef context);
JSValueRef JSContextGetException(JSContextRef context); // NULL if there is no exception
/*!
@function
@abstract Returns the current exception in a JavaScript execution context.
@param context The JSContext whose exception you want to retrieve.
@result A JSValue representing context's exception, or NULL if no exception has been set.
*/
JSValueRef JSContextGetException(JSContextRef context);
/*!
@function
@abstract Sets an exception in a JavaScript execution context.
@param context The JSContext whose exception you want to set.
@param value The exception you want to set.
*/
void JSContextSetException(JSContextRef context, JSValueRef value);
/*!
@function
@abstract Clears the exception in a JavaScript execution context.
@param context The JSContext whose exception you want to clear.
*/
void JSContextClearException(JSContextRef context);
// Evaluation
/*!
@function JSEvaluate
Evaluates a string of JavaScript
@param context execution context to use
@param script a character buffer containing the JavaScript to evaluate
@param thisObject the object to use as "this," or NULL to use the global object as "this."
@param sourceURL URL to the file containing the JavaScript, or NULL - this is only used for error reporting
@param startingLineNumber the JavaScript's starting line number in the file located at sourceURL - this is only used for error reporting
@param exception pointer to a JSValueRef in which to store an uncaught exception, if any; can be NULL
@result result of evaluation, or NULL if an uncaught exception was thrown
@function
@abstract Evaluates a string of JavaScript.
@param context The execution context to use.
@param script A JSStringBuffer 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 JSStringBuffer 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, JSStringBufferRef script, JSObjectRef thisObject, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
@function JSCheckSyntax
Check for syntax errors in a string of JavaScript
@param context execution context to use
@param script a character buffer containing the JavaScript to evaluate
@param sourceURL URL to the file containing the JavaScript, or NULL - this is only used for error reporting
@param startingLineNumber the JavaScript's starting line number in the file located at sourceURL - this is only used for error reporting
@param exception pointer to a JSValueRef in which to store a syntax error, if any; can be NULL
@result true if the script is syntactically correct, false otherwise
@function JSCheckSyntax
@abstract Checks for syntax errors in a string of JavaScript.
@param context The execution context to use.
@param script A JSStringBuffer containing the JavaScript to check for syntax errors.
@param sourceURL A JSStringBuffer 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, JSStringBufferRef script, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception);
......
......@@ -109,7 +109,7 @@ static JSClassRef JSNodePrototype_class(JSContextRef context)
{
static JSClassRef nodePrototypeClass;
if (!nodePrototypeClass)
nodePrototypeClass = JSClassCreate(context, NULL, JSNodePrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
nodePrototypeClass = JSClassCreate(NULL, JSNodePrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
return nodePrototypeClass;
}
......@@ -169,7 +169,7 @@ static JSClassRef JSNode_class(JSContextRef context)
JSObjectCallbacks JSNode_callbacks = kJSObjectCallbacksNone;
JSNode_callbacks.finalize = JSNode_finalize;
nodeClass = JSClassCreate(context, JSNode_staticValues, NULL, &JSNode_callbacks, NULL);
nodeClass = JSClassCreate(JSNode_staticValues, NULL, &JSNode_callbacks, NULL);
}
return nodeClass;
}
......
......@@ -50,7 +50,7 @@ static JSClassRef JSNodeListPrototype_class(JSContextRef context)
{
static JSClassRef jsClass;
if (!jsClass) {
jsClass = JSClassCreate(context, NULL, JSNodeListPrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
jsClass = JSClassCreate(NULL, JSNodeListPrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
}
return jsClass;
......@@ -103,7 +103,7 @@ static JSClassRef JSNodeList_class(JSContextRef context)
callbacks.getProperty = JSNodeList_getProperty;
callbacks.finalize = JSNodeList_finalize;
jsClass = JSClassCreate(context, JSNodeList_staticValues, NULL, &callbacks, NULL);
jsClass = JSClassCreate(JSNodeList_staticValues, NULL, &callbacks, NULL);
}
return jsClass;
......
......@@ -70,18 +70,26 @@ JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback
return toRef(new JSCallbackConstructor(exec, callAsConstructor));
}
JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber)
JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
ExecState* exec = toJS(context);
UString::Rep* bodyRep = toJS(body);
UString::Rep* sourceURLRep = toJS(sourceURL);
UString jsSourceURL = UString(toJS(sourceURL));
if (!bodyRep)
bodyRep = &UString::Rep::null;
RefPtr<FunctionBodyNode> bodyNode = Parser::parse(UString(sourceURLRep), startingLineNumber, bodyRep->data(), bodyRep->size(), NULL, NULL, NULL);
if (!bodyNode)
int sid;
int errLine;
UString errMsg;
RefPtr<FunctionBodyNode> bodyNode = Parser::parse(jsSourceURL, startingLineNumber, bodyRep->data(), bodyRep->size(), &sid, &errLine, &errMsg);
if (!bodyNode) {
if (exception)
*exception = Error::create(exec, SyntaxError, errMsg, errLine, sid, jsSourceURL);
return NULL;
}
ScopeChain scopeChain;
scopeChain.push(exec->dynamicInterpreter()->globalObject());
......@@ -126,8 +134,10 @@ bool JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringBuffe
JSObject* jsObject = toJS(object);
UString::Rep* nameRep = toJS(propertyName);
*value = toRef(jsObject->get(exec, Identifier(nameRep)));
return !JSValueIsUndefined(*value);
JSValue* jsValue = jsObject->get(exec, Identifier(nameRep));
if (value)
*value = toRef(jsValue);
return !jsValue->isUndefined();
}
bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value, JSPropertyAttributes attributes)
......@@ -160,21 +170,38 @@ void* JSObjectGetPrivate(JSObjectRef object)
{
JSObject* jsObject = toJS(object);
if (!jsObject->inherits(&JSCallbackObject::info))
return 0;
if (jsObject->inherits(&JSCallbackObject::info))
return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
if (jsObject->inherits(&JSCallbackFunction::info))
return static_cast<JSCallbackFunction*>(jsObject)->getPrivate();
if (jsObject->inherits(&JSCallbackConstructor::info))
return static_cast<JSCallbackConstructor*>(jsObject)->getPrivate();
return 0;
}
bool JSObjectSetPrivate(JSObjectRef object, void* data)
{
JSObject* jsObject = toJS(object);
if (!jsObject->inherits(&JSCallbackObject::info))
return false;
if (jsObject->inherits(&JSCallbackObject::info)) {
static_cast<JSCallbackObject*>(jsObject)->setPrivate(data);
return true;
}
if (jsObject->inherits(&JSCallbackFunction::info)) {
static_cast<JSCallbackFunction*>(jsObject)->setPrivate(data);
return true;
}
if (jsObject->inherits(&JSCallbackConstructor::info)) {
static_cast<JSCallbackConstructor*>(jsObject)->setPrivate(data);
return true;
}
static_cast<JSCallbackObject*>(jsObject)->setPrivate(data);
return true;
return false;
}
bool JSObjectIsFunction(JSObjectRef object)
......@@ -193,8 +220,8 @@ JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSOb
List argList;
for (size_t i = 0; i < argc; i++)
argList.append(toJS(argv[i]));
JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList));
JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false
if (exec->hadException()) {
if (exception)
*exception = exec->exception();
......@@ -220,7 +247,7 @@ JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object,
for (size_t i = 0; i < argc; i++)
argList.append(toJS(argv[i]));
JSObjectRef result = toRef(jsObject->construct(exec, argList));
JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false
if (exec->hadException()) {
if (exception)
*exception = exec->exception();
......@@ -259,8 +286,9 @@ JSStringBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyEn
ExecState* exec = toJS(context);
ReferenceListIterator& iterator = enumerator->iterator;
if (iterator != enumerator->list.end()) {
JSStringBufferRef result = toRef(iterator->getPropertyName(exec).ustring().rep());
iterator++;
return toRef(iterator->getPropertyName(exec).ustring().rep());
return result;
}
return 0;
}
......
This diff is collapsed.
......@@ -139,7 +139,7 @@ bool JSStringBufferIsEqualUTF8(JSStringBufferRef a, const char* b)
}
#if defined(__APPLE__)
JSStringBufferRef JSStringBufferCreateWithCFString(CFStringRef string)
JSStringBufferRef JSStringBufferCreateCF(CFStringRef string)
{
JSLock lock;
CFIndex length = CFStringGetLength(string);
......
......@@ -32,33 +32,135 @@
extern "C" {
#endif
#if defined(WIN32) || defined(_WIN32)
typedef wchar_t JSChar;
#else
/*!
@typedef JSChar
@abstract A Unicode character.
*/
#if !defined(WIN32) && !defined(_WIN32)
typedef unsigned short JSChar;
#else
typedef wchar_t JSChar;
#endif
/*!
@function
@abstract Creates a JavaScript string buffer from a buffer of Unicode characters.
@param chars The buffer of Unicode characters to copy into the new JSStringBuffer.
@param numChars The number of characters to copy from the buffer pointed to by chars.
@result A JSStringBuffer containing chars. Ownership follows the create rule.
*/
JSStringBufferRef JSStringBufferCreate(const JSChar* chars, size_t numChars);
/*!
@function
@abstract Creates a JavaScript string buffer from a null-terminated UTF8 string.
@param string The null-terminated UTF8 string to copy into the new JSStringBuffer.
@result A JSStringBuffer containing string. Ownership follows the create rule.
*/
JSStringBufferRef JSStringBufferCreateUTF8(const char* string);
/*!
@function
@abstract Retains a JavaScript string buffer.
@param buffer The JSStringBuffer to retain.
@result A JSStringBuffer that is the same as buffer.
*/
JSStringBufferRef JSStringBufferRetain(JSStringBufferRef buffer);
/*!
@function
@abstract Releases a JavaScript string buffer.
@param buffer The JSStringBuffer to release.
*/
void JSStringBufferRelease(JSStringBufferRef buffer);
/*!
@function
@abstract Returns the number of Unicode characters in a JavaScript string buffer.
@param buffer The JSStringBuffer whose length (in Unicode characters) you want to know.
@result The number of Unicode characters stored in buffer.
*/
size_t JSStringBufferGetLength(JSStringBufferRef buffer);
/*!
@function
@abstract Quickly obtains a pointer to the Unicode character buffer that
serves as the backing store for a JavaScript string buffer.
@param buffer The JSStringBuffer whose backing store you want to access.
@result A pointer to the Unicode character buffer that serves as buffer's
backing store, which will be deallocated when buffer is deallocated.
*/
const JSChar* JSStringBufferGetCharactersPtr(JSStringBufferRef buffer);
/*!
@function
@abstract Copies a JavaScript string buffer's Unicode characters into an
external character buffer.
@param inBuffer The source JSStringBuffer.
@param outBuffer The destination JSChar buffer into which to copy inBuffer's
characters. On return, outBuffer contains the requested Unicode characters.
@param numChars The number of Unicode characters to copy. This number must not
exceed the length of the string buffer.
*/
void JSStringBufferGetCharacters(JSStringBufferRef inBuffer, JSChar* outBuffer, size_t numChars);
/*!
@function
@abstract Returns the maximum number of bytes required to encode the
contents of a JavaScript string buffer as a null-terminated UTF8 string.
@param buffer The JSStringBuffer whose maximum encoded length (in bytes) you
want to know.
@result The maximum number of bytes required to encode buffer's contents
as a null-terminated UTF8 string.
*/
size_t JSStringBufferGetMaxLengthUTF8(JSStringBufferRef buffer);
// Returns the number of bytes written into outBuffer, including the trailing '\0'
/*!
@function
@abstract Converts a JavaScript string buffer's contents into a
null-terminated UTF8 string, and copies the result into an external byte buffer.
@param inBuffer The source JSStringBuffer.
@param outBuffer The destination byte buffer into which to copy a UTF8 string
representation of inBuffer. The buffer must be at least bufferSize bytes in length.
On return, outBuffer contains a UTF8 string representation of inBuffer.
If bufferSize is too small, outBuffer will contain only partial results.
@param bufferSize The length of the external buffer in bytes.
@result The number of bytes written into outBuffer (including the null-terminator byte).
*/
size_t JSStringBufferGetCharactersUTF8(JSStringBufferRef inBuffer, char* outBuffer, size_t bufferSize);
/*!
@function
@abstract Tests whether the characters in two JavaScript string buffers match.
@param a The first JSStringBuffer to test.
@param b The second JSStringBuffer to test.
@result true if the characters in the two buffers match, otherwise false.
*/
bool JSStringBufferIsEqual(JSStringBufferRef a, JSStringBufferRef b);
/*!
@function
@abstract Tests whether the characters in a JavaScript string buffer match
the characters in a null-terminated UTF8 string.
@param a The JSStringBuffer to test.
@param b The null-terminated UTF8 string to test.
@result true if the characters in the two buffers match, otherwise false.
*/
bool JSStringBufferIsEqualUTF8(JSStringBufferRef a, const char* b);
#if defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>
// CFString convenience methods
JSStringBufferRef JSStringBufferCreateWithCFString(CFStringRef string);
/*!
@function
@abstract Creates a JavaScript string buffer 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 JSStringBuffer.
@result A JSStringBuffer containing string. Ownership follows the create rule.
*/
JSStringBufferRef JSStringBufferCreateCF(CFStringRef string);
/*!
@function
@abstract Creates a CFString form a JavaScript string buffer.
@param alloc The alloc parameter to pass to CFStringCreate.
@param buffer The JSStringBuffer to copy into the new CFString.
@result A CFString containing buffer. Ownership follows the create rule.
*/
CFStringRef CFStringCreateWithJSStringBuffer(CFAllocatorRef alloc, JSStringBufferRef buffer);
#endif // __APPLE__
......
......@@ -135,14 +135,14 @@ bool JSValueIsStrictEqual(JSContextRef context, JSValueRef a, JSValueRef b)
return result;
}
bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef object)
bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor)
{
ExecState* exec = toJS(context);
JSValue* jsValue = toJS(value);
JSObject* jsObject = toJS(object);
if (!jsObject->implementsHasInstance())
JSObject* jsConstructor = toJS(constructor);
if (!jsConstructor->implementsHasInstance())
return false;
bool result = jsObject->hasInstance(exec, jsValue);
bool result = jsConstructor->hasInstance(exec, jsValue);
if (exec->hadException())
exec->clearException();
return result;
......
......@@ -21,7 +21,7 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*