bool ReadableStreamOperations::isReadableStream(ScriptState* scriptState, ScriptValue value) { ASSERT(!value.isEmpty()); if (!value.isObject()) return false; v8::Local<v8::Value> args[] = {value.v8Value()}; return V8ScriptRunner::callExtraOrCrash(scriptState, "IsReadableStream", args) ->ToBoolean() ->Value(); }
ScriptCustomElementDefinitionBuilder::ScriptCustomElementDefinitionBuilder( ScriptState* scriptState, CustomElementRegistry* registry, const ScriptValue& constructor, ExceptionState& exceptionState) : m_prev(s_stack), m_scriptState(scriptState), m_registry(registry), m_constructorValue(constructor.v8Value()), m_exceptionState(exceptionState) { s_stack = this; }
v8::Handle<v8::Value> WebDocument::registerEmbedderCustomElement(const WebString& name, v8::Handle<v8::Value> options, WebExceptionCode& ec) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); Document* document = unwrap<Document>(); Dictionary dictionary(options, isolate); TrackExceptionState exceptionState; ScriptValue constructor = document->registerElement(ScriptState::current(isolate), name, dictionary, exceptionState, CustomElement::EmbedderNames); ec = exceptionState.code(); if (exceptionState.hadException()) return v8::Handle<v8::Value>(); return constructor.v8Value(); }
ScriptPromise::ScriptPromise(const ScriptValue& value) { if (value.hasNoValue()) return; v8::Local<v8::Value> v8Value(value.v8Value()); v8::Isolate* isolate = value.isolate(); if (V8PromiseCustom::isPromise(v8Value, isolate)) { m_promise = value; return; } m_promise = ScriptValue(V8PromiseCustom::toPromise(v8Value, isolate), isolate); }
void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info) { XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); ExceptionState exceptionState(ExceptionState::GetterContext, "responseText", "XMLHttpRequest", info.Holder(), info.GetIsolate()); ScriptValue text = xmlHttpRequest->responseText(exceptionState); if (exceptionState.throwIfNeeded()) return; if (text.hasNoValue()) { v8SetReturnValueString(info, emptyString(), info.GetIsolate()); return; } v8SetReturnValue(info, text.v8Value()); }
ScriptValue ReadableStreamOperations::createReadableStream( ScriptState* scriptState, UnderlyingSourceBase* underlyingSource, ScriptValue strategy) { ScriptState::Scope scope(scriptState); v8::Local<v8::Value> jsUnderlyingSource = toV8(underlyingSource, scriptState); v8::Local<v8::Value> jsStrategy = strategy.v8Value(); v8::Local<v8::Value> args[] = {jsUnderlyingSource, jsStrategy}; return ScriptValue( scriptState, V8ScriptRunner::callExtraOrCrash( scriptState, "createReadableStreamWithExternalController", args)); }
BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) : UnderlyingSourceBase(scriptState), m_scriptState(scriptState), m_madeFromReadableStream(true) { DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); v8::Local<v8::Value> bodyValue = toV8(this, scriptState); DCHECK(!bodyValue.IsEmpty()); DCHECK(bodyValue->IsObject()); v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); V8HiddenValue::setHiddenValue( scriptState, body, V8HiddenValue::internalBodyStream(scriptState->isolate()), stream.v8Value()); }
void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<SharedBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const IDBKeyPath& keyPath) { ScriptState::Scope scope(scriptState); v8::Isolate* isolate = scriptState->isolate(); ScriptValue keyValue = idbKeyToScriptValue(scriptState, key); ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buffer.get(), blobInfo)); // This assertion is about already persisted data, so allow experimental types. const bool allowExperimentalTypes = true; IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, scriptValue, keyPath, allowExperimentalTypes); ASSERT(!expectedKey || expectedKey->isEqual(key)); bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptValue.v8Value(), keyPath); ASSERT_UNUSED(injected, injected); }
v8::Local<v8::Value> WebDocument::registerEmbedderCustomElement(const WebString& name, v8::Local<v8::Value> options, WebExceptionCode& ec) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); Document* document = unwrap<Document>(); TrackExceptionState exceptionState; ElementRegistrationOptions registrationOptions; V8ElementRegistrationOptions::toImpl(isolate, options, registrationOptions, exceptionState); if (exceptionState.hadException()) return v8::Local<v8::Value>(); ScriptValue constructor = document->registerElement(ScriptState::current(isolate), name, registrationOptions, exceptionState, CustomElement::EmbedderNames); ec = exceptionState.code(); if (exceptionState.hadException()) return v8::Local<v8::Value>(); return constructor.v8Value(); }
static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& value, const String& keyPath, v8::Isolate* isolate) { Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath, keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); ASSERT(isolate->InContext()); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(value.v8Value()); v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size(), isolate)); if (v8Key.IsEmpty()) return 0; return createIDBKeyFromValue(v8Key, isolate); }
void V8TestCallbackInterface::callbackWithThisValueVoidMethodStringArg(ScriptValue thisValue, const String& stringArg) { if (!canInvokeCallback()) return; if (!m_scriptState->contextIsValid()) return; ScriptState::Scope scope(m_scriptState.get()); v8::Local<v8::Value> thisHandle = thisValue.v8Value(); v8::Local<v8::Value> stringArgHandle = v8String(m_scriptState->isolate(), stringArg); v8::Local<v8::Value> argv[] = { stringArgHandle }; V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), m_scriptState->getExecutionContext(), thisHandle, 1, argv, m_scriptState->isolate()); }
bool canInjectIDBKeyIntoScriptValue(DOMRequestState* state, const ScriptValue& scriptValue, const IDBKeyPath& keyPath) { IDB_TRACE("canInjectIDBKeyIntoScriptValue"); ASSERT(keyPath.type() == IDBKeyPath::StringType); Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath.string(), keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); if (!keyPathElements.size()) return false; v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1, state->context()->GetIsolate()); }
ScriptValue ReadableStreamOperations::getReader(ScriptState* scriptState, ScriptValue stream, ExceptionState& es) { ASSERT(isReadableStream(scriptState, stream)); v8::TryCatch block(scriptState->isolate()); v8::Local<v8::Value> args[] = {stream.v8Value()}; ScriptValue result( scriptState, V8ScriptRunner::callExtra(scriptState, "AcquireReadableStreamDefaultReader", args)); if (block.HasCaught()) es.rethrowV8Exception(block.Exception()); return result; }
void AcceptConnectionObserver::responseWasResolved(const ScriptValue& value) { ASSERT(executionContext()); if (!m_resolver) { // TODO(mek): Get rid of this block when observer is only used for // service port connect events. if (!value.v8Value()->IsTrue()) { responseWasRejected(); return; } ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleCrossOriginConnectEvent(m_eventID, true); m_state = Done; return; } ScriptState* scriptState = m_resolver->scriptState(); ExceptionState exceptionState(ExceptionState::UnknownContext, nullptr, nullptr, scriptState->context()->Global(), scriptState->isolate()); ServicePortConnectResponse response = ScriptValue::to<ServicePortConnectResponse>(scriptState->isolate(), value, exceptionState); if (exceptionState.hadException()) { exceptionState.reject(m_resolver.get()); m_resolver = nullptr; responseWasRejected(); return; } if (!response.hasAccept() || !response.accept()) { responseWasRejected(); return; } WebServicePort webPort; webPort.targetUrl = m_targetURL; if (response.hasName()) webPort.name = response.name(); if (response.hasData()) { webPort.data = SerializedScriptValueFactory::instance().create(scriptState->isolate(), response.data(), nullptr, exceptionState)->toWireString(); if (exceptionState.hadException()) { exceptionState.reject(m_resolver.get()); m_resolver = nullptr; responseWasRejected(); return; } } webPort.id = m_portID; ServicePort* port = ServicePort::create(m_collection, webPort); m_collection->addPort(port); m_resolver->resolve(port); m_callbacks->onSuccess(&webPort); m_state = Done; }
void assertPrimaryKeyValidOrInjectable(DOMRequestState* state, PassRefPtr<SharedBuffer> buffer, PassRefPtr<IDBKey> prpKey, const IDBKeyPath& keyPath) { RefPtr<IDBKey> key(prpKey); DOMRequestState::Scope scope(*state); v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate::GetCurrent(); ScriptValue keyValue = idbKeyToScriptValue(state, key); ScriptValue scriptValue(deserializeIDBValueBuffer(buffer.get(), isolate), isolate); RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPath(state, scriptValue, keyPath); ASSERT(!expectedKey || expectedKey->isEqual(key.get())); bool injected = injectV8KeyIntoV8Value(keyValue.v8Value(), scriptValue.v8Value(), keyPath, isolate); ASSERT_UNUSED(injected, injected); }
void V8ErrorEvent::errorAttributeGetterCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local<v8::Value> cachedError = V8HiddenValue::getHiddenValue(ScriptState::current(isolate), info.Holder(), V8HiddenValue::error(isolate)); if (!cachedError.IsEmpty()) { v8SetReturnValue(info, cachedError); return; } ErrorEvent* event = V8ErrorEvent::toImpl(info.Holder()); ScriptState* scriptState = ScriptState::current(isolate); ScriptValue error = event->error(scriptState); if (!error.isEmpty()) setHiddenValueAndReturnValue(scriptState, info, error.v8Value()); else setHiddenValueAndReturnValue(scriptState, info, v8::Null(isolate)); }
v8::Handle<v8::Value> V8MessageEvent::dataAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.MessageEvent.data"); MessageEvent* event = V8MessageEvent::toNative(info.Holder()); v8::Handle<v8::Value> result; switch (event->dataType()) { case MessageEvent::DataTypeScriptValue: { ScriptValue scriptValue = event->dataAsScriptValue(); if (scriptValue.hasNoValue()) result = v8::Null(); else result = scriptValue.v8Value(); break; } case MessageEvent::DataTypeSerializedScriptValue: if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue()) result = serializedValue->deserialize(event->ports()); else result = v8::Null(); break; case MessageEvent::DataTypeString: { String stringValue = event->dataAsString(); result = v8::String::New(fromWebCoreString(stringValue), stringValue.length()); break; } case MessageEvent::DataTypeBlob: result = toV8(event->dataAsBlob()); break; case MessageEvent::DataTypeArrayBuffer: result = toV8(event->dataAsArrayBuffer()); break; } // Overwrite the data attribute so it returns the cached result in future invocations. // This custom handler (dataAccessGetter) will not be called again. v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly); info.Holder()->ForceSet(name, result, dataAttr); return result; }
ScriptValue call(ScriptValue v) override { RefPtr<ReadingContext> readingContext(m_readingContext); if (!readingContext) return v; bool done; v8::Local<v8::Value> item = v.v8Value(); ASSERT(item->IsObject()); v8::Local<v8::Value> value = v8CallOrCrash(v8UnpackIteratorResult(v.getScriptState(), item.As<v8::Object>(), &done)); if (done) { readingContext->onReadDone(); return v; } if (!V8Uint8Array::hasInstance(value, v.isolate())) { readingContext->onRejected(); return ScriptValue(); } readingContext->onRead(V8Uint8Array::toImpl(value.As<v8::Object>())); return v; }
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)); }
BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, BytesConsumer* consumer) : UnderlyingSourceBase(scriptState), m_scriptState(scriptState), m_consumer(consumer), m_madeFromReadableStream(false) { v8::Local<v8::Value> bodyValue = toV8(this, scriptState); DCHECK(!bodyValue.IsEmpty()); DCHECK(bodyValue->IsObject()); v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); ScriptValue readableStream = ReadableStreamOperations::createReadableStream( scriptState, this, ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0)); DCHECK(!readableStream.isEmpty()); V8HiddenValue::setHiddenValue( scriptState, body, V8HiddenValue::internalBodyStream(scriptState->isolate()), readableStream.v8Value()); m_consumer->setClient(this); onStateChange(); }
void ReadableStreamOperations::tee(ScriptState* scriptState, ScriptValue stream, ScriptValue* newStream1, ScriptValue* newStream2) { DCHECK(isReadableStream(scriptState, stream)); DCHECK(!isLocked(scriptState, stream)); v8::Local<v8::Value> args[] = {stream.v8Value()}; ScriptValue result(scriptState, V8ScriptRunner::callExtraOrCrash( scriptState, "ReadableStreamTee", args)); DCHECK(result.v8Value()->IsArray()); v8::Local<v8::Array> branches = result.v8Value().As<v8::Array>(); DCHECK_EQ(2u, branches->Length()); *newStream1 = ScriptValue( scriptState, branches->Get(scriptState->context(), 0).ToLocalChecked()); *newStream2 = ScriptValue( scriptState, branches->Get(scriptState->context(), 1).ToLocalChecked()); DCHECK(isReadableStream(scriptState, *newStream1)); DCHECK(isReadableStream(scriptState, *newStream2)); }
Response* Response::create(ScriptState* scriptState, ScriptValue bodyValue, const Dictionary& init, ExceptionState& exceptionState) { v8::Local<v8::Value> body = bodyValue.v8Value(); ScriptValue reader; v8::Isolate* isolate = scriptState->isolate(); ExecutionContext* executionContext = scriptState->executionContext(); OwnPtr<FetchDataConsumerHandle> bodyHandle; String contentType; if (bodyValue.isUndefined() || bodyValue.isNull()) { // Note: The IDL processor cannot handle this situation. See // https://crbug.com/335871. } else if (V8Blob::hasInstance(body, isolate)) { Blob* blob = V8Blob::toImpl(body.As<v8::Object>()); bodyHandle = FetchBlobDataConsumerHandle::create(executionContext, blob->blobDataHandle()); contentType = blob->type(); } else if (V8ArrayBuffer::hasInstance(body, isolate)) { bodyHandle = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(body.As<v8::Object>())); } else if (V8ArrayBufferView::hasInstance(body, isolate)) { bodyHandle = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(body.As<v8::Object>())); } else if (V8FormData::hasInstance(body, isolate)) { RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object>())->encodeMultiPartFormData(); // Here we handle formData->boundary() as a C-style string. See // FormDataEncoder::generateUniqueBoundaryString. contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + formData->boundary().data(); bodyHandle = FetchFormDataConsumerHandle::create(executionContext, formData.release()); } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnabled() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { bodyHandle = ReadableStreamDataConsumerHandle::create(scriptState, bodyValue); reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState); if (exceptionState.hadException()) { reader = ScriptValue(); bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorDataConsumerHandle()); exceptionState.clearException(); } else { bodyHandle = ReadableStreamDataConsumerHandle::create(scriptState, reader); } } else { String string = toUSVString(isolate, body, exceptionState); if (exceptionState.hadException()) return nullptr; bodyHandle = FetchFormDataConsumerHandle::create(string); contentType = "text/plain;charset=UTF-8"; } // TODO(yhirano): Add the URLSearchParams case. Response* response = create(executionContext, bodyHandle.release(), contentType, ResponseInit(init, exceptionState), exceptionState); if (!exceptionState.hadException() && !reader.isEmpty()) { // Add a hidden reference so that the weak persistent in the // ReadableStreamDataConsumerHandle will be valid as long as the // Response is valid. v8::Local<v8::Value> wrapper = toV8(response, scriptState); if (wrapper.IsEmpty()) { exceptionState.throwTypeError("Cannot create a Response wrapper"); return nullptr; } ASSERT(wrapper->IsObject()); V8HiddenValue::setHiddenValue(scriptState, wrapper.As<v8::Object>(), V8HiddenValue::readableStreamReaderInResponse(scriptState->isolate()), reader.v8Value()); } return response; }
unsigned ScriptProfiler::getHeapObjectId(const ScriptValue& value) { v8::SnapshotObjectId id = v8::HeapProfiler::GetSnapshotObjectId(value.v8Value()); return id; }
void WorkerScriptController::setException(const ScriptValue& exception) { throwError(*exception.v8Value()); }
void V8HTMLCanvasElement::getContextMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Handle<v8::Object> holder = info.Holder(); v8::Isolate* isolate = info.GetIsolate(); HTMLCanvasElement* impl = V8HTMLCanvasElement::toNative(holder); TOSTRING_VOID(V8StringResource<>, contextIdResource, info[0]); String contextId = contextIdResource; RefPtr<CanvasContextAttributes> attributes; if (contextId == "webgl" || contextId == "experimental-webgl") { RefPtr<WebGLContextAttributes> webGLAttributes = WebGLContextAttributes::create(); if (info.Length() > 1 && info[1]->IsObject()) { v8::Handle<v8::Object> jsAttributes = info[1]->ToObject(); v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha"); if (jsAttributes->Has(alpha) && !isUndefinedOrNull(jsAttributes->Get(alpha))) webGLAttributes->setAlpha(jsAttributes->Get(alpha)->BooleanValue()); v8::Handle<v8::String> depth = v8AtomicString(isolate, "depth"); if (jsAttributes->Has(depth) && !isUndefinedOrNull(jsAttributes->Get(depth))) webGLAttributes->setDepth(jsAttributes->Get(depth)->BooleanValue()); v8::Handle<v8::String> stencil = v8AtomicString(isolate, "stencil"); if (jsAttributes->Has(stencil) && !isUndefinedOrNull(jsAttributes->Get(stencil))) webGLAttributes->setStencil(jsAttributes->Get(stencil)->BooleanValue()); v8::Handle<v8::String> antialias = v8AtomicString(isolate, "antialias"); if (jsAttributes->Has(antialias) && !isUndefinedOrNull(jsAttributes->Get(antialias))) webGLAttributes->setAntialias(jsAttributes->Get(antialias)->BooleanValue()); v8::Handle<v8::String> premultipliedAlpha = v8AtomicString(isolate, "premultipliedAlpha"); if (jsAttributes->Has(premultipliedAlpha) && !isUndefinedOrNull(jsAttributes->Get(premultipliedAlpha))) webGLAttributes->setPremultipliedAlpha(jsAttributes->Get(premultipliedAlpha)->BooleanValue()); v8::Handle<v8::String> preserveDrawingBuffer = v8AtomicString(isolate, "preserveDrawingBuffer"); if (jsAttributes->Has(preserveDrawingBuffer) && !isUndefinedOrNull(jsAttributes->Get(preserveDrawingBuffer))) webGLAttributes->setPreserveDrawingBuffer(jsAttributes->Get(preserveDrawingBuffer)->BooleanValue()); v8::Handle<v8::String> failIfMajorPerformanceCaveat = v8AtomicString(isolate, "failIfMajorPerformanceCaveat"); if (jsAttributes->Has(failIfMajorPerformanceCaveat) && !isUndefinedOrNull(jsAttributes->Get(failIfMajorPerformanceCaveat))) webGLAttributes->setFailIfMajorPerformanceCaveat(jsAttributes->Get(failIfMajorPerformanceCaveat)->BooleanValue()); } attributes = webGLAttributes; } else { RefPtr<Canvas2DContextAttributes> canvas2DAttributes = Canvas2DContextAttributes::create(); if (info.Length() > 1 && info[1]->IsObject()) { v8::Handle<v8::Object> jsAttributes = info[1]->ToObject(); v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha"); if (jsAttributes->Has(alpha) && !isUndefinedOrNull(jsAttributes->Get(alpha))) canvas2DAttributes->setAlpha(jsAttributes->Get(alpha)->BooleanValue()); } attributes = canvas2DAttributes; } CanvasRenderingContext* result = impl->getContext(contextId, attributes.get()); if (!result) { v8SetReturnValueNull(info); return; } if (result->is2d()) { v8::Handle<v8::Value> v8Result = toV8(toCanvasRenderingContext2D(result), info.Holder(), info.GetIsolate()); if (InspectorInstrumentation::canvasAgentEnabled(&impl->document())) { ScriptState* scriptState = ScriptState::current(isolate); ScriptValue context(scriptState, v8Result); ScriptValue wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(&impl->document(), context); if (!wrapped.isEmpty()) { v8SetReturnValue(info, wrapped.v8Value()); return; } } v8SetReturnValue(info, v8Result); return; } if (result->is3d()) { v8::Handle<v8::Value> v8Result = toV8(toWebGLRenderingContext(result), info.Holder(), info.GetIsolate()); if (InspectorInstrumentation::canvasAgentEnabled(&impl->document())) { ScriptState* scriptState = ScriptState::current(isolate); ScriptValue glContext(scriptState, v8Result); ScriptValue wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(&impl->document(), glContext); if (!wrapped.isEmpty()) { v8SetReturnValue(info, wrapped.v8Value()); return; } } v8SetReturnValue(info, v8Result); return; } ASSERT_NOT_REACHED(); v8SetReturnValueNull(info); }
ScriptPromise Permissions::query(ScriptState* scriptState, const ScriptValue& rawPermission) { WebPermissionClient* client = permissionClient(scriptState->executionContext()); if (!client) return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions.")); TrackExceptionState exceptionState; PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); if (exceptionState.hadException()) return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8String(scriptState->isolate(), exceptionState.message()))); RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); String name = permission.name(); WebPermissionType type; if (name == "geolocation") { type = WebPermissionTypeGeolocation; } else if (name == "notifications") { type = WebPermissionTypeNotifications; } else if (name == "push") { PushPermissionDescriptor pushPermission = NativeValueTraits<PushPermissionDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); // Only "userVisible" push is supported for now. if (!pushPermission.userVisible()) { resolver->resolve(PermissionStatus::create(scriptState->executionContext(), WebPermissionStatusDenied, WebPermissionTypePush)); return promise; } type = WebPermissionTypePushNotifications; } else if (name == "midi") { MidiPermissionDescriptor midiPermission = NativeValueTraits<MidiPermissionDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); // Only sysex usage requires a permission for now. if (!midiPermission.sysex()) { resolver->resolve(PermissionStatus::create(scriptState->executionContext(), WebPermissionStatusGranted, WebPermissionTypeMidi)); return promise; } type = WebPermissionTypeMidiSysEx; } else { ASSERT_NOT_REACHED(); type = WebPermissionTypeGeolocation; } // If the current origin is a file scheme, it will unlikely return a // meaningful value because most APIs are broken on file scheme and no // permission prompt will be shown even if the returned permission will most // likely be "prompt". client->queryPermission(type, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new PermissionQueryCallback(resolver, type)); return promise; }
PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Isolate* isolate, const ScriptValue& value, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState) { ASSERT(isolate->InContext()); return create(isolate, value.v8Value(), nullptr, nullptr, nullptr, blobInfo, exceptionState); }
ScriptPromise ScriptPromise::reject(ScriptState* scriptState, const ScriptValue& value) { return ScriptPromise::reject(scriptState, value.v8Value()); }
bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState& exceptionState) { ASSERT(m_prototype.IsEmpty()); v8::TryCatch tryCatch; ScriptValue prototypeScriptValue; if (m_options->get("prototype", prototypeScriptValue) && !prototypeScriptValue.isNull()) { ASSERT(!tryCatch.HasCaught()); if (!prototypeScriptValue.isObject()) { CustomElementException::throwException(CustomElementException::PrototypeNotAnObject, type, exceptionState); tryCatch.ReThrow(); return false; } m_prototype = prototypeScriptValue.v8Value().As<v8::Object>(); } else if (!tryCatch.HasCaught()) { m_prototype = v8::Object::New(m_scriptState->isolate()); v8::Local<v8::Object> basePrototype = m_scriptState->perContextData()->prototypeForType(&V8HTMLElement::wrapperTypeInfo); if (!basePrototype.IsEmpty()) m_prototype->SetPrototype(basePrototype); } if (tryCatch.HasCaught()) { tryCatch.ReThrow(); return false; } AtomicString extends; bool extendsProvidedAndNonNull = m_options->get("extends", extends); if (tryCatch.HasCaught()) { tryCatch.ReThrow(); return false; } if (!m_scriptState->perContextData()) { // FIXME: This should generate an InvalidContext exception at a later point. CustomElementException::throwException(CustomElementException::ContextDestroyedCheckingPrototype, type, exceptionState); tryCatch.ReThrow(); return false; } AtomicString namespaceURI = HTMLNames::xhtmlNamespaceURI; if (hasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo)) namespaceURI = SVGNames::svgNamespaceURI; ASSERT(!tryCatch.HasCaught()); AtomicString localName; if (extendsProvidedAndNonNull) { localName = extends.lower(); if (!Document::isValidName(localName)) { CustomElementException::throwException(CustomElementException::ExtendsIsInvalidName, type, exceptionState); tryCatch.ReThrow(); return false; } if (CustomElement::isValidName(localName)) { CustomElementException::throwException(CustomElementException::ExtendsIsCustomElementName, type, exceptionState); tryCatch.ReThrow(); return false; } } else { if (namespaceURI == SVGNames::svgNamespaceURI) { CustomElementException::throwException(CustomElementException::ExtendsIsInvalidName, type, exceptionState); tryCatch.ReThrow(); return false; } localName = type; } if (!extendsProvidedAndNonNull) m_wrapperType = &V8HTMLElement::wrapperTypeInfo; else if (namespaceURI == HTMLNames::xhtmlNamespaceURI) m_wrapperType = findWrapperTypeForHTMLTagName(localName); else m_wrapperType = findWrapperTypeForSVGTagName(localName); ASSERT(!tryCatch.HasCaught()); ASSERT(m_wrapperType); tagName = QualifiedName(nullAtom, localName, namespaceURI); return m_wrapperType; }
void ScriptPromiseResolver::reject(ScriptValue value) { ASSERT(m_isolate->InContext()); reject(value.v8Value()); }