static v8::Handle<v8::Value> webkitStartActivityCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    Navigator* imp = V8Navigator::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    V8TRYCATCH(Intent*, intent, V8Intent::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Intent::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
    RefPtr<IntentResultCallback> successCallback;
    if (args.Length() > 1 && !args[1]->IsNull() && !args[1]->IsUndefined()) {
        if (!args[1]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        successCallback = V8IntentResultCallback::create(args[1], getScriptExecutionContext());
    }
    RefPtr<IntentResultCallback> failureCallback;
    if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
        if (!args[2]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        failureCallback = V8IntentResultCallback::create(args[2], getScriptExecutionContext());
    }
    NavigatorIntents::webkitStartActivity(imp, intent, successCallback, failureCallback, ec);
    if (UNLIKELY(ec))
        goto fail;
    return v8Undefined();
    }
    fail:
    return setDOMException(ec, args.GetIsolate());
}
static v8::Handle<v8::Value> changeVersionCallback(const v8::Arguments& args)
{
    if (args.Length() < 2)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    Database* imp = V8Database::toNative(args.Holder());
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, oldVersion, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, newVersion, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined));
    RefPtr<SQLTransactionCallback> callback;
    if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
        if (!args[2]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        callback = V8SQLTransactionCallback::create(args[2], getScriptExecutionContext());
    }
    RefPtr<SQLTransactionErrorCallback> errorCallback;
    if (args.Length() > 3 && !args[3]->IsNull() && !args[3]->IsUndefined()) {
        if (!args[3]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        errorCallback = V8SQLTransactionErrorCallback::create(args[3], getScriptExecutionContext());
    }
    RefPtr<VoidCallback> successCallback;
    if (args.Length() > 4 && !args[4]->IsNull() && !args[4]->IsUndefined()) {
        if (!args[4]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        successCallback = V8VoidCallback::create(args[4], getScriptExecutionContext());
    }
    imp->changeVersion(oldVersion, newVersion, callback, errorCallback, successCallback);
    return v8Undefined();
}
static v8::Handle<v8::Value> readAsTextCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    FileReaderSync* imp = V8FileReaderSync::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    V8TRYCATCH(Blob*, blob, V8Blob::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Blob::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
    if (args.Length() <= 1) {
        ScriptExecutionContext* scriptContext = getScriptExecutionContext();
        String result = imp->readAsText(scriptContext, blob, ec);
        if (UNLIKELY(ec))
            goto fail;
        return v8String(result, args.GetIsolate());
    }
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, encoding, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined));
    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    String result = imp->readAsText(scriptContext, blob, encoding, ec);
    if (UNLIKELY(ec))
        goto fail;
    return v8String(result, args.GetIsolate());
    }
    fail:
    return setDOMException(ec, args.GetIsolate());
}
Exemplo n.º 4
0
v8::Handle<v8::Value> V8TestInterface::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TestInterface.Constructor");

    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();
    if (args.Length() < 1)
        return throwError("Not enough arguments", V8Proxy::TypeError);

    ExceptionCode ec = 0;
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str1, MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined));
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str2, MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined));

    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return throwError("TestInterface constructor's associated context is not available", V8Proxy::ReferenceError);

    RefPtr<TestInterface> obj = TestInterface::create(context, str1, str2, ec);
    if (ec)
        goto fail;

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, obj.get());
    obj->ref();
    V8DOMWrapper::setJSWrapperForActiveDOMObject(obj.get(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
  fail:
    return throwError(ec);
}
Exemplo n.º 5
0
v8::Handle<v8::Value> V8WebKitMutationObserver::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.WebKitMutationObserver.Constructor");

    if (!args.IsConstructCall())
        return V8Proxy::throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    if (args.Length() < 1)
        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());

    v8::Local<v8::Value> arg = args[0];
    if (!arg->IsObject())
        return throwError(TYPE_MISMATCH_ERR, args.GetIsolate());

    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return V8Proxy::throwError(V8Proxy::ReferenceError, "WebKitMutationObserver constructor's associated frame unavailable", args.GetIsolate());

    RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context);
    RefPtr<WebKitMutationObserver> observer = WebKitMutationObserver::create(callback.release());

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, observer.get());
    V8DOMWrapper::setJSWrapperForDOMObject(observer.release(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
}
ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions)
{
    ScriptScope scope(m_scriptState, reportExceptions);

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

    ASSERT(value->IsFunction());

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

    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, getScriptExecutionContext(), thisObject, m_arguments.size(), args.get());
    if (!scope.success()) {
        hadException = true;
        return ScriptValue();
    }

    return ScriptValue(result);
}
static v8::Handle<v8::Value> webkitGetUserMediaCallback(const v8::Arguments& args)
{
    if (args.Length() < 2)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    Navigator* imp = V8Navigator::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    V8TRYCATCH(Dictionary, options, Dictionary(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined), args.GetIsolate()));
    if (!options.isUndefinedOrNull() && !options.isObject())
        return throwTypeError("Not an object.", args.GetIsolate());
    if (args.Length() <= 1 || !args[1]->IsFunction())
        return throwTypeError(0, args.GetIsolate());
    RefPtr<NavigatorUserMediaSuccessCallback> successCallback = V8NavigatorUserMediaSuccessCallback::create(args[1], getScriptExecutionContext());
    RefPtr<NavigatorUserMediaErrorCallback> errorCallback;
    if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
        if (!args[2]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        errorCallback = V8NavigatorUserMediaErrorCallback::create(args[2], getScriptExecutionContext());
    }
    NavigatorMediaStream::webkitGetUserMedia(imp, options, successCallback, errorCallback, ec);
    if (UNLIKELY(ec))
        goto fail;
    return v8Undefined();
    }
    fail:
    return setDOMException(ec, args.GetIsolate());
}
Exemplo n.º 8
0
void reportException(ScriptState* scriptState, v8::TryCatch& exceptionCatcher)
{
    String errorMessage;
    int lineNumber = 0;
    String sourceURL;

    // There can be a situation that an exception is thrown without setting a message.
    v8::Local<v8::Message> message = exceptionCatcher.Message();
    if (message.IsEmpty()) {
        v8::Local<v8::String> exceptionString = exceptionCatcher.Exception()->ToString();
        // Conversion of the exception object to string can fail if an
        // exception is thrown during conversion.
        if (!exceptionString.IsEmpty())
            errorMessage = toWebCoreString(exceptionString);
    } else {
        errorMessage = toWebCoreString(message->Get());
        lineNumber = message->GetLineNumber();
        sourceURL = toWebCoreString(message->GetScriptResourceName());
    }

    // Do not report the exception if the current execution context is Document because we do not want to lead to duplicate error messages in the console.
    // FIXME (31171): need better design to solve the duplicate error message reporting problem.
    ScriptExecutionContext* context = getScriptExecutionContext(scriptState);
    // During the frame teardown, there may not be a valid context.
    if (context && !context->isDocument())
        context->reportException(errorMessage, lineNumber, sourceURL);
    exceptionCatcher.Reset();
}
Exemplo n.º 9
0
String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
{
    v8::Handle<v8::Function> lookupNamespaceURIFunc;
    v8::Handle<v8::String> lookupNamespaceURIName = v8::String::New("lookupNamespaceURI");

    // Check if the resolver has a function property named lookupNamespaceURI.
    if (m_resolver->Has(lookupNamespaceURIName)) {
        v8::Handle<v8::Value> lookupNamespaceURI = m_resolver->Get(lookupNamespaceURIName);
        if (lookupNamespaceURI->IsFunction())
            lookupNamespaceURIFunc = v8::Handle<v8::Function>::Cast(lookupNamespaceURI);
    }

    if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) {
        if (ScriptExecutionContext* context = getScriptExecutionContext())
            context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String(), 0);
        return String();
    }

    // Catch exceptions from calling the namespace resolver.
    v8::TryCatch try_catch;
    try_catch.SetVerbose(true);  // Print exceptions to console.

    const int argc = 1;
    v8::Handle<v8::Value> argv[argc] = { v8String(prefix) };
    v8::Handle<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Handle<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc;

    v8::Handle<v8::Value> retval = V8Proxy::instrumentedCallFunction(0 /* page */, function, m_resolver, argc, argv);

    // Eat exceptions from namespace resolver and return an empty string. This will most likely cause NAMESPACE_ERR.
    if (try_catch.HasCaught())
        return String();

    return toWebCoreStringWithNullCheck(retval);
}
static void messageHandlerInWorker(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data)
{
    static bool isReportingException = false;
    // Exceptions that occur in error handler should be ignored since in that case
    // WorkerGlobalScope::reportException will send the exception to the worker object.
    if (isReportingException)
        return;
    isReportingException = true;

    // During the frame teardown, there may not be a valid context.
    if (ScriptExecutionContext* context = getScriptExecutionContext()) {
        String errorMessage = toWebCoreString(message->Get());
        String sourceURL = toWebCoreString(message->GetScriptResourceName());
        RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, message->GetLineNumber(), message->GetStartColumn());
        v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Object>(), v8::Isolate::GetCurrent());
        if (!wrappedEvent.IsEmpty()) {
            ASSERT(wrappedEvent->IsObject());
            v8::Local<v8::Object>::Cast(wrappedEvent)->SetHiddenValue(V8HiddenPropertyName::error(), data);
        }
        AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;
        context->reportException(event.release(), 0, corsStatus);
    }

    isReportingException = false;
}
Exemplo n.º 11
0
static v8::Handle<v8::Value> openDatabaseSyncCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.WorkerContext.openDatabaseSync");
    if (args.Length() < 4)
        return throwError("Not enough arguments", V8Proxy::SyntaxError);
    WorkerContext* imp = V8WorkerContext::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, name, args[0]);
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, version, args[1]);
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, displayName, args[2]);
    EXCEPTION_BLOCK(unsigned, estimatedSize, toUInt32(args[3]));
    RefPtr<DatabaseCallback> creationCallback;
    if (args.Length() > 4 && !args[4]->IsNull() && !args[4]->IsUndefined()) {
        if (!args[4]->IsObject())
            return throwError(TYPE_MISMATCH_ERR);
        creationCallback = V8DatabaseCallback::create(args[4], getScriptExecutionContext());
    }
    RefPtr<DatabaseSync> result = imp->openDatabaseSync(name, version, displayName, estimatedSize, creationCallback, ec);
    if (UNLIKELY(ec))
        goto fail;
    return toV8(result.release());
    }
    fail:
    V8Proxy::setDOMException(ec);
    return v8::Handle<v8::Value>();
}
Exemplo n.º 12
0
v8::Handle<v8::Value> V8XMLHttpRequest::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.XMLHttpRequest.Constructor");

    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    // Expect no parameters.
    // Allocate a XMLHttpRequest object as its internal field.
    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return throwError(ReferenceError, "XMLHttpRequest constructor's associated context is not available", args.GetIsolate());

    RefPtr<SecurityOrigin> securityOrigin;
    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered())
        securityOrigin = isolatedContext->securityOrigin();
    RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
    v8::Handle<v8::Object> wrapper = args.Holder();
    V8DOMWrapper::setDOMWrapper(wrapper, &info, xmlHttpRequest.get());
    V8DOMWrapper::setJSWrapperForActiveDOMObject(xmlHttpRequest.release(), wrapper);
    return wrapper;
}
v8::Handle<v8::Value> V8MutationObserver::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.MutationObserver.Constructor");

    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());

    v8::Local<v8::Value> arg = args[0];
    if (!arg->IsObject())
        return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());

    ScriptExecutionContext* context = getScriptExecutionContext();

    RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context);
    RefPtr<MutationObserver> observer = MutationObserver::create(callback.release());

    v8::Handle<v8::Object> wrapper = args.Holder();
    V8DOMWrapper::setDOMWrapper(wrapper, &info, observer.get());
    V8DOMWrapper::setJSWrapperForDOMObject(observer.release(), wrapper);
    return wrapper;
}
Exemplo n.º 14
0
ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions)
{
    ScriptScope scope(m_scriptState, reportExceptions);

    v8::Local<v8::Object> thisObject = m_thisObject.v8Object();
    v8::Local<v8::Value> value = thisObject->Get(v8String(m_name));
    if (!scope.success()) {
        hadException = true;
        return ScriptValue();
    }

    ASSERT(value->IsFunction());

    v8::Local<v8::Function> function(v8::Function::Cast(*value));
    OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]);
    for (size_t i = 0; i < m_arguments.size(); ++i)
        args[i] = m_arguments[i].v8Value();

    v8::Local<v8::Value> result;
    {
        V8RecursionScope innerScope(getScriptExecutionContext());
        result = function->Call(thisObject, m_arguments.size(), args.get());
    }
    if (!scope.success()) {
        hadException = true;
        return ScriptValue();
    }

    return ScriptValue(result);
}
Exemplo n.º 15
0
v8::Handle<v8::Value> V8MessageChannel::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.MessageChannel.Constructor");
    // FIXME: The logic here is almost exact duplicate of V8::constructDOMObject.
    // Consider refactoring to reduce duplication.
    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.");

    // Get the ScriptExecutionContext (WorkerContext or Document)
    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return v8::Undefined();

    // Note: it's OK to let this RefPtr go out of scope because we also call
    // SetDOMWrapper(), which effectively holds a reference to obj.
    RefPtr<MessageChannel> obj = MessageChannel::create(context);

    v8::Local<v8::Object> messageChannel = args.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.
// CAPPFIX_WEB_WEBWORKERS_START
    V8DOMWrapper::setNamedHiddenReference(messageChannel, "port1", toV8(obj->port1()));
    V8DOMWrapper::setNamedHiddenReference(messageChannel, "port2", toV8(obj->port2()));
// CAPPFIX_WEB_WEBWORKERS_END

    // Setup the standard wrapper object internal fields.
    V8DOMWrapper::setDOMWrapper(messageChannel, &info, obj.get());
    return toV8(obj.release(), messageChannel);
}
static v8::Handle<v8::Value> fileCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    FileEntry* imp = V8FileEntry::toNative(args.Holder());
    if (args.Length() <= 0 || !args[0]->IsFunction())
        return throwTypeError(0, args.GetIsolate());
    RefPtr<FileCallback> successCallback = V8FileCallback::create(args[0], getScriptExecutionContext());
    RefPtr<ErrorCallback> errorCallback;
    if (args.Length() > 1 && !args[1]->IsNull() && !args[1]->IsUndefined()) {
        if (!args[1]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        errorCallback = V8ErrorCallback::create(args[1], getScriptExecutionContext());
    }
    imp->file(successCallback, errorCallback);
    return v8Undefined();
}
Exemplo n.º 17
0
void injectInternalsObject(v8::Local<v8::Context> context)
{
    v8::Context::Scope contextScope(context);
    v8::HandleScope scope;

    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    if (scriptContext->isDocument())
        context->Global()->Set(v8::String::New(Internals::internalsId), toV8(Internals::create(static_cast<Document*>(scriptContext))));
}
Exemplo n.º 18
0
PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(size_t maxStackSize)
{
    size_t stackSize = 1;
    if (InspectorInstrumentation::hasFrontends()) {
        ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext();
        if (InspectorInstrumentation::consoleAgentEnabled(scriptExecutionContext))
            stackSize = maxStackSize;
    }
    return createScriptCallStack(stackSize);
}
Exemplo n.º 19
0
bool Dictionary::get(const String& key, RefPtr<VoidCallback>& value) const
{
    v8::Local<v8::Value> v8Value;
    if (!getKey(key, v8Value))
        return false;

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

    value = V8VoidCallback::create(v8Value, getScriptExecutionContext());
    return true;
}
static v8::Handle<v8::Value> queryUsageAndQuotaCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    StorageInfo* imp = V8StorageInfo::toNative(args.Holder());
    V8TRYCATCH(int, storageType, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)));
    RefPtr<StorageInfoUsageCallback> usageCallback;
    if (args.Length() > 1 && !args[1]->IsNull() && !args[1]->IsUndefined()) {
        if (!args[1]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        usageCallback = V8StorageInfoUsageCallback::create(args[1], getScriptExecutionContext());
    }
    RefPtr<StorageInfoErrorCallback> errorCallback;
    if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
        if (!args[2]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        errorCallback = V8StorageInfoErrorCallback::create(args[2], getScriptExecutionContext());
    }
    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    imp->queryUsageAndQuota(scriptContext, storageType, usageCallback, errorCallback);
    return v8Undefined();
}
Exemplo n.º 21
0
v8::Handle<v8::Value> V8Notification::requestPermissionCallback(const v8::Arguments& args)
{
    INC_STATS(L"DOM.Notification.requestPermission");

    bool succeeded = false;
    RefPtr<V8NotificationPermissionCallback> callback = createFunctionOnlyCallback<V8NotificationPermissionCallback>(args[0], succeeded, args.GetIsolate());
    if (!succeeded)
        return v8::Undefined();
    ASSERT(callback);

    Notification::requestPermission(getScriptExecutionContext(), callback.release());
    return v8::Undefined();
}
static v8::Handle<v8::Value> transactionCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    Database* imp = V8Database::toNative(args.Holder());
    if (args.Length() <= 0 || !args[0]->IsFunction())
        return throwTypeError(0, args.GetIsolate());
    RefPtr<SQLTransactionCallback> callback = V8SQLTransactionCallback::create(args[0], getScriptExecutionContext());
    RefPtr<SQLTransactionErrorCallback> errorCallback;
    if (args.Length() > 1 && !args[1]->IsNull() && !args[1]->IsUndefined()) {
        if (!args[1]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        errorCallback = V8SQLTransactionErrorCallback::create(args[1], getScriptExecutionContext());
    }
    RefPtr<VoidCallback> successCallback;
    if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
        if (!args[2]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        successCallback = V8VoidCallback::create(args[2], getScriptExecutionContext());
    }
    imp->transaction(callback, errorCallback, successCallback);
    return v8Undefined();
}
static v8::Handle<v8::Value> requestQuotaCallback(const v8::Arguments& args)
{
    if (args.Length() < 2)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    StorageInfo* imp = V8StorageInfo::toNative(args.Holder());
    V8TRYCATCH(int, storageType, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)));
    V8TRYCATCH(unsigned long long, newQuotaInBytes, toInt64(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined)));
    RefPtr<StorageInfoQuotaCallback> quotaCallback;
    if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
        if (!args[2]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        quotaCallback = V8StorageInfoQuotaCallback::create(args[2], getScriptExecutionContext());
    }
    RefPtr<StorageInfoErrorCallback> errorCallback;
    if (args.Length() > 3 && !args[3]->IsNull() && !args[3]->IsUndefined()) {
        if (!args[3]->IsFunction())
            return throwTypeError(0, args.GetIsolate());
        errorCallback = V8StorageInfoErrorCallback::create(args[3], getScriptExecutionContext());
    }
    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    imp->requestQuota(scriptContext, storageType, newQuotaInBytes, quotaCallback, errorCallback);
    return v8Undefined();
}
Exemplo n.º 24
0
void resetInternalsObject(v8::Local<v8::Context> context)
{
    // This can happen if JavaScript is disabled in the main frame.
    if (context.IsEmpty())
        return;

    v8::Context::Scope contextScope(context);
    v8::HandleScope scope;

    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    ASSERT(scriptContext->isDocument());
    Page* page = static_cast<Document*>(scriptContext)->frame()->page();
    Internals::resetToConsistentState(page);
    InternalSettings::from(page)->resetToConsistentState();
}
Exemplo n.º 25
0
v8::Handle<v8::Value> V8XMLHttpRequest::constructorCustom(const v8::Arguments& args)
{
    ScriptExecutionContext* context = getScriptExecutionContext();

    RefPtr<SecurityOrigin> securityOrigin;
    if (context->isDocument()) {
        if (DOMWrapperWorld* world = isolatedWorldForEnteredContext())
            securityOrigin = world->isolatedWorldSecurityOrigin();
    }

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

    v8::Handle<v8::Object> wrapper = args.Holder();
    V8DOMWrapper::associateObjectWithWrapper(xmlHttpRequest.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
    return wrapper;
}
static v8::Handle<v8::Value> readAsArrayBufferCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    FileReaderSync* imp = V8FileReaderSync::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    V8TRYCATCH(Blob*, blob, V8Blob::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Blob::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    RefPtr<ArrayBuffer> result = imp->readAsArrayBuffer(scriptContext, blob, ec);
    if (UNLIKELY(ec))
        goto fail;
    return toV8(result.release(), args.Holder(), args.GetIsolate());
    }
    fail:
    return setDOMException(ec, args.GetIsolate());
}
Exemplo n.º 27
0
v8::Handle<v8::Value> V8MessageChannel::constructorCustom(const v8::Arguments& args)
{
    ScriptExecutionContext* context = getScriptExecutionContext();

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

    v8::Local<v8::Object> wrapper = args.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.
    V8HiddenPropertyName::setNamedHiddenReference(wrapper, "port1", toV8(obj->port1(), args.Holder(), args.GetIsolate()));
    V8HiddenPropertyName::setNamedHiddenReference(wrapper, "port2", toV8(obj->port2(), args.Holder(), args.GetIsolate()));

    V8DOMWrapper::associateObjectWithWrapper(obj.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
    return wrapper;
}
v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.XMLHttpRequest.open()");
    // Four cases:
    // open(method, url)
    // open(method, url, async)
    // open(method, url, async, user)
    // open(method, url, async, user, passwd)

    if (args.Length() < 2)
        return throwError("Not enough arguments", V8Proxy::SyntaxError);

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

    String method = toWebCoreString(args[0]);
    String urlstring = toWebCoreString(args[1]);
    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return v8::Undefined();

    KURL url = context->completeURL(urlstring);

    ExceptionCode ec = 0;

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

        if (args.Length() >= 4 && !args[3]->IsUndefined()) {
            String user = toWebCoreStringWithNullCheck(args[3]);
            
            if (args.Length() >= 5 && !args[4]->IsUndefined()) {
                String passwd = toWebCoreStringWithNullCheck(args[4]);
                xmlHttpRequest->open(method, url, async, user, passwd, ec);
            } else
                xmlHttpRequest->open(method, url, async, user, ec);
        } else
            xmlHttpRequest->open(method, url, async, ec);
    } else
        xmlHttpRequest->open(method, url, ec);

    if (ec)
        return throwError(ec);

    return v8::Undefined();
}
Exemplo n.º 29
0
v8::Handle<v8::Value> V8MutationObserver::constructorCallbackCustom(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());

    v8::Local<v8::Value> arg = args[0];
    if (!arg->IsObject())
        return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());

    ScriptExecutionContext* context = getScriptExecutionContext();
    v8::Handle<v8::Object> wrapper = args.Holder();

    RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context, wrapper, args.GetIsolate());
    RefPtr<MutationObserver> observer = MutationObserver::create(callback.release());

    V8DOMWrapper::associateObjectWithWrapper(observer.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
    return wrapper;
}
Exemplo n.º 30
0
static v8::Handle<v8::Value> supplementalMethod2Callback(const v8::Arguments& args)
{
    if (args.Length() < 2)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    TestInterface* imp = V8TestInterface::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, strArg, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
    V8TRYCATCH(TestObj*, objArg, V8TestObj::HasInstance(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined)) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined))) : 0);
    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    RefPtr<TestObj> result = TestSupplemental::supplementalMethod2(scriptContext, imp, strArg, objArg, ec);
    if (UNLIKELY(ec))
        goto fail;
    return toV8(result.release(), args.Holder(), args.GetIsolate());
    }
    fail:
    return setDOMException(ec, args.GetIsolate());
}