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;
125 NSEnumerator *keyEnum =
nil;
128
129 self = [super init];
130 if (
self ==
nil) problem =
@"allocation failure";
131 else
132 {
134
135 if (JS_IsExceptionPending(context))
136 {
137 JS_ClearPendingException(context);
138 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);
139 }
140
141
142 if (!problem)
143 {
145 if (
_jsSelf == NULL) problem =
@"allocation failure";
146 }
147
149 {
150 problem = @"could not add JavaScript root object";
151 }
152
154 {
155 problem = @"could not add JavaScript root object";
156 }
157
158 if (!problem)
159 {
161 {
162 problem = @"could not set private backreference";
163 }
164 }
165
166
168 {
171 };
173
175
176 if (!problem)
177 {
178 OOLog(
@"script.javaScript.willLoad",
@"About to load JavaScript %@", path);
180 }
182
183
184 NSDictionary *defaultProperties = [self defaultPropertiesFromPath:path];
185 for (keyEnum = [defaultProperties keyEnumerator]; (key = [keyEnum nextObject]); )
186 {
187 if ([key isKindOfClass:[NSString class]])
188 {
189 property = [defaultProperties objectForKey:key];
191 {
192
193 [self defineProperty:property named:key];
194 }
195 else
196 {
197
198 [self setProperty:property named:key];
199 }
200 }
201 }
202
203
204 if (!problem && properties !=
nil)
205 {
206 for (keyEnum = [properties keyEnumerator]; (key = [keyEnum nextObject]); )
207 {
208 if ([key isKindOfClass:[NSString class]])
209 {
210 property = [properties objectForKey:key];
211 [self defineProperty:property named:key];
212 }
213 }
214 }
215
216
217
218
219
220
221
222 jsid nameID =
OOJSID(
"name");
223 [self setProperty:[self scriptNameFromPath:path] withID:nameID inContext:context];
224
225
226 if (!problem)
227 {
229 if (!JS_ExecuteScript(context,
_jsSelf, script, &returnValue))
230 {
231 problem = @"could not run script";
232 }
234
235
236 JS_DestroyScript(context, script);
237 }
238
239 JS_RemoveObjectRoot(context, &scriptObject);
240
242
243 if (!problem)
244 {
245
247 name = [StrippedName([[
self propertyWithID:nameID inContext:context] description]) copy];
249 {
250 name = [[
self scriptNameFromPath:path] retain];
251 [self setProperty:name withID:nameID inContext:context];
252 }
253
254 version = [[[
self propertyWithID:OOJSID("version") inContext:context] description] copy];
255 description = [[[
self propertyWithID:OOJSID("description") inContext:context] description] copy];
256
258 }
259
261
263 }
264
265 if (problem)
266 {
267 OOLog(
@"script.javaScript.load.failed",
@"***** Error loading JavaScript script %@ -- %@", path, problem);
268 JS_ReportPendingException(context);
270 }
271
273
275 {
276 [[NSNotificationCenter defaultCenter] addObserver:self
277 selector:@selector(javaScriptEngineWillReset:)
278 name:kOOJavaScriptEngineWillResetNotification
280 }
281
282 return self;
283}
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,...)