PassRefPtr<JSONValue> toJSONValue(const ScriptValue& value)
{
    ScriptState* scriptState = value.scriptState();
    ASSERT(scriptState->contextIsValid());
    ScriptState::Scope scope(scriptState);
    NonThrowableExceptionState exceptionState;
    return ScriptValue::to<JSONValuePtr>(scriptState->isolate(), value, exceptionState);
}
void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument)
{
    if (argument.scriptState() != m_scriptState) {
        appendUndefinedArgument();
        return;
    }
    m_arguments.append(argument);
}
Example #3
0
ScriptPromise ScriptPromise::cast(const ScriptValue& value)
{
    if (value.isEmpty())
        return ScriptPromise();
    v8::Local<v8::Value> v8Value(value.v8Value());
    v8::Isolate* isolate = value.isolate();
    if (V8PromiseCustom::isPromise(v8Value, isolate) || v8Value->IsPromise()) {
        return ScriptPromise(value.scriptState(), v8Value);
    }
    if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) {
        v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isolate);
        if (resolver.IsEmpty()) {
            // The Promise constructor may return an empty value, for example
            // when the stack is exhausted.
            return ScriptPromise();
        }
        resolver->Resolve(v8Value);
        return ScriptPromise(value.scriptState(), resolver->GetPromise());
    }
    return ScriptPromise(value.scriptState(), V8PromiseCustom::toPromise(v8Value, isolate));
}
void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result)
{
    bool ok;
    unsigned id = heapSnapshotObjectId.toUInt(&ok);
    if (!ok) {
        *error = "Invalid heap snapshot object id";
        return;
    }
    ScriptValue heapObject = ScriptProfiler::objectByHeapObjectId(id);
    if (heapObject.isEmpty()) {
        *error = "Object is not available";
        return;
    }
    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(heapObject.scriptState());
    if (injectedScript.isEmpty()) {
        *error = "Object is not available. Inspected context is gone";
        return;
    }
    result = injectedScript.wrapObject(heapObject, objectGroup ? *objectGroup : "");
    if (!result)
        *error = "Failed to wrap object";
}
PassRefPtr<JSONValue> toJSONValue(const ScriptValue& value)
{
    ScriptState* scriptState = value.scriptState();
    return value.toJSONValue(scriptState);
}
ScriptFunctionCall::ScriptFunctionCall(const ScriptValue& thisObject, const String& name)
    : ScriptCallArgumentHandler(thisObject.scriptState())
    , m_thisObject(thisObject)
    , m_name(name)
{
}