118 :(NSString *)path properties:(NSDictionary *)properties
119{
120 JSContext *context = NULL;
121 NSString *problem =
nil;
122 JSScript *script = NULL;
123 JSObject *scriptObject = NULL;
124 jsval returnValue = JSVAL_VOID;
127
128 self = [super init];
129 if (
self ==
nil) problem =
@"allocation failure";
130 else
131 {
133
134 if (JS_IsExceptionPending(context))
135 {
136 JS_ClearPendingException(context);
137 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);
138 }
139
140
141 if (!problem)
142 {
144 if (
_jsSelf == NULL) problem =
@"allocation failure";
145 }
146
148 {
149 problem = @"could not add JavaScript root object";
150 }
151
153 {
154 problem = @"could not add JavaScript root object";
155 }
156
157 if (!problem)
158 {
160 {
161 problem = @"could not set private backreference";
162 }
163 }
164
165
167 {
170 };
172
174
175 if (!problem)
176 {
177 OOLog(
@"script.javaScript.willLoad",
@"About to load JavaScript %@", path);
179 }
181
182
183 NSDictionary *defaultProperties = [self defaultPropertiesFromPath:path];
185 {
186 if ([key isKindOfClass:[NSString class]])
187 {
188 property = [defaultProperties objectForKey:key];
190 {
191
192 [self defineProperty:property named:key];
193 }
194 else
195 {
196
197 [self setProperty:property named:key];
198 }
199 }
200 }
201
202
203 if (!problem && properties !=
nil)
204 {
206 {
207 if ([key isKindOfClass:[NSString class]])
208 {
209 property = [properties objectForKey:key];
210 [self defineProperty:property named:key];
211 }
212 }
213 }
214
215
216
217
218
219
220
221 jsid nameID =
OOJSID(
"name");
222 [self setProperty:[self scriptNameFromPath:path] withID:nameID inContext:context];
223
224
225 if (!problem)
226 {
228 if (!JS_ExecuteScript(context,
_jsSelf, script, &returnValue))
229 {
230 problem = @"could not run script";
231 }
233
234
235 JS_DestroyScript(context, script);
236 }
237
238 JS_RemoveObjectRoot(context, &scriptObject);
239
241
242 if (!problem)
243 {
244
246 name = [StrippedName([[
self propertyWithID:nameID inContext:context] description]) copy];
248 {
249 name = [[
self scriptNameFromPath:path] retain];
250 [self setProperty:name withID:nameID inContext:context];
251 }
252
253 version = [[[
self propertyWithID:OOJSID("version") inContext:context] description] copy];
254 description = [[[
self propertyWithID:OOJSID("description") inContext:context] description] copy];
255
257 }
258
260
262 }
263
264 if (problem)
265 {
266 OOLog(
@"script.javaScript.load.failed",
@"***** Error loading JavaScript script %@ -- %@", path, problem);
267 JS_ReportPendingException(context);
269 }
270
272
274 {
275 [[NSNotificationCenter defaultCenter] addObserver:self
276 selector:@selector(javaScriptEngineWillReset:)
277 name:kOOJavaScriptEngineWillResetNotification
279 }
280
281 return self;
282}
#define foreachkey(VAR, DICT)
id OOConsumeReference(id OO_NS_CONSUMED value)
#define kOOJSLongTimeLimit
#define OOJSStartTimeLimiterWithTimeLimit(limit)
static NSString *const kLocalManifestProperty
static JSObject * sScriptPrototype
static JSClass sScriptClass
static JSScript * LoadScriptWithName(JSContext *context, NSString *path, JSObject *object, JSObject **outScriptObject, NSString **outErrorMessage)
#define OOLogERR(class, format,...)