The last thing I want to do is make you guys job with patches harder, so I thought I'd seek some advice. I created two convenience functions for building arrays with consecutive indexes (i.e., new Array(1,2,3,4,5,6,7,8)). I haven't gone over all the style guidelines yet (but did a quick overview.) I'll do that before I go further, but my question is this: This patch doesn't use anything internal inside JSC itself (it was created outside in my code.) Therefore, it's probably a slow/less efficient path. Is this a bad idea? If so, I'll just scrap the idea before going any further. The functions are: (in JSObjectRef) JSValueRef JSObjectSetArray(JSContextRef ctx,size_t valueCount,const JSValueRef values[],JSValueRef *exception) { JSObjectRef arrayProtoObj; JSStringRef jsStr; JSValueRef arrayVal; // get the array prototype jsStr=JSStringCreateWithUTF8CString("Array"); arrayVal=JSObjectGetProperty(ctx,JSContextGetGlobalObject(ctx),jsStr,exception); JSStringRelease(jsStr); if (arrayVal==NULL) return(NULL); arrayProtoObj=JSValueToObject(ctx,arrayVal,exception); if (arrayProtoObj==NULL) return(NULL); // create the new array object return((JSValueRef)JSObjectCallAsConstructor(ctx,arrayProtoObj,valueCount,values,exception)); } (in JSValueRef) bool JSValueIsArray(JSContextRef ctx,JSValueRef value) { char *ch,str[64]; JSStringRef jsStr; JSObjectRef arrayObj; JSValueRef val; // only check objects if (!JSValueIsObject(ctx,value)) return(FALSE); // get constructor arrayObj=JSValueToObject(ctx,value,NULL); if (arrayObj==NULL) return(FALSE); jsStr=JSStringCreateWithUTF8CString("constructor"); val=JSObjectGetProperty(ctx,arrayObj,jsStr,NULL); JSStringRelease(jsStr); if (val==NULL) return(FALSE); // get constructor as a function jsStr=JSValueToStringCopy(ctx,val,NULL); if (jsStr==NULL) return(FALSE); JSStringGetUTF8CString(jsStr,str,64); str[63]=0x0; JSStringRelease(jsStr); // special check to make sure we don't have Array // anywhere else in a function body or there just // instead a function body ch=strchr(str,'{'); if (ch==NULL) return(FALSE); *ch=0x0; // look for array in string return(strstr(str,"Array")!=NULL); } Thanks for any help ... [>] Brian
On Aug 19, 2009, at 11:37 AM, Brian Barnes wrote:
JSValueRef JSObjectSetArray(JSContextRef ctx,size_t valueCount,const JSValueRef values[],JSValueRef *exception)
This looks to be duplicating the functionality of JSObjectMakeArray (see <http://trac.webkit.org/browser/trunk/JavaScriptCore/API/JSObjectRef.h#L433
).
bool JSValueIsArray(JSContextRef ctx,JSValueRef value) { char *ch,str[64]; JSStringRef jsStr; JSObjectRef arrayObj; JSValueRef val; // only check objects
if (!JSValueIsObject(ctx,value)) return(FALSE); // get constructor
arrayObj=JSValueToObject(ctx,value,NULL); if (arrayObj==NULL) return(FALSE);
jsStr=JSStringCreateWithUTF8CString("constructor"); val=JSObjectGetProperty(ctx,arrayObj,jsStr,NULL); JSStringRelease(jsStr);
if (val==NULL) return(FALSE);
// get constructor as a function
jsStr=JSValueToStringCopy(ctx,val,NULL); if (jsStr==NULL) return(FALSE);
JSStringGetUTF8CString(jsStr,str,64); str[63]=0x0;
JSStringRelease(jsStr);
// special check to make sure we don't have Array // anywhere else in a function body or there just // instead a function body
ch=strchr(str,'{'); if (ch==NULL) return(FALSE);
*ch=0x0;
// look for array in string
return(strstr(str,"Array")!=NULL); }
There are definitely more efficient ways to do this below the JSC API layer. I don't think there's any API to do this currently. -Adam
Adam Roben wrote:
On Aug 19, 2009, at 11:37 AM, Brian Barnes wrote:
JSValueRef JSObjectSetArray(JSContextRef ctx,size_t valueCount,const JSValueRef values[],JSValueRef *exception)
This looks to be duplicating the functionality of JSObjectMakeArray (see <http://trac.webkit.org/browser/trunk/JavaScriptCore/API/JSObjectRef.h#L433>).
Ah -- from now on I depend on the headers, the docs I was using: http://developer.apple.com/documentation/Carbon/Reference/WebKit_JavaScriptC... Are way out of date. Thanks, and sorry for the duplication. A ValueIsArray would be useful (and probably a parallel IsDate as that is part of the ObjectRef). [>] Brian
participants (2)
-
Adam Roben
-
Brian Barnes