Oolite
Loading...
Searching...
No Matches
OOJSScript.m
Go to the documentation of this file.
1/*
2
3OOJSScript.m
4
5JavaScript support for Oolite
6Copyright (C) 2007-2013 David Taylor and Jens Ayton.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#ifndef OO_CACHE_JS_SCRIPTS
26#define OO_CACHE_JS_SCRIPTS 1
27#endif
28
29#import "OOJSScript.h"
32
33#import "Entity.h"
37#import "OOConstToJSString.h"
38#import "OOConstToString.h"
39#import "OODebugStandards.h"
40#import "OOLogging.h"
42#import "OOPListParsing.h"
43
44#if OO_CACHE_JS_SCRIPTS
45#import "OOCacheManager.h"
46#include <jsxdrapi.h>
47#endif
48
54
55static JSObject* sScriptPrototype;
57
58static void AddStackToArrayReversed(NSMutableArray* array, RunningStack* stack);
59
60static JSScript* LoadScriptWithName(JSContext* context, NSString* path, JSObject* object, JSObject** outScriptObject, NSString** outErrorMessage);
61
62#if OO_CACHE_JS_SCRIPTS
63static NSData* CompiledScriptData(JSContext* context, JSScript* script);
64static JSScript* ScriptWithCompiledData(JSContext* context, NSData* data);
65#endif
66
67static NSString* StrippedName(NSString* string);
68
69static JSBool ScriptAddProperty(JSContext* context, JSObject* this, jsid propID, jsval* value);
70
71static JSClass sScriptClass = {
72 "Script",
73 JSCLASS_HAS_PRIVATE,
74
76 JS_PropertyStub,
77 JS_PropertyStub,
78 JS_StrictPropertyStub,
79 JS_EnumerateStub,
80 JS_ResolveStub,
81 JS_ConvertStub,
83};
84
85static JSFunctionSpec sScriptMethods[] = {
86 // JS name Function min args
87 {
88 "toString",
90 0,
91 },
92 { 0 }
93};
94
95@interface OOJSScript (OOPrivate)
96
97- (NSString*)scriptNameFromPath:(NSString*)path;
98- (NSDictionary*)defaultPropertiesFromPath:(NSString*)path;
99
100@end
101
102@implementation OOJSScript
103
104+ (id)scriptWithPath:(NSString*)path properties:(NSDictionary*)properties
105{
106 return [[[self alloc] initWithPath:path properties:properties] autorelease];
107}
108
109- (id)initWithPath:(NSString*)path properties:(NSDictionary*)properties
110{
111 JSContext* context = NULL;
112 NSString* problem = nil; // Acts as error flag.
113 JSScript* script = NULL;
114 JSObject* scriptObject = NULL;
115 jsval returnValue = JSVAL_VOID;
116 NSString* key = nil;
117 id property = nil;
118
119 self = [super init];
120 if (self == nil)
121 problem = @"allocation failure";
122 else {
123 context = OOJSAcquireContext();
124
125 if (JS_IsExceptionPending(context)) {
126 JS_ClearPendingException(context);
127 OOLogERR(@"script.javaScript.load.waitingException", @"Prior to loading script %@, there was a pending JavaScript exception, which has been cleared. This is an internal error, please report it.", path);
128 }
129
130 // Set up JS object
131 if (!problem) {
132 _jsSelf = JS_NewObject(context, &sScriptClass, sScriptPrototype, NULL);
133 if (_jsSelf == NULL)
134 problem = @"allocation failure";
135 }
136
137 if (!problem && !OOJSAddGCObjectRoot(context, &_jsSelf, "Script object")) {
138 problem = @"could not add JavaScript root object";
139 }
140
141 if (!problem && !OOJSAddGCObjectRoot(context, &scriptObject, "Script GC holder")) {
142 problem = @"could not add JavaScript root object";
143 }
144
145 if (!problem) {
146 if (!JS_SetPrivate(context, _jsSelf, OOConsumeReference([self weakRetain]))) {
147 problem = @"could not set private backreference";
148 }
149 }
150
151 // Push self on stack of running scripts.
152 RunningStack stackElement = {
153 .back = sRunningStack,
154 .current = self
155 };
156 sRunningStack = &stackElement;
157
158 filePath = [path retain];
159
160 if (!problem) {
161 OOLog(@"script.javaScript.willLoad", @"About to load JavaScript %@", path);
162 script = LoadScriptWithName(context, path, _jsSelf, &scriptObject, &problem);
163 }
164 OOLogIndentIf(@"script.javaScript.willLoad");
165
166 // Set default properties from manifest.plist
167 NSDictionary* defaultProperties = [self defaultPropertiesFromPath:path];
168 foreachkey(key, defaultProperties)
169 {
170 if ([key isKindOfClass:[NSString class]]) {
171 property = [defaultProperties objectForKey:key];
172 if ([key isEqualToString:kLocalManifestProperty]) {
173 // this must not be editable
174 [self defineProperty:property named:key];
175 } else {
176 // can be overwritten by script itself
177 [self setProperty:property named:key];
178 }
179 }
180 }
181
182 // Set properties. (read-only)
183 if (!problem && properties != nil) {
184 foreachkey(key, properties)
185 {
186 if ([key isKindOfClass:[NSString class]]) {
187 property = [properties objectForKey:key];
188 [self defineProperty:property named:key];
189 }
190 }
191 }
192
193 /* Set initial name (in case of script error during initial run).
194 The "name" ivar is not set here, so the property can be fetched from JS
195 if we fail during setup. However, the "name" ivar is set later so that
196 the script object can't be renamed after the initial run. This could
197 probably also be achieved by fiddling with JS property attributes.
198 */
199 jsid nameID = OOJSID("name");
200 [self setProperty:[self scriptNameFromPath:path] withID:nameID inContext:context];
201
202 // Run the script (allowing it to set up the properties we need, as well as setting up those event handlers)
203 if (!problem) {
205 if (!JS_ExecuteScript(context, _jsSelf, script, &returnValue)) {
206 problem = @"could not run script";
207 }
209
210 // We don't need the script any more - the event handlers hang around as long as the JS object exists.
211 JS_DestroyScript(context, script);
212 }
213
214 JS_RemoveObjectRoot(context, &scriptObject);
215
216 sRunningStack = stackElement.back;
217
218 if (!problem) {
219 // Get display attributes from script
220 DESTROY(name);
221 name = [StrippedName([[self propertyWithID:nameID inContext:context] description]) copy];
222 if (name == nil) {
223 name = [[self scriptNameFromPath:path] retain];
224 [self setProperty:name withID:nameID inContext:context];
225 }
226
227 version = [[[self propertyWithID:OOJSID("version") inContext:context] description] copy];
228 description = [[[self propertyWithID:OOJSID("description") inContext:context] description] copy];
229
230 OOLog(@"script.javaScript.load.success", @"Loaded JavaScript: %@ -- %@", [self displayName], description ? description : (NSString*)@"(no description)");
231 }
232
233 OOLogOutdentIf(@"script.javaScript.willLoad");
234
235 DESTROY(filePath); // Only used for error reporting during startup.
236 }
237
238 if (problem) {
239 OOLog(@"script.javaScript.load.failed", @"***** Error loading JavaScript script %@ -- %@", path, problem);
240 JS_ReportPendingException(context);
241 DESTROY(self);
242 }
243
244 OOJSRelinquishContext(context);
245
246 if (self != nil) {
247 [[NSNotificationCenter defaultCenter] addObserver:self
248 selector:@selector(javaScriptEngineWillReset:)
249 name:kOOJavaScriptEngineWillResetNotification
251 }
252
253 return self;
254}
255
256- (void)dealloc
257{
258 [[NSNotificationCenter defaultCenter] removeObserver:self
259 name:kOOJavaScriptEngineWillResetNotification
261
262 DESTROY(name);
266
267 if (_jsSelf != NULL) {
268 JSContext* context = OOJSAcquireContext();
269
270 OOJSObjectWrapperFinalize(context, _jsSelf); // Release weakref to self
271 JS_RemoveObjectRoot(context, &_jsSelf); // Unroot jsSelf
272
273 OOJSRelinquishContext(context);
274 }
275
277
278 [super dealloc];
279}
280
281- (NSString*)oo_jsClassName
282{
283 return @"Script";
284}
285
287{
288 if (_jsSelf != NULL)
289 return [super descriptionComponents];
290 else
291 return @"invalid script";
292}
293
294- (void)javaScriptEngineWillReset:(NSNotification*)notification
295{
296 // All scripts become invalid when the JS engine resets.
297 if (_jsSelf != NULL) {
298 _jsSelf = NULL;
299 JSContext* context = OOJSAcquireContext();
300 JS_RemoveObjectRoot(context, &_jsSelf);
301 OOJSRelinquishContext(context);
302 }
303}
304
305+ (OOJSScript*)currentlyRunningScript
306{
307 if (sRunningStack == NULL)
308 return NULL;
309 return sRunningStack->current;
310}
311
312+ (NSArray*)scriptStack
313{
314 NSMutableArray* result = nil;
315
316 result = [NSMutableArray array];
318 return result;
319}
320
322{
323 if (weakSelf == nil)
325 return [weakSelf retain];
326}
327
328- (void)weakRefDied:(OOWeakReference*)weakRef
329{
330 if (weakRef == weakSelf)
331 weakSelf = nil;
332}
333
334- (NSString*)name
335{
336 if (name == nil)
337 name = [[self propertyNamed:@"name"] copy];
338 if (name == nil)
339 return [self scriptNameFromPath:filePath]; // Special case for parse errors during load.
340 return name;
341}
342
344{
345 return description;
346}
347
348- (NSString*)version
349{
350 return version;
351}
352
353- (void)runWithTarget:(Entity*)target
354{
355}
356
357- (BOOL)callMethod:(jsid)methodID
358 inContext:(JSContext*)context
359 withArguments:(jsval*)argv
360 count:(intN)argc
361 result:(jsval*)outResult
362{
363 NSParameterAssert(name != NULL && (argv != NULL || argc == 0) && context != NULL && JS_IsInRequest(context));
364 if (_jsSelf == NULL)
365 return NO;
366
367 JSObject* root = NULL;
368 BOOL OK = NO;
369 jsval method;
370 jsval ignoredResult = JSVAL_VOID;
371
372 if (outResult == NULL)
373 outResult = &ignoredResult;
374 OOJSAddGCObjectRoot(context, &root, "OOJSScript method root");
375
376 if (EXPECT(JS_GetMethodById(context, _jsSelf, methodID, &root, &method) && !JSVAL_IS_VOID(method))) {
377#ifndef NDEBUG
378 if (JS_IsExceptionPending(context)) {
379 OOLog(@"script.internalBug", @"Exception pending on context before calling method in %s, clearing. This is an internal error, please report it.", __PRETTY_FUNCTION__);
380 JS_ClearPendingException(context);
381 }
382
383 OOLog(@"script.javaScript.call", @"Calling [%@].%@()", [self name], OOStringFromJSID(methodID));
384 OOLogIndentIf(@"script.javaScript.call");
385#endif
386
387 // Push self on stack of running scripts.
388 RunningStack stackElement = {
389 .back = sRunningStack,
390 .current = self
391 };
392 sRunningStack = &stackElement;
393
394 // Call the method.
396 OK = JS_CallFunctionValue(context, _jsSelf, method, argc, argv, outResult);
398
399 if (JS_IsExceptionPending(context)) {
400 JS_ReportPendingException(context);
401 OK = NO;
402 }
403
404 // Pop running scripts stack
405 sRunningStack = stackElement.back;
406
407#ifndef NDEBUG
408 OOLogOutdentIf(@"script.javaScript.call");
409#endif
410 }
411
412 JS_RemoveObjectRoot(context, &root);
413
414 return OK;
415}
416
417- (id)propertyWithID:(jsid)propID inContext:(JSContext*)context
418{
419 NSParameterAssert(context != NULL && JS_IsInRequest(context));
420 if (_jsSelf == NULL)
421 return nil;
422
423 jsval jsValue = JSVAL_VOID;
424 if (JS_GetPropertyById(context, _jsSelf, propID, &jsValue)) {
425 return OOJSNativeObjectFromJSValue(context, jsValue);
426 }
427 return nil;
428}
429
430- (BOOL)setProperty:(id)value withID:(jsid)propID inContext:(JSContext*)context
431{
432 NSParameterAssert(context != NULL && JS_IsInRequest(context));
433 if (_jsSelf == NULL)
434 return NO;
435
436 jsval jsValue = OOJSValueFromNativeObject(context, value);
437 return JS_SetPropertyById(context, _jsSelf, propID, &jsValue);
438}
439
440- (BOOL)defineProperty:(id)value withID:(jsid)propID inContext:(JSContext*)context
441{
442 NSParameterAssert(context != NULL && JS_IsInRequest(context));
443 if (_jsSelf == NULL)
444 return NO;
445
446 jsval jsValue = OOJSValueFromNativeObject(context, value);
447 return JS_DefinePropertyById(context, _jsSelf, propID, jsValue, NULL, NULL, OOJS_PROP_READONLY);
448}
449
450- (id)propertyNamed:(NSString*)propName
451{
452 if (propName == nil)
453 return nil;
454 if (_jsSelf == NULL)
455 return nil;
456
457 JSContext* context = OOJSAcquireContext();
458 id result = [self propertyWithID:OOJSIDFromString(propName) inContext:context];
459 OOJSRelinquishContext(context);
460
461 return result;
462}
463
464- (BOOL)setProperty:(id)value named:(NSString*)propName
465{
466 if (value == nil || propName == nil)
467 return NO;
468 if (_jsSelf == NULL)
469 return NO;
470
471 JSContext* context = OOJSAcquireContext();
472 BOOL result = [self setProperty:value withID:OOJSIDFromString(propName) inContext:context];
473 OOJSRelinquishContext(context);
474
475 return result;
476}
477
478- (BOOL)defineProperty:(id)value named:(NSString*)propName
479{
480 if (value == nil || propName == nil)
481 return NO;
482 if (_jsSelf == NULL)
483 return NO;
484
485 JSContext* context = OOJSAcquireContext();
486 BOOL result = [self defineProperty:value withID:OOJSIDFromString(propName) inContext:context];
487 OOJSRelinquishContext(context);
488
489 return result;
490}
491
492- (jsval)oo_jsValueInContext:(JSContext*)context
493{
494 if (_jsSelf == NULL)
495 return JSVAL_VOID;
496 return OBJECT_TO_JSVAL(_jsSelf);
497}
498
499+ (void)pushScript:(OOJSScript*)script
500{
501 RunningStack* element = NULL;
502
503 element = malloc(sizeof *element);
504 if (element == NULL)
505 exit(EXIT_FAILURE);
506
507 element->back = sRunningStack;
508 element->current = script;
509 sRunningStack = element;
510}
511
512+ (void)popScript:(OOJSScript*)script
513{
514 RunningStack* element = NULL;
515
516 assert(sRunningStack->current == script);
517
518 element = sRunningStack;
520 free(element);
521}
522
523@end
524
525@implementation OOJSScript (OOPrivate)
526
527/* Generate default name for script which doesn't set its name property when
528 first run.
529
530 The generated name is <name>.anon-script, where <name> is selected as
531 follows:
532 * If path is nil (futureproofing), use the address of the script object.
533 * If the file's name is something other than script.*, use the file name.
534 * If the containing directory is something other than Config, use the
535 containing directory's name.
536 * Otherwise, use the containing directory's parent (which will generally
537 be an OXP root directory).
538 * If either of the two previous steps results in an empty string, fall
539 back on the full path.
540*/
541- (NSString*)scriptNameFromPath:(NSString*)path
542{
543 NSString* lastComponent = nil;
544 NSString* truncatedPath = nil;
545 NSString* theName = nil;
546
547 if (path == nil)
548 theName = [NSString stringWithFormat:@"%p", self];
549 else {
550 lastComponent = [path lastPathComponent];
551 if (![lastComponent hasPrefix:@"script."])
552 theName = lastComponent;
553 else {
554 truncatedPath = [path stringByDeletingLastPathComponent];
555 if (NSOrderedSame == [[truncatedPath lastPathComponent] caseInsensitiveCompare:@"Config"]) {
556 truncatedPath = [truncatedPath stringByDeletingLastPathComponent];
557 }
558 if (NSOrderedSame == [[truncatedPath pathExtension] caseInsensitiveCompare:@"oxp"]) {
559 truncatedPath = [truncatedPath stringByDeletingPathExtension];
560 }
561
562 lastComponent = [truncatedPath lastPathComponent];
563 theName = lastComponent;
564 }
565 }
566
567 if (0 == [theName length])
568 theName = path;
569
570 return StrippedName([theName stringByAppendingString:@".anon-script"]);
571}
572
573- (NSDictionary*)defaultPropertiesFromPath:(NSString*)path
574{
575 // remove file name, remove OXP subfolder, add manifest.plist
576 NSString* manifestPath = [[[path stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"manifest.plist"];
577 NSDictionary* manifest = OODictionaryFromFile(manifestPath);
578 NSMutableDictionary* properties = [NSMutableDictionary dictionaryWithCapacity:3];
579 /* __oolite.tmp.* is allocated for OXPs without manifests. Its
580 * values are meaningless and shouldn't be used here */
581 if (manifest != nil && ![[manifest oo_stringForKey:kOOManifestIdentifier] hasPrefix:@"__oolite.tmp."]) {
582 if ([manifest objectForKey:kOOManifestVersion] != nil) {
583 [properties setObject:[manifest oo_stringForKey:kOOManifestVersion] forKey:@"version"];
584 }
585 if ([manifest objectForKey:kOOManifestIdentifier] != nil) {
586 // used for system info
587 [properties setObject:[manifest oo_stringForKey:kOOManifestIdentifier] forKey:kLocalManifestProperty];
588 }
589 if ([manifest objectForKey:kOOManifestAuthor] != nil) {
590 [properties setObject:[manifest oo_stringForKey:kOOManifestAuthor] forKey:@"author"];
591 }
592 if ([manifest objectForKey:kOOManifestLicense] != nil) {
593 [properties setObject:[manifest oo_stringForKey:kOOManifestLicense] forKey:@"license"];
594 }
595 }
596 return properties;
597}
598
599@end
600
601@implementation OOScript (JavaScriptEvents)
602
603- (BOOL)callMethod:(jsid)methodID
604 inContext:(JSContext*)context
605 withArguments:(jsval*)argv
606 count:(intN)argc
607 result:(jsval*)outResult
608{
609 return NO;
610}
611
612@end
613
614void InitOOJSScript(JSContext* context, JSObject* global)
615{
616 sScriptPrototype = JS_InitClass(context, global, NULL, &sScriptClass, OOJSUnconstructableConstruct, 0, NULL, sScriptMethods, NULL, NULL);
618}
619
620static JSBool ScriptAddProperty(JSContext* context, JSObject* this, jsid propID, jsval* value)
621{
622 // Complain about attempts to set the property tickle.
623 if (JSID_IS_STRING(propID)) {
624 JSString* propName = JSID_TO_STRING(propID);
625 JSBool match;
626 if (JS_StringEqualsAscii(context, propName, "tickle", &match) && match) {
627 OOJSScript* thisScript = OOJSNativeObjectOfClassFromJSObject(context, this, [OOJSScript class]);
628 OOJSReportWarning(context, @"Script %@ appears to use the tickle() event handler, which is no longer supported.", [thisScript name]);
629 }
630 }
631
632 return YES;
633}
634
635static void AddStackToArrayReversed(NSMutableArray* array, RunningStack* stack)
636{
637 if (stack != NULL) {
638 AddStackToArrayReversed(array, stack->back);
639 [array addObject:stack->current];
640 }
641}
642
643static JSScript* LoadScriptWithName(JSContext* context, NSString* path, JSObject* object, JSObject** outScriptObject, NSString** outErrorMessage)
644{
645#if OO_CACHE_JS_SCRIPTS
646 OOCacheManager* cache = nil;
647#endif
648 NSString* fileContents = nil;
649 NSData* data = nil;
650 JSScript* script = NULL;
651
652 NSCParameterAssert(outScriptObject != NULL && outErrorMessage != NULL);
653 *outErrorMessage = nil;
654
655#if OO_CACHE_JS_SCRIPTS
656 // Look for cached compiled script
657 cache = [OOCacheManager sharedCache];
658 data = [cache objectForKey:path inCache:@"compiled JavaScript scripts"];
659 if (data != nil) {
660 script = ScriptWithCompiledData(context, data);
661 }
662#endif
663
664 if (script == NULL) {
665 fileContents = [NSString stringWithContentsOfUnicodeFile:path];
666
667 if (fileContents != nil) {
668#ifdef OO_DEBUG_MONITOR_ENABLED
669 /* FIXME: this isn't strictly the right test, since strict
670 * mode can be enabled with this string within a function
671 * definition, but it seems unlikely anyone is actually doing
672 * that here. */
673 if ([fileContents rangeOfString:@"\"use strict\";"].location == NSNotFound && [fileContents rangeOfString:@"'use strict';"].location == NSNotFound) {
674 OOStandardsDeprecated([NSString stringWithFormat:@"Script %@ does not \"use strict\";", path]);
675 if (OOEnforceStandards()) {
676 // prepend it anyway
677 // TODO: some time after 1.82, make this required
678 fileContents = [@"\"use strict\";\n" stringByAppendingString:fileContents];
679 }
680 }
681#endif
682 data = [fileContents utf16DataWithBOM:NO];
683 }
684 if (data == nil)
685 *outErrorMessage = @"could not load file";
686 else {
687 script = JS_CompileUCScript(context, object, [data bytes], [data length] / sizeof(unichar), [path UTF8String], 1);
688 if (script != NULL)
689 *outScriptObject = JS_NewScriptObject(context, script);
690 else
691 *outErrorMessage = @"compilation failed";
692 }
693
694#if OO_CACHE_JS_SCRIPTS
695 if (script != NULL) {
696 // Write compiled script to cache
697 data = CompiledScriptData(context, script);
698 [cache setObject:data forKey:path inCache:@"compiled JavaScript scripts"];
699 }
700#endif
701 }
702
703 return script;
704}
705
706#if OO_CACHE_JS_SCRIPTS
707static NSData* CompiledScriptData(JSContext* context, JSScript* script)
708{
709 JSXDRState* xdr = NULL;
710 NSData* result = nil;
711 uint32 length;
712 void* bytes = NULL;
713
714 xdr = JS_XDRNewMem(context, JSXDR_ENCODE);
715 if (xdr != NULL) {
716 if (JS_XDRScript(xdr, &script)) {
717 bytes = JS_XDRMemGetData(xdr, &length);
718 if (bytes != NULL) {
719 result = [NSData dataWithBytes:bytes length:length];
720 }
721 }
722 JS_XDRDestroy(xdr);
723 }
724
725 return result;
726}
727
728static JSScript* ScriptWithCompiledData(JSContext* context, NSData* data)
729{
730 JSXDRState* xdr = NULL;
731 JSScript* result = NULL;
732
733 if (data == nil)
734 return NULL;
735
736 xdr = JS_XDRNewMem(context, JSXDR_DECODE);
737 if (xdr != NULL) {
738 NSUInteger length = [data length];
739 if (EXPECT_NOT(length > UINT32_MAX))
740 return NULL;
741
742 JS_XDRMemSetData(xdr, (void*)[data bytes], (uint32_t)length);
743 if (!JS_XDRScript(xdr, &result))
744 result = NULL;
745
746 JS_XDRMemSetData(xdr, NULL, 0); // Don't let it be freed by XDRDestroy
747 JS_XDRDestroy(xdr);
748 }
749
750 return result;
751}
752#endif
753
754static NSString* StrippedName(NSString* string)
755{
756 static NSCharacterSet* invalidSet = nil;
757 if (invalidSet == nil)
758 invalidSet = [[NSCharacterSet characterSetWithCharactersInString:@"_ \t\n\r\v"] retain];
759
760 return [string stringByTrimmingCharactersInSet:invalidSet];
761}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
#define DESTROY(x)
#define foreachkey(VAR, DICT)
id OOConsumeReference(id OO_NS_CONSUMED value)
#define EXPECT_NOT(x)
#define EXPECT(x)
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
#define kOOJSLongTimeLimit
#define OOJSStartTimeLimiterWithTimeLimit(limit)
#define OOJSID(str)
Definition OOJSPropID.h:42
void InitOOJSScript(JSContext *context, JSObject *global)
Definition OOJSScript.m:614
static NSString *const kLocalManifestProperty
Definition OOJSScript.h:28
static NSString * StrippedName(NSString *string)
Definition OOJSScript.m:754
static JSBool ScriptAddProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSScript.m:620
static NSData * CompiledScriptData(JSContext *context, JSScript *script)
Definition OOJSScript.m:707
static JSObject * sScriptPrototype
Definition OOJSScript.m:55
static RunningStack * sRunningStack
Definition OOJSScript.m:56
static JSFunctionSpec sScriptMethods[]
Definition OOJSScript.m:85
struct RunningStack RunningStack
Definition OOJSScript.m:49
static JSClass sScriptClass
Definition OOJSScript.m:71
static JSScript * LoadScriptWithName(JSContext *context, NSString *path, JSObject *object, JSObject **outScriptObject, NSString **outErrorMessage)
Definition OOJSScript.m:643
static void AddStackToArrayReversed(NSMutableArray *array, RunningStack *stack)
Definition OOJSScript.m:635
static JSScript * ScriptWithCompiledData(JSContext *context, NSData *data)
Definition OOJSScript.m:728
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
void OOJSReportWarning(JSContext *context, NSString *format,...)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
#define JS_IsInRequest(context)
NSString * OOStringFromJSID(jsid propID)
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
OOINLINE JSContext * OOJSAcquireContext(void)
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
id OOJSNativeObjectOfClassFromJSObject(JSContext *context, JSObject *object, Class requiredClass)
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
#define OOLogOutdentIf(class)
Definition OOLogging.h:112
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OOLogIndentIf(class)
Definition OOLogging.h:107
static NSString *const kOOManifestLicense
static NSString *const kOOManifestIdentifier
static NSString *const kOOManifestVersion
static NSString *const kOOManifestAuthor
NSDictionary * OODictionaryFromFile(NSString *path)
return nil
static NSString * StrippedName(NSString *string)
Definition OOJSScript.m:967
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
OOWeakReference * weakSelf
Definition OOJSScript.h:39
NSString * version
Definition OOJSScript.m:113
NSString * filePath
Definition OOJSScript.h:37
NSString * oo_jsClassName()
Definition OOJSScript.m:281
NSString * description
Definition OOJSScript.h:35
JSObject * _jsSelf
Definition OOJSScript.h:32
NSString * descriptionComponents()
Definition OOJSScript.m:286
NSString * name
Definition OOJSScript.m:108
NSString * scriptDescription()
Definition OOJSScript.m:343
void dealloc()
Definition OOJSScript.m:256
OOJavaScriptEngine * sharedEngine()
id weakRefWithObject:(id< OOWeakReferenceSupport > object)
OOJSScript * current
Definition OOJSScript.m:52
RunningStack * back
Definition OOJSScript.m:51