示例#1
0
JSValueRef JSEvaluateScriptInternal(const JSLockHolder&, ExecState* exec, JSContextRef ctx, JSObjectRef thisObject, const SourceCode& source, JSValueRef* exception)
{
    UNUSED_PARAM(ctx);

    JSObject* jsThisObject = toJS(thisObject);

    // evaluate sets "this" to the global object if it is NULL
    VM& vm = exec->vm();
    JSGlobalObject* globalObject = vm.vmEntryGlobalObject(exec);
    NakedPtr<Exception> evaluationException;
    JSValue returnValue = profiledEvaluate(globalObject->globalExec(), ProfilingReason::API, source, jsThisObject, evaluationException);

    if (evaluationException) {
        if (exception)
            *exception = toRef(exec, evaluationException->value());
#if ENABLE(REMOTE_INSPECTOR)
        // FIXME: If we have a debugger attached we could learn about ParseError exceptions through
        // ScriptDebugServer::sourceParsed and this path could produce a duplicate warning. The
        // Debugger path is currently ignored by inspector.
        // NOTE: If we don't have a debugger, this SourceCode will be forever lost to the inspector.
        // We could stash it in the inspector in case an inspector is ever opened.
        globalObject->inspectorController().reportAPIException(exec, evaluationException);
#endif
        return nullptr;
    }

    if (returnValue)
        return toRef(exec, returnValue);

    // happens, for example, when the only statement is an empty (';') statement
    return toRef(exec, jsUndefined());
}
示例#2
0
JSValueRef JSScriptEvaluate(JSContextRef context, JSScriptRef script, JSValueRef thisValueRef, JSValueRef* exception)
{
    ExecState* exec = toJS(context);
    JSLockHolder locker(exec);
    if (script->vm() != &exec->vm()) {
        RELEASE_ASSERT_NOT_REACHED();
        return 0;
    }
    NakedPtr<Exception> internalException;
    JSValue thisValue = thisValueRef ? toJS(exec, thisValueRef) : jsUndefined();
    JSValue result = evaluate(exec, SourceCode(script), thisValue, internalException);
    if (internalException) {
        if (exception)
            *exception = toRef(exec, internalException->value());
        return 0;
    }
    ASSERT(result);
    return toRef(exec, result);
}
示例#3
0
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
    if (!ctx) {
        ASSERT_NOT_REACHED();
        return 0;
    }
    ExecState* exec = toJS(ctx);
    JSLockHolder locker(exec);

    JSObject* jsThisObject = toJS(thisObject);

    startingLineNumber = std::max(1, startingLineNumber);

    // evaluate sets "this" to the global object if it is NULL
    JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
    auto sourceURLString = sourceURL ? sourceURL->string() : String();
    SourceCode source = makeSource(script->string(), SourceOrigin { sourceURLString }, sourceURLString, TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber()));

    NakedPtr<Exception> evaluationException;
    JSValue returnValue = profiledEvaluate(globalObject->globalExec(), ProfilingReason::API, source, jsThisObject, evaluationException);

    if (evaluationException) {
        if (exception)
            *exception = toRef(exec, evaluationException->value());
#if ENABLE(REMOTE_INSPECTOR)
        // FIXME: If we have a debugger attached we could learn about ParseError exceptions through
        // ScriptDebugServer::sourceParsed and this path could produce a duplicate warning. The
        // Debugger path is currently ignored by inspector.
        // NOTE: If we don't have a debugger, this SourceCode will be forever lost to the inspector.
        // We could stash it in the inspector in case an inspector is ever opened.
        globalObject->inspectorController().reportAPIException(exec, evaluationException);
#endif
        return 0;
    }

    if (returnValue)
        return toRef(exec, returnValue);

    // happens, for example, when the only statement is an empty (';') statement
    return toRef(exec, jsUndefined());
}
示例#4
0
bool ScriptDebugServer::evaluateBreakpointAction(const ScriptBreakpointAction& breakpointAction)
{
    DebuggerCallFrame* debuggerCallFrame = currentDebuggerCallFrame();

    switch (breakpointAction.type) {
    case ScriptBreakpointActionTypeLog: {
        dispatchBreakpointActionLog(debuggerCallFrame->exec(), breakpointAction.data);
        break;
    }
    case ScriptBreakpointActionTypeEvaluate: {
        NakedPtr<Exception> exception;
        debuggerCallFrame->evaluate(breakpointAction.data, exception);
        if (exception)
            reportException(debuggerCallFrame->exec(), exception);
        break;
    }
    case ScriptBreakpointActionTypeSound:
        dispatchBreakpointActionSound(debuggerCallFrame->exec(), breakpointAction.identifier);
        break;
    case ScriptBreakpointActionTypeProbe: {
        NakedPtr<Exception> exception;
        JSValue result = debuggerCallFrame->evaluate(breakpointAction.data, exception);
        if (exception)
            reportException(debuggerCallFrame->exec(), exception);
        
        JSC::ExecState* state = debuggerCallFrame->scope()->globalObject()->globalExec();
        Deprecated::ScriptValue wrappedResult = Deprecated::ScriptValue(state->vm(), exception ? exception->value() : result);
        dispatchBreakpointActionProbe(state, breakpointAction, wrappedResult);
        break;
    }
    default:
        ASSERT_NOT_REACHED();
    }

    return true;
}
示例#5
0
TEST(WTF_NakedPtr, Basic)
{
    DerivedRefLogger a("a");

    NakedPtr<RefLogger> empty;
    ASSERT_EQ(nullptr, empty.get());

    {
        NakedPtr<RefLogger> ptr(&a);
        ASSERT_EQ(&a, ptr.get());
        ASSERT_EQ(&a, &*ptr);
        ASSERT_EQ(&a.name, &ptr->name);
    }

    {
        NakedPtr<RefLogger> ptr = &a;
        ASSERT_EQ(&a, ptr.get());
    }

    {
        NakedPtr<RefLogger> p1 = &a;
        NakedPtr<RefLogger> p2(p1);
        ASSERT_EQ(&a, p1.get());
        ASSERT_EQ(&a, p2.get());
    }

    {
        NakedPtr<RefLogger> p1 = &a;
        NakedPtr<RefLogger> p2 = p1;
        ASSERT_EQ(&a, p1.get());
        ASSERT_EQ(&a, p2.get());
    }

    {
        NakedPtr<RefLogger> p1 = &a;
        NakedPtr<RefLogger> p2 = WTFMove(p1);
        ASSERT_EQ(&a, p1.get());
        ASSERT_EQ(&a, p2.get());
    }

    {
        NakedPtr<RefLogger> p1 = &a;
        NakedPtr<RefLogger> p2(WTFMove(p1));
        ASSERT_EQ(&a, p1.get());
        ASSERT_EQ(&a, p2.get());
    }

    {
        NakedPtr<DerivedRefLogger> p1 = &a;
        NakedPtr<RefLogger> p2 = p1;
        ASSERT_EQ(&a, p1.get());
        ASSERT_EQ(&a, p2.get());
    }

    {
        NakedPtr<DerivedRefLogger> p1 = &a;
        NakedPtr<RefLogger> p2 = WTFMove(p1);
        ASSERT_EQ(&a, p1.get());
        ASSERT_EQ(&a, p2.get());
    }

    {
        NakedPtr<RefLogger> ptr(&a);
        ASSERT_EQ(&a, ptr.get());
        ptr.clear();
        ASSERT_EQ(nullptr, ptr.get());
    }
}