32- (id)initWithFunction:(JSFunction*)function context:(JSContext*)context
34 NSParameterAssert(context != NULL);
36 if (
function == NULL) {
41 if ((
self = [super init])) {
44 _name = [OOStringFromJSString(context, JS_GetFunctionId(function)) retain];
46 [[NSNotificationCenter defaultCenter] addObserver:
self
47 selector:@selector(deleteJSValue)
48 name:kOOJavaScriptEngineWillResetNotification
55- (id)initWithName:(NSString*)name
56 scope:(JSObject*)scope
58 argumentCount:(NSUInteger)argCount
59 argumentNames:(const
char**)argNames
60 fileName:(NSString*)fileName
61 lineNumber:(NSUInteger)lineNumber
62 context:(JSContext*)context
65 BOOL releaseContext = NO;
66 jschar* buffer = NULL;
70 if (context == NULL) {
77 if (code ==
nil || (argCount > 0 && argNames == NULL))
82 assert(
sizeof(jschar) ==
sizeof(unichar));
84 length = [code length];
85 buffer = malloc(
sizeof(jschar) * length);
91 assert(argCount < UINT32_MAX);
93 [code getCharacters:buffer];
95 function = JS_CompileUCFunction(context, scope, [
name UTF8String], (uint32_t)argCount, argNames, buffer, length, [fileName UTF8String], (uint32_t)lineNumber);
103 self = [
self initWithFunction:function context:context];
118 JS_RemoveObjectRoot(context, (JSObject**)&
_function);
123 name:kOOJavaScriptEngineWillResetNotification
140 name =
@"<anonymous>";
141 return [
NSString stringWithFormat:@"%@()", name];
157 return OBJECT_TO_JSVAL(JS_GetFunctionObject(
_function));
163- (BOOL)evaluateWithContext:(JSContext*)context
164 scope:(JSObject*)jsThis
167 result:(jsval*)result
171 BOOL OK = JS_CallFunction(context, jsThis,
_function, argc, argv, result);
179- (BOOL)evaluateWithContext:(JSContext*)context
181 arguments:(NSArray*)arguments
182 result:(jsval*)result
185 assert(argc < UINT32_MAX);
188 for (i = 0; i < argc; i++) {
189 argv[
i] = [[
arguments objectAtIndex:i] oo_jsValueInContext:context];
193 JSObject* scopeObj = NULL;
196 OK = JS_ValueToObject(context, [jsThis oo_jsValueInContext:context], &scopeObj);
204 for (i = 0; i < argc; i++) {
205 JS_RemoveValueRoot(context, &argv[i]);
211- (id)evaluateWithContext:(JSContext*)context
213 arguments:(NSArray*)arguments
216 BOOL OK = [
self evaluateWithContext:context
226- (BOOL)evaluatePredicateWithContext:(JSContext*)context
228 arguments:(NSArray*)arguments
231 BOOL OK = [
self evaluateWithContext:context
237 OK = JS_ValueToBoolean(context, result, &retval);
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define OOJSAddGCValueRoot(context, root, name)
NSString * descriptionComponents()
BOOL evaluateWithContext:scope:argc:argv:result:(JSContext *context,[scope] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *result)
void pushScript:(OOJSScript *script)
void popScript:(OOJSScript *script)
JSObject * globalObject()
OOJavaScriptEngine * sharedEngine()