mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:57:47 +00:00
LibJS: Remove GlobalObject from VM::throw_completion()
This is a continuation of the previous five commits. A first big step into the direction of no longer having to pass a realm (or currently, a global object) trough layers upon layers of AOs! Unlike the create() APIs we can safely assume that this is only ever called when a running execution context and therefore current realm exists. If not, you can always manually allocate the Error and put it in a Completion :^) In the spec, throw exceptions implicitly use the current realm's intrinsics as well: https://tc39.es/ecma262/#sec-throw-an-exception
This commit is contained in:
parent
5398dcc55e
commit
f3117d46dc
165 changed files with 892 additions and 900 deletions
|
@ -31,7 +31,7 @@ void AudioConstructor::initialize(JS::Realm& realm)
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> AudioConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Audio");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Audio");
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-audio
|
||||
|
|
|
@ -30,7 +30,7 @@ void CSSNamespace::initialize(JS::Realm& realm)
|
|||
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
|
||||
{
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "CSS.escape");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "CSS.escape");
|
||||
|
||||
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||
return JS::js_string(vm, Web::CSS::serialize_an_identifier(identifier));
|
||||
|
@ -40,7 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
|
|||
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
||||
{
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
|
||||
|
||||
if (vm.argument_count() >= 2) {
|
||||
// When the supports(property, value) method is invoked with two arguments property and value:
|
||||
|
|
|
@ -81,7 +81,7 @@ JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS:
|
|||
return JS::PropertyDescriptor { .value = JS::js_undefined(), .writable = false, .enumerable = false, .configurable = true };
|
||||
|
||||
// 2. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't access property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't access property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-)
|
||||
|
@ -201,7 +201,7 @@ JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject& global_objec
|
|||
|
||||
// 6. If getter is undefined, then throw a "SecurityError" DOMException.
|
||||
if (!getter.has_value())
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't get property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't get property '{}' on cross-origin object", property_key)));
|
||||
|
||||
// 7. Return ? Call(getter, Receiver).
|
||||
return JS::call(global_object, *getter, receiver);
|
||||
|
@ -229,7 +229,7 @@ JS::ThrowCompletionOr<bool> cross_origin_set(JS::GlobalObject& global_object, JS
|
|||
}
|
||||
|
||||
// 4. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't set property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't set property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 7.2.3.7 CrossOriginOwnPropertyKeys ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginownpropertykeys-(-o-)
|
||||
|
|
|
@ -67,7 +67,7 @@ ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& global_obj
|
|||
switch (exception.type) {
|
||||
#define E(x) \
|
||||
case DOM::SimpleExceptionType::x: \
|
||||
return vm.template throw_completion<JS::x>(global_object, exception.message);
|
||||
return vm.template throw_completion<JS::x>(exception.message);
|
||||
|
||||
ENUMERATE_SIMPLE_WEBIDL_EXCEPTION_TYPES(E)
|
||||
|
||||
|
@ -77,7 +77,7 @@ ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& global_obj
|
|||
}
|
||||
},
|
||||
[&](NonnullRefPtr<DOM::DOMException> exception) {
|
||||
return vm.template throw_completion<DOMExceptionWrapper>(global_object, move(exception));
|
||||
return vm.template throw_completion<DOMExceptionWrapper>(move(exception));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -88,7 +88,7 @@ JS::Completion call_user_object_operation(Bindings::CallbackType& callback, Stri
|
|||
|
||||
// 4. If ! IsCallable(X) is false, then set completion to a new Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}, and jump to the step labeled return.
|
||||
if (!get_result.value().is_function()) {
|
||||
completion = realm.vm().template throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAFunction, get_result.value().to_string_without_side_effects());
|
||||
completion = realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, get_result.value().to_string_without_side_effects());
|
||||
return clean_up_on_return(stored_settings, relevant_settings, completion);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ void ImageConstructor::initialize(JS::Realm& realm)
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> ImageConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Image");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Image");
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-image
|
||||
|
|
|
@ -20,12 +20,12 @@ LocationConstructor::~LocationConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> LocationConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Location");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Location");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> LocationConstructor::construct(FunctionObject&)
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Location");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Location");
|
||||
}
|
||||
|
||||
void LocationConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -78,7 +78,7 @@ static JS::ThrowCompletionOr<LocationObject*> typed_this_value(JS::GlobalObject&
|
|||
auto& vm = global_object.vm();
|
||||
auto this_value = vm.this_value(global_object);
|
||||
if (!this_value.is_object() || !is<LocationObject>(this_value.as_object()))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Location");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Location");
|
||||
return static_cast<LocationObject*>(&this_value.as_object());
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
|
|||
auto new_href = TRY(vm.argument(0).to_string(global_object));
|
||||
auto href_url = window.impl().associated_document().parse_url(new_href);
|
||||
if (!href_url.is_valid())
|
||||
return vm.throw_completion<JS::URIError>(global_object, String::formatted("Invalid URL '{}'", new_href));
|
||||
return vm.throw_completion<JS::URIError>(String::formatted("Invalid URL '{}'", new_href));
|
||||
|
||||
// 3. Location-object navigate given the resulting URL record.
|
||||
window.impl().did_set_location_href({}, href_url);
|
||||
|
@ -313,7 +313,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_define_own_property(JS::Pro
|
|||
}
|
||||
|
||||
// 2. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't define property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't define property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get
|
||||
|
@ -353,7 +353,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_delete(JS::PropertyKey cons
|
|||
return JS::Object::internal_delete(property_key);
|
||||
|
||||
// 2. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't delete property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't delete property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeys
|
||||
|
|
|
@ -284,7 +284,7 @@ JS::VM& main_thread_vm()
|
|||
// FIXME: Implement 8.1.5.4.4 HostGetSupportedImportAssertions(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions
|
||||
|
||||
vm->host_resolve_imported_module = [&](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr<NonnullRefPtr<JS::Module>> {
|
||||
return vm->throw_completion<JS::InternalError>(vm->current_realm()->global_object(), JS::ErrorType::NotImplemented, "Modules in the browser");
|
||||
return vm->throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Modules in the browser");
|
||||
};
|
||||
|
||||
// NOTE: We push a dummy execution context onto the JS execution context stack,
|
||||
|
|
|
@ -20,12 +20,12 @@ NavigatorConstructor::~NavigatorConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> NavigatorConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Navigator");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Navigator");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> NavigatorConstructor::construct(FunctionObject&)
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Navigator");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Navigator");
|
||||
}
|
||||
|
||||
void NavigatorConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -32,7 +32,7 @@ void OptionConstructor::initialize(JS::Realm& realm)
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> OptionConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Option");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Option");
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define REPLACEABLE_PROPERTY_SETTER(ObjectType, property) \
|
||||
auto this_value = vm.this_value(global_object); \
|
||||
if (!this_value.is_object() || !is<ObjectType>(this_value.as_object())) \
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, #ObjectType); \
|
||||
TRY(this_value.as_object().internal_define_own_property( \
|
||||
#property, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true })); \
|
||||
#define REPLACEABLE_PROPERTY_SETTER(ObjectType, property) \
|
||||
auto this_value = vm.this_value(global_object); \
|
||||
if (!this_value.is_object() || !is<ObjectType>(this_value.as_object())) \
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, #ObjectType); \
|
||||
TRY(this_value.as_object().internal_define_own_property( \
|
||||
#property, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true })); \
|
||||
return JS::js_undefined();
|
||||
|
|
|
@ -20,12 +20,12 @@ WindowConstructor::~WindowConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> WindowConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Window");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Window");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> WindowConstructor::construct(FunctionObject&)
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Window");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Window");
|
||||
}
|
||||
|
||||
void WindowConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -187,7 +187,7 @@ static JS::ThrowCompletionOr<HTML::Window*> impl_from(JS::VM& vm, JS::GlobalObje
|
|||
auto* this_object = MUST(this_value.to_object(global_object));
|
||||
|
||||
if (!is<WindowObject>(*this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WindowObject");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WindowObject");
|
||||
return &static_cast<WindowObject*>(this_object)->impl();
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout)
|
|||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "setTimeout");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "setTimeout");
|
||||
|
||||
auto handler = TRY(make_timer_handler(global_object, vm.argument(0)));
|
||||
|
||||
|
@ -264,7 +264,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_interval)
|
|||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "setInterval");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "setInterval");
|
||||
|
||||
auto handler = TRY(make_timer_handler(global_object, vm.argument(0)));
|
||||
|
||||
|
@ -310,10 +310,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_animation_frame)
|
|||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "requestAnimationFrame");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "requestAnimationFrame");
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(global_object));
|
||||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
NonnullOwnPtr<Bindings::CallbackType> callback = adopt_own(*new Bindings::CallbackType(JS::make_handle(callback_object), HTML::incumbent_settings_object()));
|
||||
return JS::Value(impl->request_animation_frame(move(callback)));
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_animation_frame)
|
|||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "cancelAnimationFrame");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "cancelAnimationFrame");
|
||||
auto id = TRY(vm.argument(0).to_i32(global_object));
|
||||
impl->cancel_animation_frame(id);
|
||||
return JS::js_undefined();
|
||||
|
@ -332,10 +332,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::queue_microtask)
|
|||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "queueMicrotask");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "queueMicrotask");
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(global_object));
|
||||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
|
||||
auto callback = adopt_own(*new Bindings::CallbackType(JS::make_handle(callback_object), HTML::incumbent_settings_object()));
|
||||
|
||||
|
@ -347,10 +347,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_idle_callback)
|
|||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "requestIdleCallback");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "requestIdleCallback");
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(global_object));
|
||||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
// FIXME: accept options object
|
||||
|
||||
auto callback = adopt_own(*new Bindings::CallbackType(JS::make_handle(callback_object), HTML::incumbent_settings_object()));
|
||||
|
@ -362,7 +362,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_idle_callback)
|
|||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "cancelIdleCallback");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "cancelIdleCallback");
|
||||
auto id = TRY(vm.argument(0).to_u32(global_object));
|
||||
impl->cancel_idle_callback(id);
|
||||
return JS::js_undefined();
|
||||
|
@ -371,11 +371,11 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_idle_callback)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
||||
{
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "atob");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "atob");
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto decoded = decode_base64(StringView(string));
|
||||
if (decoded.is_error())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidFormat, "Base64");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidFormat, "Base64");
|
||||
|
||||
// decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
|
||||
auto decoder = TextCodec::decoder_for("windows-1252");
|
||||
|
@ -386,14 +386,14 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
||||
{
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "btoa");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "btoa");
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
|
||||
Vector<u8> byte_string;
|
||||
byte_string.ensure_capacity(string.length());
|
||||
for (u32 code_point : Utf8View(string)) {
|
||||
if (code_point > 0xff)
|
||||
return vm.throw_completion<JS::InvalidCharacterError>(global_object, JS::ErrorType::NotAByteString, "btoa");
|
||||
return vm.throw_completion<JS::InvalidCharacterError>(JS::ErrorType::NotAByteString, "btoa");
|
||||
byte_string.append(code_point);
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_setter)
|
|||
// https://webidl.spec.whatwg.org/#dfn-attribute-setter
|
||||
// 4.1. If no arguments were passed, then throw a TypeError.
|
||||
if (vm.argument_count() == 0)
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "set performance");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "set performance");
|
||||
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
|
||||
|
@ -517,7 +517,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
|
|||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
if (!is<ElementWrapper>(object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "DOM element");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
|
||||
|
||||
return wrap(global_object, impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
|
|||
if (!behavior_string_value.is_undefined())
|
||||
behavior_string = TRY(behavior_string_value.to_string(global_object));
|
||||
if (behavior_string != "smooth" && behavior_string != "auto")
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "Behavior is not one of 'smooth' or 'auto'");
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'");
|
||||
|
||||
} else if (vm.argument_count() >= 2) {
|
||||
// We ignore arguments 2+ in line with behavior of Chrome and Firefox
|
||||
|
@ -655,7 +655,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
|
|||
auto behavior_string_value = TRY(options->get("behavior"));
|
||||
auto behavior_string = behavior_string_value.is_undefined() ? "auto" : TRY(behavior_string_value.to_string(global_object));
|
||||
if (behavior_string != "smooth" && behavior_string != "auto")
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "Behavior is not one of 'smooth' or 'auto'");
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'");
|
||||
ScrollBehavior behavior = (behavior_string == "smooth") ? ScrollBehavior::Smooth : ScrollBehavior::Auto;
|
||||
|
||||
// FIXME: Spec wants us to call scroll(options) here.
|
||||
|
|
|
@ -93,7 +93,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
|
|||
return Optional<JS::PropertyDescriptor> {};
|
||||
|
||||
// 2. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't access property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't access property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 6. Return PropertyDescriptor{ [[Value]]: value, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: true }.
|
||||
|
@ -146,7 +146,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_define_own_property(JS::Proper
|
|||
}
|
||||
|
||||
// 3. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't define property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't define property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get
|
||||
|
@ -222,7 +222,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_delete(JS::PropertyKey const&
|
|||
}
|
||||
|
||||
// 3. Throw a "SecurityError" DOMException.
|
||||
return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't delete property '{}' on cross-origin object", property_key)));
|
||||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't delete property '{}' on cross-origin object", property_key)));
|
||||
}
|
||||
|
||||
// 7.4.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-ownpropertykeys
|
||||
|
|
|
@ -165,7 +165,7 @@ JS::ThrowCompletionOr<void> Headers::for_each(ForEachCallback callback)
|
|||
auto value_pairs_to_iterate_over = [&]() -> JS::ThrowCompletionOr<Vector<Fetch::Infrastructure::Header>> {
|
||||
auto headers_or_error = m_header_list.sort_and_combine();
|
||||
if (headers_or_error.is_error())
|
||||
return vm.throw_completion<JS::InternalError>(global_object, JS::ErrorType::NotEnoughMemoryToAllocate);
|
||||
return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotEnoughMemoryToAllocate);
|
||||
return headers_or_error.release_value();
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ JS::ThrowCompletionOr<JS::Object*> HeadersIterator::next()
|
|||
auto value_pairs_to_iterate_over = [&]() -> JS::ThrowCompletionOr<Vector<Fetch::Infrastructure::Header>> {
|
||||
auto headers_or_error = m_headers.m_header_list.sort_and_combine();
|
||||
if (headers_or_error.is_error())
|
||||
return vm.throw_completion<JS::InternalError>(global_object, JS::ErrorType::NotEnoughMemoryToAllocate);
|
||||
return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotEnoughMemoryToAllocate);
|
||||
return headers_or_error.release_value();
|
||||
};
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
|
||||
// 5. If script's error to rethrow is not null, then set evaluationStatus to Completion { [[Type]]: throw, [[Value]]: script's error to rethrow, [[Target]]: empty }.
|
||||
if (m_error_to_rethrow.has_value()) {
|
||||
evaluation_status = vm.throw_completion<JS::SyntaxError>(global_object, m_error_to_rethrow.value().to_string());
|
||||
evaluation_status = vm.throw_completion<JS::SyntaxError>(m_error_to_rethrow.value().to_string());
|
||||
} else {
|
||||
auto timer = Core::ElapsedTimer::start_new();
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ WebAssemblyInstanceConstructor::~WebAssemblyInstanceConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> WebAssemblyInstanceConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Instance");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Instance");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(FunctionObject&)
|
||||
|
@ -34,7 +34,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(Fun
|
|||
|
||||
auto* module_argument = TRY(vm.argument(0).to_object(global_object));
|
||||
if (!is<WebAssemblyModuleObject>(module_argument))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
|
||||
auto result = TRY(WebAssemblyObject::instantiate_module(module_object.module(), vm, global_object));
|
||||
return heap().allocate<WebAssemblyInstanceObject>(realm, realm, result);
|
||||
|
|
|
@ -21,7 +21,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)
|
|||
auto this_value = vm.this_value(global_object);
|
||||
auto* this_object = TRY(this_value.to_object(global_object));
|
||||
if (!is<WebAssemblyInstanceObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Instance");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Instance");
|
||||
auto object = static_cast<WebAssemblyInstanceObject*>(this_object);
|
||||
return object->m_exports_object;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ WebAssemblyMemoryConstructor::~WebAssemblyMemoryConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> WebAssemblyMemoryConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Memory");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Memory");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(FunctionObject&)
|
||||
|
@ -35,7 +35,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
|
|||
auto maximum_value = TRY(descriptor->get("maximum"));
|
||||
|
||||
if (!initial_value.is_number())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Number");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Number");
|
||||
|
||||
u32 initial = TRY(initial_value.to_u32(global_object));
|
||||
|
||||
|
@ -46,10 +46,10 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
|
|||
|
||||
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
|
||||
if (!address.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "Wasm Memory allocation failed");
|
||||
return vm.throw_completion<JS::TypeError>("Wasm Memory allocation failed");
|
||||
|
||||
if (!WebAssemblyObject::s_abstract_machine.store().get(*address)->grow(initial))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, String::formatted("Wasm Memory grow failed: {}", initial));
|
||||
return vm.throw_completion<JS::TypeError>(String::formatted("Wasm Memory grow failed: {}", initial));
|
||||
|
||||
return vm.heap().allocate<WebAssemblyMemoryObject>(realm, realm, *address);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
|||
auto page_count = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||
auto address = memory_object->address();
|
||||
auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||
|
@ -31,7 +31,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
|||
|
||||
auto previous_size = memory->size() / Wasm::Constants::page_size;
|
||||
if (!memory->grow(page_count * Wasm::Constants::page_size))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "Memory.grow() grows past the stated limit of the memory instance");
|
||||
return vm.throw_completion<JS::TypeError>("Memory.grow() grows past the stated limit of the memory instance");
|
||||
|
||||
return JS::Value(static_cast<u32>(previous_size));
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
|||
|
||||
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||
auto address = memory_object->address();
|
||||
auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||
|
|
|
@ -23,7 +23,7 @@ WebAssemblyModuleConstructor::~WebAssemblyModuleConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> WebAssemblyModuleConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Module");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Module");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> WebAssemblyModuleConstructor::construct(FunctionObject&)
|
||||
|
|
|
@ -131,7 +131,7 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::GlobalObject& global_object, JS::
|
|||
auto& buffer = static_cast<JS::DataView&>(*buffer_object);
|
||||
data = buffer.viewed_array_buffer()->buffer().span().slice(buffer.byte_offset(), buffer.byte_length());
|
||||
} else {
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "Not a BufferSource");
|
||||
return vm.throw_completion<JS::TypeError>("Not a BufferSource");
|
||||
}
|
||||
InputMemoryStream stream { data };
|
||||
auto module_result = Wasm::Module::parse(stream);
|
||||
|
@ -142,12 +142,12 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::GlobalObject& global_object, JS::
|
|||
};
|
||||
if (module_result.is_error()) {
|
||||
// FIXME: Throw CompileError instead.
|
||||
return vm.throw_completion<JS::TypeError>(global_object, Wasm::parse_error_to_string(module_result.error()));
|
||||
return vm.throw_completion<JS::TypeError>(Wasm::parse_error_to_string(module_result.error()));
|
||||
}
|
||||
|
||||
if (auto validation_result = WebAssemblyObject::s_abstract_machine.validate(module_result.value()); validation_result.is_error()) {
|
||||
// FIXME: Throw CompileError instead.
|
||||
return vm.throw_completion<JS::TypeError>(global_object, validation_result.error().error_string);
|
||||
return vm.throw_completion<JS::TypeError>(validation_result.error().error_string);
|
||||
}
|
||||
|
||||
WebAssemblyObject::s_compiled_modules.append(make<WebAssemblyObject::CompiledWebAssemblyModule>(module_result.release_value()));
|
||||
|
@ -250,11 +250,11 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
if (import_.is_number() || import_.is_bigint()) {
|
||||
if (import_.is_number() && type.type().kind() == Wasm::ValueType::I64) {
|
||||
// FIXME: Throw a LinkError instead.
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "LinkError: Import resolution attempted to cast a Number to a BigInteger");
|
||||
return vm.throw_completion<JS::TypeError>("LinkError: Import resolution attempted to cast a Number to a BigInteger");
|
||||
}
|
||||
if (import_.is_bigint() && type.type().kind() != Wasm::ValueType::I64) {
|
||||
// FIXME: Throw a LinkError instead.
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "LinkError: Import resolution attempted to cast a BigInteger to a Number");
|
||||
return vm.throw_completion<JS::TypeError>("LinkError: Import resolution attempted to cast a BigInteger to a Number");
|
||||
}
|
||||
auto cast_value = TRY(to_webassembly_value(global_object, import_, type.type()));
|
||||
address = s_abstract_machine.store().allocate({ type.type(), false }, cast_value);
|
||||
|
@ -264,7 +264,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
// let globaladdr be v.[[Global]]
|
||||
|
||||
// FIXME: Throw a LinkError instead
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "LinkError: Invalid value for global type");
|
||||
return vm.throw_completion<JS::TypeError>("LinkError: Invalid value for global type");
|
||||
}
|
||||
|
||||
resolved_imports.set(import_name, Wasm::ExternValue { *address });
|
||||
|
@ -273,7 +273,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
[&](Wasm::MemoryType const&) -> JS::ThrowCompletionOr<void> {
|
||||
if (!import_.is_object() || !is<WebAssemblyMemoryObject>(import_.as_object())) {
|
||||
// FIXME: Throw a LinkError instead
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "LinkError: Expected an instance of WebAssembly.Memory for a memory import");
|
||||
return vm.throw_completion<JS::TypeError>("LinkError: Expected an instance of WebAssembly.Memory for a memory import");
|
||||
}
|
||||
auto address = static_cast<WebAssemblyMemoryObject const&>(import_.as_object()).address();
|
||||
resolved_imports.set(import_name, Wasm::ExternValue { address });
|
||||
|
@ -282,7 +282,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
[&](Wasm::TableType const&) -> JS::ThrowCompletionOr<void> {
|
||||
if (!import_.is_object() || !is<WebAssemblyTableObject>(import_.as_object())) {
|
||||
// FIXME: Throw a LinkError instead
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "LinkError: Expected an instance of WebAssembly.Table for a table import");
|
||||
return vm.throw_completion<JS::TypeError>("LinkError: Expected an instance of WebAssembly.Table for a table import");
|
||||
}
|
||||
auto address = static_cast<WebAssemblyTableObject const&>(import_.as_object()).address();
|
||||
resolved_imports.set(import_name, Wasm::ExternValue { address });
|
||||
|
@ -291,7 +291,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
[&](auto const&) -> JS::ThrowCompletionOr<void> {
|
||||
// FIXME: Implement these.
|
||||
dbgln("Unimplemented import of non-function attempted");
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "LinkError: Not Implemented");
|
||||
return vm.throw_completion<JS::TypeError>("LinkError: Not Implemented");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -303,13 +303,13 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
StringBuilder builder;
|
||||
builder.append("LinkError: Missing "sv);
|
||||
builder.join(' ', link_result.error().missing_imports);
|
||||
return vm.throw_completion<JS::TypeError>(global_object, builder.build());
|
||||
return vm.throw_completion<JS::TypeError>(builder.build());
|
||||
}
|
||||
|
||||
auto instance_result = s_abstract_machine.instantiate(module, link_result.release_value());
|
||||
if (instance_result.is_error()) {
|
||||
// FIXME: Throw a LinkError instead.
|
||||
return vm.throw_completion<JS::TypeError>(global_object, instance_result.error().error);
|
||||
return vm.throw_completion<JS::TypeError>(instance_result.error().error);
|
||||
}
|
||||
|
||||
s_instantiated_modules.append(instance_result.release_value());
|
||||
|
@ -431,7 +431,7 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::GlobalObject& global
|
|||
}
|
||||
}
|
||||
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Exported function");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Exported function");
|
||||
}
|
||||
case Wasm::ValueType::ExternReference:
|
||||
case Wasm::ValueType::NullExternReference:
|
||||
|
@ -465,7 +465,7 @@ JS::NativeFunction* create_native_function(JS::GlobalObject& global_object, Wasm
|
|||
auto result = WebAssemblyObject::s_abstract_machine.invoke(address, move(values));
|
||||
// FIXME: Use the convoluted mapping of errors defined in the spec.
|
||||
if (result.is_trap())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, String::formatted("Wasm execution trapped (WIP): {}", result.trap().reason));
|
||||
return vm.throw_completion<JS::TypeError>(String::formatted("Wasm execution trapped (WIP): {}", result.trap().reason));
|
||||
|
||||
if (result.values().is_empty())
|
||||
return JS::js_undefined();
|
||||
|
|
|
@ -23,7 +23,7 @@ WebAssemblyTableConstructor::~WebAssemblyTableConstructor() = default;
|
|||
|
||||
JS::ThrowCompletionOr<JS::Value> WebAssemblyTableConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Table");
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Table");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(FunctionObject&)
|
||||
|
@ -35,7 +35,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
auto descriptor = TRY(vm.argument(0).to_object(global_object));
|
||||
auto element_value = TRY(descriptor->get("element"));
|
||||
if (!element_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidHint, element_value.to_string_without_side_effects());
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidHint, element_value.to_string_without_side_effects());
|
||||
auto& element = element_value.as_string().string();
|
||||
|
||||
Optional<Wasm::ValueType> reference_type;
|
||||
|
@ -45,7 +45,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
reference_type = Wasm::ValueType(Wasm::ValueType::ExternReference);
|
||||
|
||||
if (!reference_type.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidHint, element);
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidHint, element);
|
||||
|
||||
auto initial_value = TRY(descriptor->get("initial"));
|
||||
auto maximum_value = TRY(descriptor->get("maximum"));
|
||||
|
@ -58,7 +58,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
maximum = TRY(maximum_value.to_u32(global_object));
|
||||
|
||||
if (maximum.has_value() && maximum.value() < initial)
|
||||
return vm.throw_completion<JS::RangeError>(global_object, "maximum should be larger than or equal to initial");
|
||||
return vm.throw_completion<JS::RangeError>("maximum should be larger than or equal to initial");
|
||||
|
||||
auto value_value = TRY(descriptor->get("value"));
|
||||
auto reference_value = TRY([&]() -> JS::ThrowCompletionOr<Wasm::Value> {
|
||||
|
@ -72,7 +72,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
|
||||
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::TableType { *reference_type, Wasm::Limits { initial, maximum } });
|
||||
if (!address.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, "Wasm Table allocation failed");
|
||||
return vm.throw_completion<JS::TypeError>("Wasm Table allocation failed");
|
||||
|
||||
auto& table = *WebAssemblyObject::s_abstract_machine.store().get(*address);
|
||||
for (auto& element : table.elements())
|
||||
|
|
|
@ -25,7 +25,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
|
|||
|
||||
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
auto address = table_object->address();
|
||||
auto* table = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||
|
@ -44,7 +44,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
|
|||
auto& reference = reference_value.value().get<Wasm::Reference>();
|
||||
|
||||
if (!table->grow(delta, reference))
|
||||
return vm.throw_completion<JS::RangeError>(global_object, "Failed to grow table");
|
||||
return vm.throw_completion<JS::RangeError>("Failed to grow table");
|
||||
|
||||
return JS::Value(static_cast<u32>(initial_size));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
|
|||
|
||||
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
auto address = table_object->address();
|
||||
auto* table = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||
|
@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
|
|||
return JS::js_undefined();
|
||||
|
||||
if (table->elements().size() <= index)
|
||||
return vm.throw_completion<JS::RangeError>(global_object, "Table element index out of range");
|
||||
return vm.throw_completion<JS::RangeError>("Table element index out of range");
|
||||
|
||||
auto& ref = table->elements()[index];
|
||||
if (!ref.has_value())
|
||||
|
@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
|
|||
|
||||
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
auto address = table_object->address();
|
||||
auto* table = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||
|
@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
|
|||
return JS::js_undefined();
|
||||
|
||||
if (table->elements().size() <= index)
|
||||
return vm.throw_completion<JS::RangeError>(global_object, "Table element index out of range");
|
||||
return vm.throw_completion<JS::RangeError>("Table element index out of range");
|
||||
|
||||
auto value_value = vm.argument(1);
|
||||
auto reference_value = TRY([&]() -> JS::ThrowCompletionOr<Wasm::Value> {
|
||||
|
@ -107,7 +107,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::length_getter)
|
|||
{
|
||||
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
auto address = table_object->address();
|
||||
auto* table = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||
|
|
|
@ -16,7 +16,7 @@ JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attribute
|
|||
|
||||
// NOTE: This code was generated by the IDL code generator and then cleaned up.
|
||||
if (!value.is_nullish() && !value.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebGLContextAttributes");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebGLContextAttributes");
|
||||
|
||||
WebGLContextAttributes context_attributes {};
|
||||
|
||||
|
@ -109,7 +109,7 @@ JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attribute
|
|||
else if (power_preference_string == "default"sv)
|
||||
power_preference_value = WebGLPowerPreference::Default;
|
||||
else
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidEnumerationValue, power_preference_string, "WebGLPowerPreference");
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, power_preference_string, "WebGLPowerPreference");
|
||||
}
|
||||
|
||||
context_attributes.power_preference = power_preference_value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue