~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to JavaScriptCore/jsc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090515183058-50q5exjo9b1kxy9s
Tags: 1.1.7-1
* New upstream release
* debian/libwebkit-1.0-2.symbols:
- updated with the new symbols in 1.1.7
* debian/libwebkit-dev.install, debian/libwebkit-dev.links,
  debian/rules:
- Build, and ship gtk-doc documentation (Closes: #526683)
* debian/copyright:
- updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "Completion.h"
27
27
#include "InitializeThreading.h"
28
28
#include "JSArray.h"
 
29
#include "JSFunction.h"
29
30
#include "JSLock.h"
30
31
#include "PrototypeFunction.h"
31
32
#include "SamplingTool.h"
68
69
static void cleanupGlobalData(JSGlobalData*);
69
70
static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer);
70
71
 
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&);
 
80
 
 
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&);
 
84
#endif
79
85
 
80
86
struct Script {
81
87
    bool isFile;
171
177
GlobalObject::GlobalObject(const Vector<UString>& arguments)
172
178
    : JSGlobalObject()
173
179
{
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));
 
188
 
 
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));
 
192
#endif
182
193
 
183
194
    JSObject* array = constructEmptyArray(globalExec());
184
195
    for (size_t i = 0; i < arguments.size(); ++i)
186
197
    putDirect(Identifier(globalExec(), "arguments"), array);
187
198
}
188
199
 
189
 
JSValuePtr functionPrint(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
200
JSValue JSC_HOST_CALL functionPrint(ExecState* exec, JSObject*, JSValue, const ArgList& args)
190
201
{
191
202
    for (unsigned i = 0; i < args.size(); ++i) {
192
203
        if (i != 0)
193
204
            putchar(' ');
194
205
        
195
 
        printf("%s", args.at(exec, i).toString(exec).UTF8String().c_str());
 
206
        printf("%s", args.at(i).toString(exec).UTF8String().c_str());
196
207
    }
197
208
    
198
209
    putchar('\n');
200
211
    return jsUndefined();
201
212
}
202
213
 
203
 
JSValuePtr functionDebug(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
214
JSValue JSC_HOST_CALL functionDebug(ExecState* exec, JSObject*, JSValue, const ArgList& args)
204
215
{
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();
207
218
}
208
219
 
209
 
JSValuePtr functionGC(ExecState* exec, JSObject*, JSValuePtr, const ArgList&)
 
220
JSValue JSC_HOST_CALL functionGC(ExecState* exec, JSObject*, JSValue, const ArgList&)
210
221
{
211
222
    JSLock lock(false);
212
223
    exec->heap()->collect();
213
224
    return jsUndefined();
214
225
}
215
226
 
216
 
JSValuePtr functionVersion(ExecState*, JSObject*, JSValuePtr, const ArgList&)
 
227
JSValue JSC_HOST_CALL functionVersion(ExecState*, JSObject*, JSValue, const ArgList&)
217
228
{
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();
221
232
}
222
233
 
223
 
JSValuePtr functionRun(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
234
JSValue JSC_HOST_CALL functionRun(ExecState* exec, JSObject*, JSValue, const ArgList& args)
224
235
{
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());
238
249
}
239
250
 
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)
241
252
{
242
 
    UString fileName = args.at(exec, 0).toString(exec);
 
253
    UNUSED_PARAM(o);
 
254
    UNUSED_PARAM(v);
 
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();
252
265
}
253
266
 
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)
 
269
{
 
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);
 
274
    }
 
275
    return jsNull();
 
276
}
 
277
 
 
278
JSValue JSC_HOST_CALL functionClearSamplingFlags(ExecState* exec, JSObject*, JSValue, const ArgList& args)
 
279
{
 
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);
 
284
    }
 
285
    return jsNull();
 
286
}
 
287
#endif
 
288
 
 
289
JSValue JSC_HOST_CALL functionReadline(ExecState* exec, JSObject*, JSValue, const ArgList&)
255
290
{
256
291
    Vector<char, 256> line;
257
292
    int c;
265
300
    return jsString(exec, line.data());
266
301
}
267
302
 
268
 
JSValuePtr functionQuit(ExecState* exec, JSObject*, JSValuePtr, const ArgList&)
 
303
JSValue JSC_HOST_CALL functionQuit(ExecState* exec, JSObject*, JSValue, const ArgList&)
269
304
{
270
305
    cleanupGlobalData(&exec->globalData());
271
306
    exit(EXIT_SUCCESS);
339
374
#if ENABLE(OPCODE_SAMPLING)
340
375
    Interpreter* interpreter = globalObject->globalData()->interpreter;
341
376
    interpreter->setSampler(new SamplingTool(interpreter));
 
377
    interpreter->sampler()->setup();
 
378
#endif
 
379
#if ENABLE(SAMPLING_FLAGS)
 
380
    SamplingFlags::start();
342
381
#endif
343
382
 
344
383
    bool success = true;
353
392
            fileName = "[Command Line]";
354
393
        }
355
394
 
356
 
#if ENABLE(OPCODE_SAMPLING)
357
 
        interpreter->sampler()->start();
 
395
#if ENABLE(SAMPLING_THREAD)
 
396
        SamplingThread::start();
358
397
#endif
 
398
 
359
399
        Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script, fileName));
360
400
        success = success && completion.complType() != Throw;
361
401
        if (dump) {
365
405
                printf("End: %s\n", completion.value().toString(globalObject->globalExec()).ascii());
366
406
        }
367
407
 
 
408
#if ENABLE(SAMPLING_THREAD)
 
409
        SamplingThread::stop();
 
410
#endif
 
411
 
368
412
        globalObject->globalExec()->clearException();
369
 
 
370
 
#if ENABLE(OPCODE_SAMPLING)
371
 
        interpreter->sampler()->stop();
372
 
#endif
373
413
    }
374
414
 
 
415
#if ENABLE(SAMPLING_FLAGS)
 
416
    SamplingFlags::stop();
 
417
#endif
375
418
#if ENABLE(OPCODE_SAMPLING)
376
419
    interpreter->sampler()->dump(globalObject->globalExec());
377
420
    delete interpreter->sampler();
378
421
#endif
 
422
#if ENABLE(SAMPLING_COUNTERS)
 
423
    AbstractSamplingCounter::dump();
 
424
#endif
379
425
    return success;
380
426
}
381
427