68
69
static void cleanupGlobalData(JSGlobalData*);
69
70
static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer);
71
static JSValuePtr functionPrint(ExecState*, JSObject*, JSValuePtr, const ArgList&);
72
static JSValuePtr functionDebug(ExecState*, JSObject*, JSValuePtr, const ArgList&);
73
static JSValuePtr functionGC(ExecState*, JSObject*, JSValuePtr, const ArgList&);
74
static JSValuePtr functionVersion(ExecState*, JSObject*, JSValuePtr, const ArgList&);
75
static JSValuePtr functionRun(ExecState*, JSObject*, JSValuePtr, const ArgList&);
76
static JSValuePtr functionLoad(ExecState*, JSObject*, JSValuePtr, const ArgList&);
77
static JSValuePtr functionReadline(ExecState*, JSObject*, JSValuePtr, const ArgList&);
78
static NO_RETURN JSValuePtr functionQuit(ExecState*, JSObject*, JSValuePtr, const ArgList&);
72
static JSValue JSC_HOST_CALL functionPrint(ExecState*, JSObject*, JSValue, const ArgList&);
73
static JSValue JSC_HOST_CALL functionDebug(ExecState*, JSObject*, JSValue, const ArgList&);
74
static JSValue JSC_HOST_CALL functionGC(ExecState*, JSObject*, JSValue, const ArgList&);
75
static JSValue JSC_HOST_CALL functionVersion(ExecState*, JSObject*, JSValue, const ArgList&);
76
static JSValue JSC_HOST_CALL functionRun(ExecState*, JSObject*, JSValue, const ArgList&);
77
static JSValue JSC_HOST_CALL functionLoad(ExecState*, JSObject*, JSValue, const ArgList&);
78
static JSValue JSC_HOST_CALL functionReadline(ExecState*, JSObject*, JSValue, const ArgList&);
79
static NO_RETURN JSValue JSC_HOST_CALL functionQuit(ExecState*, JSObject*, JSValue, const ArgList&);
81
#if ENABLE(SAMPLING_FLAGS)
82
static JSValue JSC_HOST_CALL functionSetSamplingFlags(ExecState*, JSObject*, JSValue, const ArgList&);
83
static JSValue JSC_HOST_CALL functionClearSamplingFlags(ExecState*, JSObject*, JSValue, const ArgList&);
171
177
GlobalObject::GlobalObject(const Vector<UString>& arguments)
172
178
: JSGlobalObject()
174
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "debug"), functionDebug));
175
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "print"), functionPrint));
176
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "quit"), functionQuit));
177
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "gc"), functionGC));
178
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "version"), functionVersion));
179
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "run"), functionRun));
180
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "load"), functionLoad));
181
putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "readline"), functionReadline));
180
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "debug"), functionDebug));
181
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "print"), functionPrint));
182
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "quit"), functionQuit));
183
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "gc"), functionGC));
184
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "version"), functionVersion));
185
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "run"), functionRun));
186
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "load"), functionLoad));
187
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "readline"), functionReadline));
189
#if ENABLE(SAMPLING_FLAGS)
190
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "setSamplingFlags"), functionSetSamplingFlags));
191
putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "clearSamplingFlags"), functionClearSamplingFlags));
183
194
JSObject* array = constructEmptyArray(globalExec());
184
195
for (size_t i = 0; i < arguments.size(); ++i)
200
211
return jsUndefined();
203
JSValuePtr functionDebug(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
214
JSValue JSC_HOST_CALL functionDebug(ExecState* exec, JSObject*, JSValue, const ArgList& args)
205
fprintf(stderr, "--> %s\n", args.at(exec, 0).toString(exec).UTF8String().c_str());
216
fprintf(stderr, "--> %s\n", args.at(0).toString(exec).UTF8String().c_str());
206
217
return jsUndefined();
209
JSValuePtr functionGC(ExecState* exec, JSObject*, JSValuePtr, const ArgList&)
220
JSValue JSC_HOST_CALL functionGC(ExecState* exec, JSObject*, JSValue, const ArgList&)
211
222
JSLock lock(false);
212
223
exec->heap()->collect();
213
224
return jsUndefined();
216
JSValuePtr functionVersion(ExecState*, JSObject*, JSValuePtr, const ArgList&)
227
JSValue JSC_HOST_CALL functionVersion(ExecState*, JSObject*, JSValue, const ArgList&)
218
229
// We need this function for compatibility with the Mozilla JS tests but for now
219
230
// we don't actually do any version-specific handling
220
231
return jsUndefined();
223
JSValuePtr functionRun(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
234
JSValue JSC_HOST_CALL functionRun(ExecState* exec, JSObject*, JSValue, const ArgList& args)
225
236
StopWatch stopWatch;
226
UString fileName = args.at(exec, 0).toString(exec);
237
UString fileName = args.at(0).toString(exec);
227
238
Vector<char> script;
228
239
if (!fillBufferWithContentsOfFile(fileName, script))
229
240
return throwError(exec, GeneralError, "Could not open file.");
237
248
return jsNumber(globalObject->globalExec(), stopWatch.getElapsedMS());
240
JSValuePtr functionLoad(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
251
JSValue JSC_HOST_CALL functionLoad(ExecState* exec, JSObject* o, JSValue v, const ArgList& args)
242
UString fileName = args.at(exec, 0).toString(exec);
255
UString fileName = args.at(0).toString(exec);
243
256
Vector<char> script;
244
257
if (!fillBufferWithContentsOfFile(fileName, script))
245
258
return throwError(exec, GeneralError, "Could not open file.");
251
264
return result.value();
254
JSValuePtr functionReadline(ExecState* exec, JSObject*, JSValuePtr, const ArgList&)
267
#if ENABLE(SAMPLING_FLAGS)
268
JSValue JSC_HOST_CALL functionSetSamplingFlags(ExecState* exec, JSObject*, JSValue, const ArgList& args)
270
for (unsigned i = 0; i < args.size(); ++i) {
271
unsigned flag = static_cast<unsigned>(args.at(i).toNumber(exec));
272
if ((flag >= 1) && (flag <= 32))
273
SamplingFlags::setFlag(flag);
278
JSValue JSC_HOST_CALL functionClearSamplingFlags(ExecState* exec, JSObject*, JSValue, const ArgList& args)
280
for (unsigned i = 0; i < args.size(); ++i) {
281
unsigned flag = static_cast<unsigned>(args.at(i).toNumber(exec));
282
if ((flag >= 1) && (flag <= 32))
283
SamplingFlags::clearFlag(flag);
289
JSValue JSC_HOST_CALL functionReadline(ExecState* exec, JSObject*, JSValue, const ArgList&)
256
291
Vector<char, 256> line;