EncodedJSValue JSC_HOST_CALL constructJSMutationObserver(ExecState& exec) { if (exec.argumentCount() < 1) return throwVMError(&exec, createNotEnoughArgumentsError(&exec)); JSObject* object = exec.uncheckedArgument(0).getObject(); CallData callData; if (!object || object->methodTable()->getCallData(object, callData) == CallType::None) return throwVMTypeError(&exec, ASCIILiteral("Callback argument must be a function")); DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec.callee()); auto callback = JSMutationCallback::create(object, jsConstructor->globalObject()); JSObject* jsObserver = asObject(toJSNewlyCreated(&exec, jsConstructor->globalObject(), MutationObserver::create(WTFMove(callback)))); PrivateName propertyName; jsObserver->putDirect(jsConstructor->globalObject()->vm(), propertyName, object); return JSValue::encode(jsObserver); }
EncodedJSValue JSC_HOST_CALL JSMutationObserverConstructor::constructJSMutationObserver(ExecState* exec) { if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); JSObject* object = exec->argument(0).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return JSValue::encode(jsUndefined()); } JSMutationObserverConstructor* jsConstructor = jsCast<JSMutationObserverConstructor*>(exec->callee()); RefPtr<JSMutationCallback> callback = JSMutationCallback::create(object, jsConstructor->globalObject()); JSObject* jsObserver = asObject(toJS(exec, jsConstructor->globalObject(), MutationObserver::create(callback.release()))); PrivateName propertyName; jsObserver->putDirect(jsConstructor->globalObject()->globalData(), propertyName, object); return JSValue::encode(jsObserver); }
JSValue JSWebGL2RenderingContext::getIndexedParameter(ExecState& exec) { VM& vm = exec.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (exec.argumentCount() != 2) return throwException(&exec, scope, createNotEnoughArgumentsError(&exec)); WebGL2RenderingContext& context = wrapped(); unsigned pname = exec.uncheckedArgument(0).toInt32(&exec); if (exec.hadException()) return jsUndefined(); unsigned index = exec.uncheckedArgument(1).toInt32(&exec); if (exec.hadException()) return jsUndefined(); WebGLGetInfo info = context.getIndexedParameter(pname, index); return toJS(&exec, globalObject(), info); }
JSValue JSWebKitSubtleCrypto::sign(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (state.argumentCount() < 3) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0)); RETURN_IF_EXCEPTION(scope, { }); auto parameters = JSCryptoAlgorithmDictionary::createParametersForSign(state, scope, algorithm->identifier(), state.uncheckedArgument(0)); RETURN_IF_EXCEPTION(scope, { }); RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(vm, state.uncheckedArgument(1)); if (!key) return throwTypeError(&state, scope); if (!key->allows(CryptoKeyUsageSign)) { wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'sign'")); throwNotSupportedError(state, scope); return jsUndefined(); } auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(2)); RETURN_IF_EXCEPTION(scope, { }); RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow()); auto promise = wrapper->promise(); auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable { fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size()); }; auto failureCallback = [wrapper]() mutable { wrapper->reject(); // FIXME: This should reject with an Exception. }; auto result = algorithm->sign(*parameters, *key, data, WTFMove(successCallback), WTFMove(failureCallback)); if (result.hasException()) { propagateException(state, scope, result.releaseException()); return { }; } return promise; }
EncodedJSValue JSC_HOST_CALL jsSVGStringListPrototypeFunctionRemoveItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSSVGStringList* castedThis = jsDynamicCast<JSSVGStringList*>(thisValue); if (!castedThis) return throwVMTypeError(exec); ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGStringList::info()); SVGStaticListPropertyTearOff<SVGStringList> & impl = castedThis->impl(); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; unsigned index(toUInt32(exec, exec->argument(0), NormalConversion)); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = jsStringWithCache(exec, impl.removeItem(index, ec)); setDOMException(exec, ec); return JSValue::encode(result); }
EncodedJSValue JSC_HOST_CALL jsSVGStringListPrototypeFunctionAppendItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSSVGStringList* castedThis = jsDynamicCast<JSSVGStringList*>(thisValue); if (!castedThis) return throwVMTypeError(exec); ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGStringList::info()); SVGStaticListPropertyTearOff<SVGStringList> & impl = castedThis->impl(); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; const String& item(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = jsStringWithCache(exec, impl.appendItem(item, ec)); setDOMException(exec, ec); return JSValue::encode(result); }
EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionDispatchEvent(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSTestEventTarget::s_info)) return throwVMTypeError(exec); JSTestEventTarget* castedThis = jsCast<JSTestEventTarget*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info); TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl()); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; Event* evt(toEvent(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = jsBoolean(impl->dispatchEvent(evt, ec)); setDOMException(exec, ec); return JSValue::encode(result); }
JSValue JSWebGLRenderingContext::getProgramParameter(ExecState* exec) { if (exec->argumentCount() != 2) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; WebGLRenderingContext& context = impl(); WebGLProgram* program = toWebGLProgram(exec->uncheckedArgument(0)); if (!program && !exec->uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(exec); unsigned pname = exec->uncheckedArgument(1).toInt32(exec); if (exec->hadException()) return jsUndefined(); WebGLGetInfo info = context.getProgramParameter(program, pname, ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return toJS(exec, globalObject(), info); }
JSValue JSWebGLRenderingContext::getShaderParameter(ExecState* exec) { if (exec->argumentCount() != 2) return throwError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLShader::s_info)) return throwTypeError(exec); WebGLShader* shader = toWebGLShader(exec->argument(0)); unsigned pname = exec->argument(1).toInt32(exec); if (exec->hadException()) return jsUndefined(); WebGLGetInfo info = context->getShaderParameter(shader, pname, ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return toJS(exec, globalObject(), info); }
JSValue JSWebGLRenderingContextBase::getShaderParameter(ExecState* exec) { if (exec->argumentCount() != 2) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; WebGLRenderingContextBase& context = impl(); if (!exec->uncheckedArgument(0).isUndefinedOrNull() && !exec->uncheckedArgument(0).inherits(JSWebGLShader::info())) return throwTypeError(exec); WebGLShader* shader = JSWebGLShader::toWrapped(exec->uncheckedArgument(0)); unsigned pname = exec->uncheckedArgument(1).toInt32(exec); if (exec->hadException()) return jsUndefined(); WebGLGetInfo info = context.getShaderParameter(shader, pname, ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return toJS(exec, globalObject(), info); }
EncodedJSValue JSC_HOST_CALL constructJSMutationObserver(ExecState& exec) { VM& vm = exec.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (exec.argumentCount() < 1) return throwVMError(&exec, scope, createNotEnoughArgumentsError(&exec)); JSObject* object = exec.uncheckedArgument(0).getObject(); CallData callData; if (!object || object->methodTable()->getCallData(object, callData) == CallType::None) return throwArgumentTypeError(exec, scope, 0, "callback", "MutationObserver", nullptr, "MutationCallback"); DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec.jsCallee()); auto callback = JSMutationCallback::create(object, jsConstructor->globalObject()); JSObject* jsObserver = asObject(toJSNewlyCreated(&exec, jsConstructor->globalObject(), MutationObserver::create(WTFMove(callback)))); PrivateName propertyName; jsObserver->putDirect(vm, propertyName, object); return JSValue::encode(jsObserver); }
JSValue JSWebGLRenderingContextBase::getProgramParameter(ExecState& state) { if (state.argumentCount() != 2) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); ExceptionCode ec = 0; WebGLRenderingContextBase& context = wrapped(); WebGLProgram* program = JSWebGLProgram::toWrapped(state.uncheckedArgument(0)); if (!program && !state.uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(&state); unsigned pname = state.uncheckedArgument(1).toInt32(&state); if (state.hadException()) return jsUndefined(); WebGLGetInfo info = context.getProgramParameter(program, pname, ec); if (ec) { setDOMException(&state, ec); return jsUndefined(); } return toJS(&state, globalObject(), info); }
JSValue JSWebGLRenderingContextBase::getUniform(ExecState* exec) { if (exec->argumentCount() != 2) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; WebGLRenderingContextBase& context = impl(); WebGLProgram* program = JSWebGLProgram::toWrapped(exec->uncheckedArgument(0)); if (!program && !exec->uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(exec); WebGLUniformLocation* location = JSWebGLUniformLocation::toWrapped(exec->uncheckedArgument(1)); if (!location && !exec->uncheckedArgument(1).isUndefinedOrNull()) return throwTypeError(exec); WebGLGetInfo info = context.getUniform(program, location, ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return toJS(exec, globalObject(), info); }
JSValue JSCrypto::getRandomValues(ExecState* exec) { if (exec->argumentCount() < 1) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); JSValue buffer = exec->argument(0); RefPtr<ArrayBufferView> arrayBufferView = toArrayBufferView(buffer); if (!arrayBufferView) return throwTypeError(exec); ExceptionCode ec = 0; impl()->getRandomValues(arrayBufferView.get(), ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return buffer; }
JSValue JSWebKitSubtleCrypto::digest(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (state.argumentCount() < 2) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0)); ASSERT(scope.exception() || algorithm); if (!algorithm) return jsUndefined(); auto parameters = JSCryptoAlgorithmDictionary::createParametersForDigest(&state, algorithm->identifier(), state.uncheckedArgument(0)); ASSERT(scope.exception() || parameters); if (!parameters) return jsUndefined(); CryptoOperationData data; auto success = cryptoOperationDataFromJSValue(&state, state.uncheckedArgument(1), data); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow()); auto promise = wrapper->promise(); auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable { fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size()); }; auto failureCallback = [wrapper]() mutable { wrapper->reject(nullptr); }; auto result = algorithm->digest(*parameters, data, WTFMove(successCallback), WTFMove(failureCallback)); if (result.hasException()) { propagateException(state, scope, result.releaseException()); return { }; } return promise; }
JSValue JSSubtleCrypto::digest(ExecState* exec) { if (exec->argumentCount() < 2) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); auto algorithm = createAlgorithmFromJSValue(exec, exec->uncheckedArgument(0)); if (!algorithm) { ASSERT(exec->hadException()); return jsUndefined(); } auto parameters = JSCryptoAlgorithmDictionary::createParametersForDigest(exec, algorithm->identifier(), exec->uncheckedArgument(0)); if (!parameters) { ASSERT(exec->hadException()); return jsUndefined(); } CryptoOperationData data; if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(1), data)) { ASSERT(exec->hadException()); return jsUndefined(); } JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(exec, globalObject()); DeferredWrapper wrapper(exec, globalObject(), promiseDeferred); auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable { wrapper.resolve(result); }; auto failureCallback = [wrapper]() mutable { wrapper.reject(nullptr); }; ExceptionCode ec = 0; algorithm->digest(*parameters, data, WTF::move(successCallback), WTF::move(failureCallback), ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return promiseDeferred->promise(); }
EncodedJSValue JSC_HOST_CALL jsIDBKeyRangeConstructorFunctionBound(ExecState* exec) { if (exec->argumentCount() < 2) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); if (!scriptContext) return JSValue::encode(jsUndefined()); Deprecated::ScriptValue lower(exec->vm(), exec->argument(0)); if (exec->hadException()) return JSValue::encode(jsUndefined()); Deprecated::ScriptValue upper(exec->vm(), exec->argument(1)); if (exec->hadException()) return JSValue::encode(jsUndefined()); size_t argsCount = exec->argumentCount(); if (argsCount <= 2) { JSC::JSValue result = toJS(exec, jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), WTF::getPtr(IDBKeyRange::bound(scriptContext, lower, upper, ec))); setDOMException(exec, ec); return JSValue::encode(result); } bool lowerOpen(exec->argument(2).toBoolean(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); if (argsCount <= 3) { JSC::JSValue result = toJS(exec, jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), WTF::getPtr(IDBKeyRange::bound(scriptContext, lower, upper, lowerOpen, ec))); setDOMException(exec, ec); return JSValue::encode(result); } bool upperOpen(exec->argument(3).toBoolean(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), WTF::getPtr(IDBKeyRange::bound(scriptContext, lower, upper, lowerOpen, upperOpen, ec))); setDOMException(exec, ec); return JSValue::encode(result); }
JSValue JSHTMLCanvasElement::probablySupportsContext(ExecState& state) { if (UNLIKELY(state.argumentCount() < 1)) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); HTMLCanvasElement& canvas = wrapped(); const String& contextId = state.uncheckedArgument(0).toWTFString(&state); if (state.hadException()) return jsUndefined(); RefPtr<CanvasContextAttributes> attrs; #if ENABLE(WEBGL) if (HTMLCanvasElement::is3dType(contextId)) { get3DContextAttributes(state, attrs); if (state.hadException()) return jsUndefined(); } #endif return jsBoolean(canvas.probablySupportsContext(contextId, attrs.get())); }
EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSTestEventTarget::s_info)) return throwVMTypeError(exec); JSTestEventTarget* castedThis = jsCast<JSTestEventTarget*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info); TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl()); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); int index(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).toUInt32(exec)); if (index < 0) { setDOMException(exec, INDEX_SIZE_ERR); return JSValue::encode(jsUndefined()); } if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->item(index))); return JSValue::encode(result); }
JSValue JSDOMWindow::showModalDialog(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (UNLIKELY(state.argumentCount() < 1)) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); String urlString = convert<IDLNullable<IDLDOMString>>(state, state.argument(0)); RETURN_IF_EXCEPTION(scope, JSValue()); String dialogFeaturesString = convert<IDLNullable<IDLDOMString>>(state, state.argument(2)); RETURN_IF_EXCEPTION(scope, JSValue()); DialogHandler handler(state); wrapped().showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(&state), firstDOMWindow(&state), [&handler](DOMWindow& dialog) { handler.dialogCreated(dialog); }); return handler.returnValue(); }
EncodedJSValue JSC_HOST_CALL constructJSWorker(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); ASSERT(jsCast<DOMConstructorObject*>(state.jsCallee())); ASSERT(jsCast<DOMConstructorObject*>(state.jsCallee())->globalObject()); auto& globalObject = *jsCast<DOMConstructorObject*>(state.jsCallee())->globalObject(); if (!state.argumentCount()) return throwVMError(&state, scope, createNotEnoughArgumentsError(&state)); String scriptURL = state.uncheckedArgument(0).toWTFString(&state); RETURN_IF_EXCEPTION(scope, encodedJSValue()); // See section 4.8.2 step 14 of WebWorkers for why this is the lexicalGlobalObject. auto& window = asJSDOMWindow(state.lexicalGlobalObject())->wrapped(); ASSERT(window.document()); return JSValue::encode(toJSNewlyCreated(state, globalObject, scope, Worker::create(*window.document(), scriptURL, globalObject.runtimeFlags()))); }
EncodedJSValue JSC_HOST_CALL jsAudioListenerPrototypeFunctionSetVelocity(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSAudioListener* castedThis = jsDynamicCast<JSAudioListener*>(thisValue); if (!castedThis) return throwVMTypeError(exec); ASSERT_GC_OBJECT_INHERITS(castedThis, JSAudioListener::info()); AudioListener& impl = castedThis->impl(); if (exec->argumentCount() < 3) return throwVMError(exec, createNotEnoughArgumentsError(exec)); float x(exec->argument(0).toFloat(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); float y(exec->argument(1).toFloat(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); float z(exec->argument(2).toFloat(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); impl.setVelocity(x, y, z); return JSValue::encode(jsUndefined()); }
EncodedJSValue JSC_HOST_CALL jsSVGTransformPrototypeFunctionSetSkewY(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSSVGTransform* castedThis = jsDynamicCast<JSSVGTransform*>(thisValue); if (!castedThis) return throwVMTypeError(exec); ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGTransform::info()); SVGPropertyTearOff<SVGTransform> & impl = castedThis->impl(); if (impl.isReadOnly()) { setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR); return JSValue::encode(jsUndefined()); } SVGTransform& podImpl = impl.propertyReference(); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); float angle(exec->argument(0).toFloat(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); podImpl.setSkewY(angle); impl.commitChange(); return JSValue::encode(jsUndefined()); }
JSValue JSWebGLRenderingContextBase::getAttachedShaders(ExecState* exec) { if (exec->argumentCount() < 1) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; WebGLRenderingContextBase& context = impl(); WebGLProgram* program = JSWebGLProgram::toWrapped(exec->uncheckedArgument(0)); if (!program && !exec->uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(exec); Vector<RefPtr<WebGLShader>> shaders; bool succeed = context.getAttachedShaders(program, shaders, ec); if (ec) { setDOMException(exec, ec); return jsNull(); } if (!succeed) return jsNull(); JSC::MarkedArgumentBuffer list; for (size_t ii = 0; ii < shaders.size(); ++ii) list.append(toJS(exec, globalObject(), shaders[ii].get())); return constructArray(exec, 0, globalObject(), list); }
template<> EncodedJSValue JSC_HOST_CALL JSTestInterfaceConstructor::construct(ExecState* state) { auto* castedThis = jsCast<JSTestInterfaceConstructor*>(state->callee()); if (UNLIKELY(state->argumentCount() < 1)) return throwVMError(state, createNotEnoughArgumentsError(state)); ExceptionCode ec = 0; auto str1 = state->argument(0).toWTFString(state); if (UNLIKELY(state->hadException())) return JSValue::encode(jsUndefined()); auto str2 = state->argument(1).isUndefined() ? ASCIILiteral("defaultString") : state->uncheckedArgument(1).toWTFString(state); if (UNLIKELY(state->hadException())) return JSValue::encode(jsUndefined()); ScriptExecutionContext* context = castedThis->scriptExecutionContext(); if (UNLIKELY(!context)) return throwConstructorDocumentUnavailableError(*state, "TestInterface"); auto object = TestInterface::create(*context, str1, str2, ec); if (UNLIKELY(ec)) { setDOMException(state, ec); return JSValue::encode(JSValue()); } return JSValue::encode(asObject(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)))); }
JSValue JSWebGLRenderingContext::getUniform(ExecState* exec) { if (exec->argumentCount() != 2) return throwError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info)) return throwTypeError(exec); WebGLProgram* program = toWebGLProgram(exec->argument(0)); if (exec->argumentCount() > 1 && !exec->argument(1).isUndefinedOrNull() && !exec->argument(1).inherits(&JSWebGLUniformLocation::s_info)) return throwTypeError(exec); WebGLUniformLocation* loc = toWebGLUniformLocation(exec->argument(1)); if (exec->hadException()) return jsUndefined(); WebGLGetInfo info = context->getUniform(program, loc, ec); if (ec) { setDOMException(exec, ec); return jsUndefined(); } return toJS(exec, globalObject(), info); }
EncodedJSValue JSC_HOST_CALL JSTestNamedConstructorNamedConstructor::constructJSTestNamedConstructor(ExecState* exec) { JSTestNamedConstructorNamedConstructor* castedThis = jsCast<JSTestNamedConstructorNamedConstructor*>(exec->callee()); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; const String& str1(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).toString(exec)->value(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); const String& str2(ustringToString(MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined).toString(exec)->value(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); const String& str3(ustringToString(MAYBE_MISSING_PARAMETER(exec, 2, DefaultIsNullString).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 2, DefaultIsNullString).toString(exec)->value(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); RefPtr<TestNamedConstructor> object = TestNamedConstructor::createForJSConstructor(castedThis->document(), str1, str2, str3, ec); if (ec) { setDOMException(exec, ec); return JSValue::encode(JSValue()); } return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get()))); }
EncodedJSValue JSC_HOST_CALL JSTestInterfaceConstructor::constructJSTestInterface(ExecState* exec) { JSTestInterfaceConstructor* castedThis = jsCast<JSTestInterfaceConstructor*>(exec->callee()); if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; const String& str1(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); const String& str2(exec->argument(1).isEmpty() ? String() : exec->argument(1).toString(exec)->value(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); ScriptExecutionContext* context = castedThis->scriptExecutionContext(); if (!context) return throwVMError(exec, createReferenceError(exec, "TestInterface constructor associated document is unavailable")); RefPtr<TestInterface> object = TestInterface::create(context, str1, str2, ec); if (ec) { setDOMException(exec, ec); return JSValue::encode(JSValue()); } return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get()))); }
EncodedJSValue JSC_HOST_CALL JSWebSocketConstructor::constructJSWebSocket(ExecState* exec) { JSWebSocketConstructor* jsConstructor = jsCast<JSWebSocketConstructor*>(exec->callee()); ScriptExecutionContext* context = jsConstructor->scriptExecutionContext(); if (!context) return throwVMError(exec, createReferenceError(exec, "WebSocket constructor associated document is unavailable")); if (!exec->argumentCount()) return throwVMError(exec, createNotEnoughArgumentsError(exec)); String urlString = exec->argument(0).toString(exec)->value(exec); if (exec->hadException()) return throwVMError(exec, createSyntaxError(exec, "wrong URL")); RefPtr<WebSocket> webSocket = WebSocket::create(context); ExceptionCode ec = 0; if (exec->argumentCount() < 2) webSocket->connect(urlString, ec); else { JSValue protocolsValue = exec->argument(1); if (isJSArray(protocolsValue)) { Vector<String> protocols; JSArray* protocolsArray = asArray(protocolsValue); for (unsigned i = 0; i < protocolsArray->length(); ++i) { String protocol = protocolsArray->getIndex(exec, i).toString(exec)->value(exec); if (exec->hadException()) return JSValue::encode(JSValue()); protocols.append(protocol); } webSocket->connect(urlString, protocols, ec); } else { String protocol = protocolsValue.toString(exec)->value(exec); if (exec->hadException()) return JSValue::encode(JSValue()); webSocket->connect(urlString, protocol, ec); } } setDOMException(exec, ec); return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), WebSocket, webSocket.get())); }
JSValue JSHTMLCanvasElement::getContext(ExecState& state) { if (UNLIKELY(state.argumentCount() < 1)) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); HTMLCanvasElement& canvas = wrapped(); const String& contextId = state.uncheckedArgument(0).toWTFString(&state); RefPtr<CanvasContextAttributes> attrs; #if ENABLE(WEBGL) if (HTMLCanvasElement::is3dType(contextId)) { get3DContextAttributes(state, attrs); if (state.hadException()) return jsUndefined(); } #endif CanvasRenderingContext* context = canvas.getContext(contextId, attrs.get()); if (!context) return jsNull(); return toJS(&state, globalObject(), *context); }