예제 #1
0
TiValueRef TiEvalScript(TiContextRef ctx, TiStringRef script, TiObjectRef thisObject, TiStringRef sourceURL, int startingLineNumber, TiValueRef* exception)
{
    TiExcState* exec = toJS(ctx);
    exec->globalData().heap.registerThread();
    TiLock lock(exec);

    TiObject* jsThisObject = toJS(thisObject);

    // evaluate sets "this" to the global object if it is NULL
    TiGlobalObject* globalObject = exec->dynamicGlobalObject();
    SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
    Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);

    if (completion.complType() == Throw) {
        if (exception)
            *exception = toRef(exec, completion.value());
        return 0;
    }

    if (completion.value())
        return toRef(exec, completion.value());
    
    // happens, for example, when the only statement is an empty (';') statement
    return toRef(exec, jsUndefined());
}
예제 #2
0
파일: jsc.cpp 프로젝트: rseagraves/tijscore
TiValue JSC_HOST_CALL functionRun(TiExcState* exec, TiObject*, TiValue, const ArgList& args)
{
    StopWatch stopWatch;
    UString fileName = args.at(0).toString(exec);
    Vector<char> script;
    if (!fillBufferWithContentsOfFile(fileName, script))
        return throwError(exec, GeneralError, "Could not open file.");

    TiGlobalObject* globalObject = exec->lexicalGlobalObject();

    stopWatch.start();
    evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName));
    stopWatch.stop();

    return jsNumber(globalObject->globalExec(), stopWatch.getElapsedMS());
}
예제 #3
0
TiGlobalContextRef TiGlobalContextCreate(TiClassRef globalObjectClass)
{
    initializeThreading();
#if OS(DARWIN)
    // When running on Tiger or Leopard, or if the application was linked before TiGlobalContextCreate was changed
    // to use a unique TiGlobalData, we use a shared one for compatibility.
#ifndef BUILDING_ON_LEOPARD
    if (NSVersionOfLinkTimeLibrary("TiCore") <= webkitFirstVersionWithConcurrentGlobalContexts) {
#else
    {
#endif
        TiLock lock(LockForReal);
        return TiGlobalContextCreateInGroup(toRef(&TiGlobalData::sharedInstance()), globalObjectClass);
    }
#endif // OS(DARWIN)

    return TiGlobalContextCreateInGroup(0, globalObjectClass);
}

TiGlobalContextRef TiGlobalContextCreateInGroup(TiContextGroupRef group, TiClassRef globalObjectClass)
{
    initializeThreading();

    TiLock lock(LockForReal);
    RefPtr<TiGlobalData> globalData = group ? PassRefPtr<TiGlobalData>(toJS(group)) : TiGlobalData::createContextGroup(ThreadStackTypeSmall);

    APIEntryShim entryShim(globalData.get(), false);

#if ENABLE(JSC_MULTIPLE_THREADS)
    globalData->makeUsableFromMultipleThreads();
#endif

    if (!globalObjectClass) {
        TiGlobalObject* globalObject = new (globalData.get()) TiGlobalObject(*globalData, TiGlobalObject::createStructure(*globalData, jsNull()));
        return TiGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
    }

    TiGlobalObject* globalObject = new (globalData.get()) TiCallbackObject<TiGlobalObject>(*globalData, globalObjectClass, TiCallbackObject<TiGlobalObject>::createStructure(*globalData, jsNull()));
    TiExcState* exec = globalObject->globalExec();
    TiValue prototype = globalObjectClass->prototype(exec);
    if (!prototype)
        prototype = jsNull();
    globalObject->resetPrototype(*globalData, prototype);
    return TiGlobalContextRetain(toGlobalRef(exec));
}
예제 #4
0
EncodedTiValue JSC_HOST_CALL functionLoad(TiExcState* exec)
{
    UString fileName = exec->argument(0).toString(exec);
    Vector<char> script;
    if (!fillBufferWithContentsOfFile(fileName, script))
        return TiValue::encode(throwError(exec, createError(exec, "Could not open file.")));

    TiGlobalObject* globalObject = exec->lexicalGlobalObject();
    Completion result = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName));
    if (result.complType() == Throw)
        throwError(exec, result.value());
    return TiValue::encode(result.value());
}
예제 #5
0
파일: jsc.cpp 프로젝트: rseagraves/tijscore
TiValue JSC_HOST_CALL functionCheckSyntax(TiExcState* exec, TiObject* o, TiValue v, const ArgList& args)
{
    UNUSED_PARAM(o);
    UNUSED_PARAM(v);
    UString fileName = args.at(0).toString(exec);
    Vector<char> script;
    if (!fillBufferWithContentsOfFile(fileName, script))
        return throwError(exec, GeneralError, "Could not open file.");

    TiGlobalObject* globalObject = exec->lexicalGlobalObject();
    Completion result = checkSyntax(globalObject->globalExec(), makeSource(script.data(), fileName));
    if (result.complType() == Throw)
        exec->setException(result.value());
    return result.value();
}
예제 #6
0
EncodedTiValue JSC_HOST_CALL functionCheckSyntax(TiExcState* exec)
{
    UString fileName = exec->argument(0).toString(exec);
    Vector<char> script;
    if (!fillBufferWithContentsOfFile(fileName, script))
        return TiValue::encode(throwError(exec, createError(exec, "Could not open file.")));

    TiGlobalObject* globalObject = exec->lexicalGlobalObject();

    StopWatch stopWatch;
    stopWatch.start();
    Completion result = checkSyntax(globalObject->globalExec(), makeSource(script.data(), fileName));
    stopWatch.stop();

    if (result.complType() == Throw)
        throwError(exec, result.value());
    return TiValue::encode(jsNumber(stopWatch.getElapsedMS()));
}