示例#1
0
static void constructor4(const v8::FunctionCallbackInfo<v8::Value>& info) {
  ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "TestInterfaceConstructor");
  ScriptState* scriptState = ScriptState::forReceiverObject(info);

  V8StringResource<> arg;
  V8StringResource<> arg2;
  V8StringResource<> arg3;
  arg = info[0];
  if (!arg.prepare())
    return;

  arg2 = info[1];
  if (!arg2.prepare())
    return;

  arg3 = info[2];
  if (!arg3.prepare())
    return;

  ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
  Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
  TestInterfaceConstructor* impl = TestInterfaceConstructor::create(scriptState, executionContext, document, arg, arg2, arg3, exceptionState);
  if (exceptionState.hadException()) {
    return;
  }
  v8::Local<v8::Object> wrapper = info.Holder();
  wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
  v8SetReturnValue(info, wrapper);
}
static void constructor3(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    V8StringResource<> arg;
    V8StringResource<> optArg;
    {
        TOSTRING_VOID_INTERNAL(arg, info[0]);
        if (UNLIKELY(info.Length() <= 1)) {
            ScriptState* scriptState = ScriptState::current(info.GetIsolate());
            ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
            Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
            RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(scriptState, executionContext, document, arg, exceptionState);
            if (exceptionState.hadException()) {
                exceptionState.throwIfNeeded();
                return;
            }
            v8::Local<v8::Object> wrapper = info.Holder();
            impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
            v8SetReturnValue(info, wrapper);
            return;
        }
        TOSTRING_VOID_INTERNAL(optArg, info[1]);
    }
    ScriptState* scriptState = ScriptState::current(info.GetIsolate());
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(scriptState, executionContext, document, arg, optArg, exceptionState);
    if (exceptionState.hadException()) {
        exceptionState.throwIfNeeded();
        return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}
示例#3
0
void V8Document::createTouchMethodPrologueCustom(
    const v8::FunctionCallbackInfo<v8::Value>& info,
    Document*) {
  v8::Local<v8::Value> v8Window = info[0];
  if (isUndefinedOrNull(v8Window)) {
    UseCounter::countIfNotPrivateScript(
        info.GetIsolate(), currentExecutionContext(info.GetIsolate()),
        UseCounter::DocumentCreateTouchWindowNull);
  } else if (!toDOMWindow(info.GetIsolate(), v8Window)) {
    UseCounter::countIfNotPrivateScript(
        info.GetIsolate(), currentExecutionContext(info.GetIsolate()),
        UseCounter::DocumentCreateTouchWindowWrongType);
  }

  v8::Local<v8::Value> v8Target = info[1];
  if (isUndefinedOrNull(v8Target)) {
    UseCounter::countIfNotPrivateScript(
        info.GetIsolate(), currentExecutionContext(info.GetIsolate()),
        UseCounter::DocumentCreateTouchTargetNull);
  } else if (!toEventTarget(info.GetIsolate(), v8Target)) {
    UseCounter::countIfNotPrivateScript(
        info.GetIsolate(), currentExecutionContext(info.GetIsolate()),
        UseCounter::DocumentCreateTouchTargetWrongType);
  }

  if (info.Length() < 7) {
    UseCounter::countIfNotPrivateScript(
        info.GetIsolate(), currentExecutionContext(info.GetIsolate()),
        UseCounter::DocumentCreateTouchLessThanSevenArguments);
  }
}
static void V8TestInterfaceConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("Audio"));
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    if (UNLIKELY(info.Length() < 1)) {
        setMinimumArityTypeError(exceptionState, 1, info.Length());
        exceptionState.throwIfNeeded();
        return;
    }
    V8StringResource<> arg;
    V8StringResource<> optArg;
    {
        TOSTRING_VOID_INTERNAL(arg, info[0]);
        if (UNLIKELY(info.Length() <= 1)) {
            ScriptState* scriptState = ScriptState::current(info.GetIsolate());
            ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
            Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
            RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(scriptState, executionContext, document, arg, exceptionState);
            if (exceptionState.hadException()) {
                exceptionState.throwIfNeeded();
                return;
            }
            v8::Local<v8::Object> wrapper = info.Holder();
            impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper);
            v8SetReturnValue(info, wrapper);
            return;
        }
        TOSTRING_VOID_INTERNAL(optArg, info[1]);
    }
    ScriptState* scriptState = ScriptState::current(info.GetIsolate());
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(scriptState, executionContext, document, arg, optArg, exceptionState);
    if (exceptionState.hadException()) {
        exceptionState.throwIfNeeded();
        return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}
static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    ScriptState* scriptState = ScriptState::current(info.GetIsolate());
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(scriptState, executionContext, document, exceptionState);
    if (exceptionState.hadException()) {
        exceptionState.throwIfNeeded();
        return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}
示例#6
0
unsigned CSSStyleSheet::insertRule(const String& rule,
                                   ExceptionState& exceptionState) {
  Deprecation::countDeprecation(
      currentExecutionContext(V8PerIsolateData::mainThreadIsolate()),
      UseCounter::CSSStyleSheetInsertRuleOptionalArg);
  return insertRule(rule, 0, exceptionState);
}
示例#7
0
ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions)
{
    ScriptState::Scope scope(m_scriptState.get());
    v8::TryCatch tryCatch;
    tryCatch.SetVerbose(reportExceptions);

    v8::Handle<v8::Object> thisObject = m_thisObject.v8Object();
    v8::Local<v8::Value> value = thisObject->Get(v8String(m_scriptState->isolate(), m_name));
    if (tryCatch.HasCaught()) {
        hadException = true;
        return ScriptValue();
    }

    ASSERT(value->IsFunction());

    v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
    OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]);
    for (size_t i = 0; i < m_arguments.size(); ++i) {
        info[i] = m_arguments[i].v8Value();
        ASSERT(!info[i].IsEmpty());
    }

    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, currentExecutionContext(m_scriptState->isolate()), thisObject, m_arguments.size(), info.get(), m_scriptState->isolate());
    if (tryCatch.HasCaught()) {
        hadException = true;
        return ScriptValue();
    }

    return ScriptValue(m_scriptState.get(), result);
}
示例#8
0
static void hrefCallWithAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
{
    v8::Handle<v8::Object> holder = info.Holder();
    TestNode* impl = V8TestNode::toImpl(holder);
    TOSTRING_VOID(V8StringResource<>, cppValue, v8Value);
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    impl->setHrefCallWith(executionContext, callingDOMWindow(info.GetIsolate()), enteredDOMWindow(info.GetIsolate()), cppValue);
}
static void useCounterCallback(v8::Isolate* isolate, v8::Isolate::UseCounterFeature feature)
{
    UseCounter::Feature blinkFeature;
    bool deprecated = false;
    switch (feature) {
    case v8::Isolate::kUseAsm:
        blinkFeature = UseCounter::UseAsm;
        break;
    case v8::Isolate::kBreakIterator:
        blinkFeature = UseCounter::BreakIterator;
        break;
    case v8::Isolate::kLegacyConst:
        blinkFeature = UseCounter::LegacyConst;
        break;
    case v8::Isolate::kObjectObserve:
        blinkFeature = UseCounter::ObjectObserve;
        deprecated = true;
        break;
    case v8::Isolate::kSloppyMode:
        blinkFeature = UseCounter::V8SloppyMode;
        break;
    case v8::Isolate::kStrictMode:
        blinkFeature = UseCounter::V8StrictMode;
        break;
    case v8::Isolate::kStrongMode:
        blinkFeature = UseCounter::V8StrongMode;
        break;
    case v8::Isolate::kRegExpPrototypeStickyGetter:
        blinkFeature = UseCounter::V8RegExpPrototypeStickyGetter;
        break;
    case v8::Isolate::kRegExpPrototypeToString:
        blinkFeature = UseCounter::V8RegExpPrototypeToString;
        break;
    default:
        // This can happen if V8 has added counters that this version of Blink
        // does not know about. It's harmless.
        return;
    }
    if (deprecated)
        UseCounter::countDeprecation(currentExecutionContext(isolate), blinkFeature);
    else
        UseCounter::count(currentExecutionContext(isolate), blinkFeature);
}
示例#10
0
static void hrefCallWithAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info)
{
    v8::Local<v8::Object> holder = info.Holder();
    TestNode* impl = V8TestNode::toImpl(holder);
    V8StringResource<> cppValue = v8Value;
    if (!cppValue.prepare())
        return;
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    impl->setHrefCallWith(executionContext, currentDOMWindow(info.GetIsolate()), enteredDOMWindow(info.GetIsolate()), cppValue);
}
static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    double doubleArg;
    V8StringResource<> stringArg;
    TestInterfaceEmpty* testInterfaceEmptyArg;
    Dictionary dictionaryArg;
    Vector<String> sequenceStringArg;
    Vector<Dictionary> sequenceDictionaryArg;
    Dictionary optionalDictionaryArg;
    TestInterfaceEmpty* optionalTestInterfaceEmptyArg;
    {
        TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(doubleArg, toDouble(info[0], exceptionState), exceptionState);
        TOSTRING_VOID_INTERNAL(stringArg, info[1]);
        testInterfaceEmptyArg = V8TestInterfaceEmpty::toImplWithTypeCheck(info.GetIsolate(), info[2]);
        if (!isUndefinedOrNull(info[3]) && !info[3]->IsObject()) {
            exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
            exceptionState.throwIfNeeded();
            return;
        }
        TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(dictionaryArg, Dictionary(info[3], info.GetIsolate(), exceptionState), exceptionState);
        TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(sequenceStringArg, toImplArray<String>(info[4], 5, info.GetIsolate(), exceptionState), exceptionState);
        TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(sequenceDictionaryArg, toImplArray<Dictionary>(info[5], 6, info.GetIsolate(), exceptionState), exceptionState);
        if (!isUndefinedOrNull(info[6]) && !info[6]->IsObject()) {
            exceptionState.throwTypeError("parameter 7 ('optionalDictionaryArg') is not an object.");
            exceptionState.throwIfNeeded();
            return;
        }
        TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(optionalDictionaryArg, Dictionary(info[6], info.GetIsolate(), exceptionState), exceptionState);
        optionalTestInterfaceEmptyArg = V8TestInterfaceEmpty::toImplWithTypeCheck(info.GetIsolate(), info[7]);
    }
    ScriptState* scriptState = ScriptState::current(info.GetIsolate());
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(scriptState, executionContext, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, sequenceDictionaryArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
    if (exceptionState.hadException()) {
        exceptionState.throwIfNeeded();
        return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}
示例#12
0
static void constructor3(const v8::FunctionCallbackInfo<v8::Value>& info) {
  ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "TestInterfaceConstructor");
  ScriptState* scriptState = ScriptState::forReceiverObject(info);

  V8StringResource<> arg;
  V8StringResource<> optArg;
  int numArgsPassed = info.Length();
  while (numArgsPassed > 0) {
    if (!info[numArgsPassed - 1]->IsUndefined())
      break;
    --numArgsPassed;
  }
  arg = info[0];
  if (!arg.prepare())
    return;

  if (UNLIKELY(numArgsPassed <= 1)) {
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    TestInterfaceConstructor* impl = TestInterfaceConstructor::create(scriptState, executionContext, document, arg, exceptionState);
    if (exceptionState.hadException()) {
      return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
    return;
  }
  optArg = info[1];
  if (!optArg.prepare())
    return;

  ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
  Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
  TestInterfaceConstructor* impl = TestInterfaceConstructor::create(scriptState, executionContext, document, arg, optArg, exceptionState);
  if (exceptionState.hadException()) {
    return;
  }
  v8::Local<v8::Object> wrapper = info.Holder();
  wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper);
  v8SetReturnValue(info, wrapper);
}
示例#13
0
// Set a |promise|'s state and result that correspond to the state.
// |promise| must be a Promise instance.
void setStateForPromise(v8::Handle<v8::Object> promise, V8PromiseCustom::PromiseState state, v8::Handle<v8::Value> value, v8::Isolate* isolate)
{
    ASSERT(!value.IsEmpty());
    ASSERT(state == V8PromiseCustom::Pending || state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejected || state == V8PromiseCustom::Following);
    v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise);
    internal->SetInternalField(V8PromiseCustom::InternalStateIndex, v8::Integer::New(isolate, state));
    internal->SetInternalField(V8PromiseCustom::InternalResultIndex, value);
    ExecutionContext* context = currentExecutionContext(isolate);
    if (InspectorInstrumentation::isPromiseTrackerEnabled(context))
        InspectorInstrumentation::didUpdatePromiseState(context, ScriptObject(ScriptState::forContext(isolate->GetCurrentContext()), promise), state, ScriptValue(value, isolate));
}
示例#14
0
static PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(v8::Isolate* isolate, v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize, bool emptyStackIsAllowed)
{
    ASSERT(isolate->InContext());
    v8::HandleScope scope(isolate);
    Vector<ScriptCallFrame> scriptCallFrames;
    toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptyStackIsAllowed, isolate);
    RefPtrWillBeRawPtr<ScriptCallStack> callStack = ScriptCallStack::create(scriptCallFrames);
    if (InspectorInstrumentation::hasFrontends() && maxStackSize > 1)
        InspectorInstrumentation::appendAsyncCallStack(currentExecutionContext(isolate), callStack.get());
    return callStack.release();
}
PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStackForConsole(size_t maxStackSize, bool emptyStackIsAllowed)
{
    size_t stackSize = 1;
    if (InspectorInstrumentation::hasFrontends()) {
        v8::Isolate* isolate = v8::Isolate::GetCurrent();
        if (!isolate->InContext())
            return nullptr;
        if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContext(isolate)))
            stackSize = maxStackSize;
    }
    return createScriptCallStack(stackSize, emptyStackIsAllowed);
}
示例#16
0
bool Dictionary::get(const String& key, OwnPtr<VoidCallback>& value) const
{
    v8::Local<v8::Value> v8Value;
    if (!getKey(key, v8Value))
        return false;

    if (!v8Value->IsFunction())
        return false;

    value = V8VoidCallback::create(v8::Handle<v8::Function>::Cast(v8Value), currentExecutionContext(m_isolate));
    return true;
}
V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, DOMWrapperWorld& world, v8::Isolate* isolate)
    : EventListener(JSEventListenerType)
    , m_isAttribute(isAttribute)
    , m_world(world)
    , m_isolate(isolate)
    , m_workerGlobalScope(nullptr)
{
    if (isMainThread())
        InstanceCounters::incrementCounter(InstanceCounters::JSEventListenerCounter);
    else
        m_workerGlobalScope = toWorkerGlobalScope(currentExecutionContext(isolate));
}
示例#18
0
PassRefPtr<ScriptCallStack> ScriptCallStack::captureForConsole()
{
    size_t stackSize = 1;
    if (InspectorInstrumentation::hasFrontends()) {
        v8::Isolate* isolate = v8::Isolate::GetCurrent();
        if (!isolate->InContext())
            return nullptr;
        if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContext(isolate)))
            stackSize = V8StackTrace::maxCallStackSizeToCapture;
    }
    return ScriptCallStack::capture(stackSize);
}
static void unscopeableVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    String errorMessage;
    if (!OriginTrials::featureNameEnabled(executionContext, errorMessage)) {
         v8SetReturnValue(info, v8::Undefined(info.GetIsolate()));
         if (!errorMessage.isEmpty()) {
             toDocument(executionContext)->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorMessage));
         }
         return;
    }
    TestInterfaceImplementationPartialV8Internal::unscopeableVoidMethodMethod(info);
}
static void unscopeableVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    String errorMessage;
    if (!ExperimentalFeatures::featureNameEnabled(executionContext, errorMessage)) {
         v8SetReturnValue(info, v8::Undefined(info.GetIsolate()));
         toDocument(executionContext)->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorMessage));
         return;
    }
    TestInterfaceImplementationPartialV8Internal::unscopeableVoidMethodMethod(info);
    TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
void V8MessageChannel::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExecutionContext* context = currentExecutionContext(info.GetIsolate());

    RefPtrWillBeRawPtr<MessageChannel> obj = MessageChannel::create(context);

    v8::Local<v8::Object> wrapper = info.Holder();

    // Create references from the MessageChannel wrapper to the two
    // MessagePort wrappers to make sure that the MessagePort wrappers
    // stay alive as long as the MessageChannel wrapper is around.
    V8HiddenValue::setHiddenValue(info.GetIsolate(), wrapper, V8HiddenValue::port1(info.GetIsolate()), toV8(obj->port1(), info.Holder(), info.GetIsolate()));
    V8HiddenValue::setHiddenValue(info.GetIsolate(), wrapper, V8HiddenValue::port2(info.GetIsolate()), toV8(obj->port2(), info.Holder(), info.GetIsolate()));

    V8DOMWrapper::associateObjectWithWrapper<V8MessageChannel>(obj.release(), &wrapperTypeInfo, wrapper, info.GetIsolate());
    info.GetReturnValue().Set(wrapper);
}
void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExecutionContext* context = currentExecutionContext(info.GetIsolate());

    RefPtr<SecurityOrigin> securityOrigin;
    if (context->isDocument()) {
        DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate());
        if (world.isIsolatedWorld())
            securityOrigin = world.isolatedWorldSecurityOrigin();
    }

    RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);

    v8::Handle<v8::Object> wrapper = info.Holder();
    V8DOMWrapper::associateObjectWithWrapper<V8XMLHttpRequest>(xmlHttpRequest.release(), &wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
    info.GetReturnValue().Set(wrapper);
}
static void V8TestInterfaceEventTargetConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Name"), info.GetIsolate());
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtrWillBeRawPtr<TestInterfaceEventTarget> impl = TestInterfaceEventTarget::createForJSConstructor(document);
    v8::Handle<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(&V8TestInterfaceEventTargetConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    v8SetReturnValue(info, wrapper);
}
void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    // Four cases:
    // open(method, url)
    // open(method, url, async)
    // open(method, url, async, user)
    // open(method, url, async, user, passwd)

    ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "XMLHttpRequest", info.Holder(), info.GetIsolate());

    if (info.Length() < 2) {
        exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length()));
        exceptionState.throwIfNeeded();
        return;
    }

    XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());

    TOSTRING_VOID(V8StringResource<>, method, info[0]);
    TOSTRING_VOID(V8StringResource<>, urlstring, info[1]);

    ExecutionContext* context = currentExecutionContext(info.GetIsolate());
    KURL url = context->completeURL(urlstring);

    if (info.Length() >= 3) {
        bool async = info[2]->BooleanValue();

        if (info.Length() >= 4 && !info[3]->IsUndefined()) {
            TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, user, info[3]);

            if (info.Length() >= 5 && !info[4]->IsUndefined()) {
                TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, password, info[4]);
                xmlHttpRequest->open(method, url, async, user, password, exceptionState);
            } else {
                xmlHttpRequest->open(method, url, async, user, exceptionState);
            }
        } else {
            xmlHttpRequest->open(method, url, async, exceptionState);
        }
    } else {
        xmlHttpRequest->open(method, url, exceptionState);
    }

    exceptionState.throwIfNeeded();
}
void V8InjectedScriptHost::evaluateWithExceptionDetailsCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    v8::Isolate* isolate = info.GetIsolate();
    if (info.Length() < 1) {
        isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, "One argument expected.")));
        return;
    }

    v8::Local<v8::String> expression = info[0]->ToString(isolate);
    if (expression.IsEmpty()) {
        isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, "The argument must be a string.")));
        return;
    }

    ASSERT(isolate->InContext());
    v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate);
    if (wrappedResult.IsEmpty())
        return;

    v8::TryCatch tryCatch(isolate);
    v8::Local<v8::Script> script;
    v8::Local<v8::Value> result;
    if (!v8Call(V8ScriptRunner::compileScript(expression, String(), String(), TextPosition(), isolate), script, tryCatch)) {
        setExceptionAsReturnValue(info, wrappedResult, tryCatch);
        return;
    }

    v8::Local<v8::Symbol> commandLineAPISymbolValue = commandLineAPISymbol(isolate);
    v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global();
    if (info.Length() >= 2 && info[1]->IsObject()) {
        v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate);
        global->Set(commandLineAPISymbolValue, commandLineAPI);
    }

    if (!v8Call(V8ScriptRunner::runCompiledScript(isolate, script, currentExecutionContext(isolate)), result, tryCatch)) {
        global->Delete(isolate->GetCurrentContext(), commandLineAPISymbolValue);
        setExceptionAsReturnValue(info, wrappedResult, tryCatch);
        return;
    }

    global->Delete(isolate->GetCurrentContext(), commandLineAPISymbolValue);
    wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result);
    wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8::Undefined(isolate));
    v8SetReturnValue(info, wrappedResult);
}
示例#26
0
static void supplementalMethod2Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ExecutionContext, "supplementalMethod2", "TestInterface", info.Holder(), info.GetIsolate());
    if (UNLIKELY(info.Length() < 2)) {
        exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length()));
        exceptionState.throwIfNeeded();
        return;
    }
    TestInterface* impl = V8TestInterface::toNative(info.Holder());
    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, strArg, info[0]);
    V8TRYCATCH_VOID(TestObject*, objArg, V8TestObject::toNativeWithTypeCheck(info.GetIsolate(), info[1]));
    ASSERT(impl);
    ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate());
    RefPtr<TestObject> result = TestPartialInterface::supplementalMethod2(scriptContext, *impl, strArg, objArg, exceptionState);
    if (exceptionState.throwIfNeeded())
        return;
    v8SetReturnValue(info, result.release());
}
// Custom constructor to make new TextTrackCue(...) return a VTTCue. This is legacy
// compat, not per spec, and should be removed at the earliest opportunity.
void V8TextTrackCue::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TextTrackCue", info.Holder(), info.GetIsolate());
    if (UNLIKELY(info.Length() < 3)) {
        exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, info.Length()));
        exceptionState.throwIfNeeded();
        return;
    }
    V8TRYCATCH_VOID(double, startTime, static_cast<double>(info[0]->NumberValue()));
    V8TRYCATCH_VOID(double, endTime, static_cast<double>(info[1]->NumberValue()));
    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, text, info[2]);

    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    UseCounter::countDeprecation(document, UseCounter::TextTrackCueConstructor);

    RefPtr<VTTCue> impl = VTTCue::create(document, startTime, endTime, text);
    v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate());

    v8SetReturnValue(info, wrapper);
}
示例#28
0
static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    v8::Isolate* isolate = info.GetIsolate();
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterface", info.Holder(), isolate);
    if (UNLIKELY(info.Length() < 1)) {
        exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
        exceptionState.throwIfNeeded();
        return;
    }
    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, str1, info[0]);
    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, str2, info[1]);
    ExecutionContext* context = currentExecutionContext(isolate);
    RefPtr<TestInterface> impl = TestInterface::create(context, str1, str2, exceptionState);
    if (exceptionState.throwIfNeeded())
        return;

    v8::Handle<v8::Object> wrapper = info.Holder();
    V8DOMWrapper::associateObjectWithWrapper<V8TestInterface>(impl.release(), &V8TestInterface::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
    v8SetReturnValue(info, wrapper);
}
示例#29
0
void V8Client::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "ServiceWorker", info.Holder(), info.GetIsolate());
    Client* client = V8Client::toNative(info.Holder());
    MessagePortArray ports;
    ArrayBufferArray arrayBuffers;
    if (info.Length() > 1) {
        const int transferablesArgIndex = 1;
        if (!SerializedScriptValue::extractTransferables(info[transferablesArgIndex], transferablesArgIndex, ports, arrayBuffers, exceptionState, info.GetIsolate())) {
            exceptionState.throwIfNeeded();
            return;
        }
    }
    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &ports, &arrayBuffers, exceptionState, info.GetIsolate());
    if (exceptionState.throwIfNeeded())
        return;
    ExecutionContext* context = currentExecutionContext(info.GetIsolate());
    client->postMessage(context, message.release(), &ports, exceptionState);
    exceptionState.throwIfNeeded();
}
static void V8TestInterfaceNamedConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("Audio"));
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceNamedConstructor", info.Holder(), info.GetIsolate());
    if (UNLIKELY(info.Length() < 1)) {
        setMinimumArityTypeError(exceptionState, 1, info.Length());
        exceptionState.throwIfNeeded();
        return;
    }
    V8StringResource<> stringArg;
    bool defaultUndefinedOptionalBooleanArg;
    int defaultUndefinedOptionalLongArg;
    V8StringResource<> defaultUndefinedOptionalStringArg;
    V8StringResource<> defaultNullStringOptionalstringArg;
    V8StringResource<> optionalStringArg;
    {
        int numArgsPassed = info.Length();
        while (numArgsPassed > 0) {
            if (!info[numArgsPassed - 1]->IsUndefined())
                break;
            --numArgsPassed;
        }
        stringArg = info[0];
        if (!stringArg.prepare())
            return;
        defaultUndefinedOptionalBooleanArg = toBoolean(info.GetIsolate(), info[1], exceptionState);
        if (exceptionState.throwIfNeeded())
            return;
        defaultUndefinedOptionalLongArg = toInt32(info.GetIsolate(), info[2], NormalConversion, exceptionState);
        if (exceptionState.throwIfNeeded())
            return;
        defaultUndefinedOptionalStringArg = info[3];
        if (!defaultUndefinedOptionalStringArg.prepare())
            return;
        if (!info[4]->IsUndefined()) {
            defaultNullStringOptionalstringArg = info[4];
            if (!defaultNullStringOptionalstringArg.prepare())
                return;
        } else {
            defaultNullStringOptionalstringArg = nullptr;
        }
        if (UNLIKELY(numArgsPassed <= 5)) {
            Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
            RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, exceptionState);
            if (exceptionState.hadException()) {
                exceptionState.throwIfNeeded();
                return;
            }
            v8::Local<v8::Object> wrapper = info.Holder();
            wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper);
            v8SetReturnValue(info, wrapper);
            return;
        }
        optionalStringArg = info[5];
        if (!optionalStringArg.prepare())
            return;
    }
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, optionalStringArg, exceptionState);
    if (exceptionState.hadException()) {
        exceptionState.throwIfNeeded();
        return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}