String JSNSResolver::lookupNamespaceURI(ExceptionContext* exceptionContext, 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)) { // In case the property is a getter that throws an error, // see LayoutTests/fast/dom/SelectorAPI/NSResolver-exceptions.xhtml ExceptionCatcher exceptionCatcher(exceptionContext); v8::Handle<v8::Value> lookupNamespaceURI = m_resolver->Get( lookupNamespaceURIName); if (exceptionContext->hadException()) return String(); if (lookupNamespaceURI->IsFunction()) { lookupNamespaceURIFunc = v8::Handle<v8::Function>::Cast( lookupNamespaceURI); } } if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) { Frame* frame = ScriptController::retrieveActiveFrame(); log_info(frame, "NSResolver does not have a lookupNamespaceURI method.", String()); return String(); } // Catch exceptions from calling the namespace resolver. ExceptionCatcher exceptionCatcher(exceptionContext); 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; V8Proxy* proxy = V8Proxy::retrieve(); v8::Handle<v8::Value> retval = proxy->CallFunction(function, m_resolver, argc, argv); // Eat exceptions from namespace resolver and return an empty string. This // will cause NAMESPACE_ERR. if (exceptionContext->hadException()) return String(); return valueToStringWithNullOrUndefinedCheck(retval); }
bool VoidCallbackFunctionInterfaceArg::call(ScriptWrappable* scriptWrappable, HTMLDivElement* divElement) { if (!m_scriptState->contextIsValid()) return false; ExecutionContext* context = m_scriptState->getExecutionContext(); DCHECK(context); if (context->activeDOMObjectsAreSuspended() || context->isContextDestroyed()) return false; if (m_callback.isEmpty()) return false; // TODO(bashi): Make sure that using DummyExceptionStateForTesting is OK. // crbug.com/653769 DummyExceptionStateForTesting exceptionState; ScriptState::Scope scope(m_scriptState.get()); v8::Local<v8::Value> divElementArgument = toV8(divElement, m_scriptState->context()->Global(), m_scriptState->isolate()); v8::Local<v8::Value> thisValue = toV8(scriptWrappable, m_scriptState->context()->Global(), m_scriptState->isolate()); v8::Local<v8::Value> argv[] = { divElementArgument }; v8::Local<v8::Value> v8ReturnValue; v8::TryCatch exceptionCatcher(m_scriptState->isolate()); exceptionCatcher.SetVerbose(true); if (V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), m_scriptState->getExecutionContext(), thisValue, 1, argv, m_scriptState->isolate()).ToLocal(&v8ReturnValue)) { return true; } return false; }
V0CustomElementLifecycleCallbacks* V0CustomElementConstructorBuilder::createCallbacks() { ASSERT(!m_prototype.IsEmpty()); v8::TryCatch exceptionCatcher(m_scriptState->isolate()); exceptionCatcher.SetVerbose(true); v8::MaybeLocal<v8::Function> created = retrieveCallback("createdCallback"); v8::MaybeLocal<v8::Function> attached = retrieveCallback("attachedCallback"); v8::MaybeLocal<v8::Function> detached = retrieveCallback("detachedCallback"); v8::MaybeLocal<v8::Function> attributeChanged = retrieveCallback("attributeChangedCallback"); m_callbacks = V8V0CustomElementLifecycleCallbacks::create(m_scriptState.get(), m_prototype, created, attached, detached, attributeChanged); return m_callbacks.get(); }
bool V8TestCallbackInterface::booleanMethod() { if (!canInvokeCallback()) return true; if (!m_scriptState->contextIsValid()) return true; ScriptState::Scope scope(m_scriptState.get()); v8::Local<v8::Value> *argv = 0; v8::TryCatch exceptionCatcher(m_scriptState->isolate()); exceptionCatcher.SetVerbose(true); V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), m_scriptState->getExecutionContext(), v8::Undefined(m_scriptState->isolate()), 0, argv, m_scriptState->isolate()); return !exceptionCatcher.HasCaught(); }
void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) { if (!m_resolver) return; ScriptState* scriptState = m_resolver->getScriptState(); ScriptState::Scope scope(scriptState); v8::Local<v8::String> jsonString = v8AtomicString(scriptState->isolate(), utf8Data, length); v8::TryCatch exceptionCatcher(scriptState->isolate()); v8::Local<v8::Value> jsonDictionary; if (v8Call(v8::JSON::Parse(scriptState->isolate(), jsonString), jsonDictionary, exceptionCatcher)) m_resolver->resolve(jsonDictionary); else m_resolver->reject(exceptionCatcher.Exception()); clearResolver(); }
bool V8SQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) { if (!canInvokeCallback()) return true; v8::Isolate* isolate = m_scriptState->isolate(); if (!m_scriptState->contextIsValid()) return true; ScriptState::Scope scope(m_scriptState.get()); v8::Local<v8::Value> transactionHandle = toV8(transaction, m_scriptState->context()->Global(), isolate); v8::Local<v8::Value> errorHandle = toV8(error, m_scriptState->context()->Global(), isolate); ASSERT(transactionHandle->IsObject()); v8::Local<v8::Value> argv[] = {transactionHandle, errorHandle}; v8::TryCatch exceptionCatcher(isolate); exceptionCatcher.SetVerbose(true); v8::Local<v8::Value> result; // FIXME: This comment doesn't make much sense given what the code is actually // doing. // // Step 6: If the error callback returns false, then move on to the next // statement, if any, or onto the next overall step otherwise. Otherwise, // the error callback did not return false, or there was no error callback. // Jump to the last step in the overall steps. if (!V8ScriptRunner::callFunction(m_callback.newLocal(isolate), m_scriptState->getExecutionContext(), m_scriptState->context()->Global(), WTF_ARRAY_LENGTH(argv), argv, isolate) .ToLocal(&result)) return true; bool value; if (!result->BooleanValue(isolate->GetCurrentContext()).To(&value)) return true; return value; }
bool StringSequenceCallbackFunctionLongSequenceArg::call(ScriptState* scriptState, ScriptWrappable* scriptWrappable, const Vector<int>& arg, Vector<String>& returnValue) { if (!scriptState->contextIsValid()) return false; ExecutionContext* context = scriptState->getExecutionContext(); DCHECK(context); if (context->activeDOMObjectsAreSuspended() || context->activeDOMObjectsAreStopped()) return false; if (m_callback.isEmpty()) return false; // TODO(bashi): Make sure that using TrackExceptionState is OK. // crbug.com/653769 TrackExceptionState exceptionState; ScriptState::Scope scope(scriptState); v8::Local<v8::Value> argArgument = toV8(arg, scriptState->context()->Global(), scriptState->isolate()); v8::Local<v8::Value> thisValue = toV8(scriptWrappable, scriptState->context()->Global(), scriptState->isolate()); v8::Local<v8::Value> argv[] = { argArgument }; v8::Local<v8::Value> v8ReturnValue; v8::TryCatch exceptionCatcher(scriptState->isolate()); exceptionCatcher.SetVerbose(true); if (V8ScriptRunner::callFunction(m_callback.newLocal(scriptState->isolate()), scriptState->getExecutionContext(), thisValue, 1, argv, scriptState->isolate()).ToLocal(&v8ReturnValue)) { Vector<String> cppValue = toImplArray<Vector<String>>(v8ReturnValue, 0, scriptState->isolate(), exceptionState); if (exceptionState.hadException()) return false; returnValue = cppValue; return true; } return false; }
void V8XMLHttpRequest::responseAttributeGetterCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); switch (xmlHttpRequest->responseTypeCode()) { case XMLHttpRequest::ResponseTypeDefault: case XMLHttpRequest::ResponseTypeText: responseTextAttributeGetterCustom(info); return; case XMLHttpRequest::ResponseTypeJSON: { v8::Isolate* isolate = info.GetIsolate(); ScriptString jsonSource = xmlHttpRequest->responseJSONSource(); if (jsonSource.isEmpty()) { v8SetReturnValue(info, v8::Null(isolate)); return; } // Catch syntax error. Swallows an exception (when thrown) as the // spec says. https://xhr.spec.whatwg.org/#response-body v8::TryCatch exceptionCatcher(isolate); v8::Local<v8::Value> json; if (v8Call(v8::JSON::Parse(isolate, jsonSource.v8Value()), json, exceptionCatcher)) v8SetReturnValue(info, json); else v8SetReturnValue(info, v8::Null(isolate)); return; } case XMLHttpRequest::ResponseTypeDocument: { ExceptionState exceptionState(ExceptionState::GetterContext, "response", "XMLHttpRequest", info.Holder(), info.GetIsolate()); Document* document = xmlHttpRequest->responseXML(exceptionState); if (exceptionState.throwIfNeeded()) return; v8SetReturnValueFast(info, document, xmlHttpRequest); return; } case XMLHttpRequest::ResponseTypeBlob: { Blob* blob = xmlHttpRequest->responseBlob(); v8SetReturnValueFast(info, blob, xmlHttpRequest); return; } case XMLHttpRequest::ResponseTypeLegacyStream: { Stream* stream = xmlHttpRequest->responseLegacyStream(); v8SetReturnValueFast(info, stream, xmlHttpRequest); return; } case XMLHttpRequest::ResponseTypeArrayBuffer: { DOMArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); return; } } }