mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:47:44 +00:00
LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
This commit is contained in:
parent
f6c4a0f5d0
commit
a022e548b8
129 changed files with 1230 additions and 1325 deletions
|
@ -37,6 +37,8 @@ JS::ThrowCompletionOr<JS::Value> AudioConstructor::call()
|
|||
// https://html.spec.whatwg.org/multipage/media.html#dom-audio
|
||||
JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let document be the current global object's associated Document.
|
||||
auto& window = static_cast<WindowObject&>(HTML::current_global_object());
|
||||
auto& document = window.impl().associated_document();
|
||||
|
@ -47,12 +49,12 @@ JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&)
|
|||
// 3. Set an attribute value for audio using "preload" and "auto".
|
||||
audio->set_attribute(HTML::AttributeNames::preload, "auto"sv);
|
||||
|
||||
auto src_value = vm().argument(0);
|
||||
auto src_value = vm.argument(0);
|
||||
|
||||
// 4. If src is given, then set an attribute value for audio using "src" and src.
|
||||
// (This will cause the user agent to invoke the object's resource selection algorithm before returning.)
|
||||
if (!src_value.is_undefined()) {
|
||||
auto src = TRY(src_value.to_string(global_object()));
|
||||
auto src = TRY(src_value.to_string(vm));
|
||||
audio->set_attribute(HTML::AttributeNames::src, move(src));
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
|
|||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "CSS.escape");
|
||||
|
||||
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
return JS::js_string(vm, Web::CSS::serialize_an_identifier(identifier));
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,13 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
|||
|
||||
if (vm.argument_count() >= 2) {
|
||||
// When the supports(property, value) method is invoked with two arguments property and value:
|
||||
auto property_name = TRY(vm.argument(0).to_string(global_object));
|
||||
auto property_name = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
|
||||
// and value successfully parses according to that property’s grammar, return true.
|
||||
auto property = CSS::property_id_from_string(property_name);
|
||||
if (property != CSS::PropertyID::Invalid) {
|
||||
auto value_string = TRY(vm.argument(1).to_string(global_object));
|
||||
auto value_string = TRY(vm.argument(1).to_string(vm));
|
||||
if (parse_css_value({}, value_string, property))
|
||||
return JS::Value(true);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
|||
return JS::Value(false);
|
||||
} else {
|
||||
// When the supports(conditionText) method is invoked with a single conditionText argument:
|
||||
auto supports_text = TRY(vm.argument(0).to_string(global_object));
|
||||
auto supports_text = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
|
||||
if (auto supports = parse_css_supports({}, supports_text); supports && supports->matches())
|
||||
|
|
|
@ -48,11 +48,12 @@ JS::ThrowCompletionOr<bool> CSSStyleDeclarationWrapper::internal_set(JS::Propert
|
|||
{
|
||||
if (!name.is_string())
|
||||
return Base::internal_set(name, value, receiver);
|
||||
auto& vm = this->vm();
|
||||
auto property_id = property_id_from_name(name.to_string());
|
||||
if (property_id == CSS::PropertyID::Invalid)
|
||||
return Base::internal_set(name, value, receiver);
|
||||
|
||||
auto css_text = TRY(value.to_string(global_object()));
|
||||
auto css_text = TRY(value.to_string(vm));
|
||||
|
||||
impl().set_property(property_id, css_text);
|
||||
return true;
|
||||
|
|
|
@ -37,6 +37,8 @@ JS::ThrowCompletionOr<JS::Value> ImageConstructor::call()
|
|||
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-image
|
||||
JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let document be the current global object's associated Document.
|
||||
auto& window = static_cast<WindowObject&>(HTML::current_global_object());
|
||||
auto& document = window.impl().associated_document();
|
||||
|
@ -45,14 +47,14 @@ JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&)
|
|||
auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML);
|
||||
|
||||
// 3. If width is given, then set an attribute value for img using "width" and width.
|
||||
if (vm().argument_count() > 0) {
|
||||
u32 width = TRY(vm().argument(0).to_u32(global_object()));
|
||||
if (vm.argument_count() > 0) {
|
||||
u32 width = TRY(vm.argument(0).to_u32(vm));
|
||||
image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width));
|
||||
}
|
||||
|
||||
// 4. If height is given, then set an attribute value for img using "height" and height.
|
||||
if (vm().argument_count() > 1) {
|
||||
u32 height = TRY(vm().argument(1).to_u32(global_object()));
|
||||
if (vm.argument_count() > 1) {
|
||||
u32 height = TRY(vm.argument(1).to_u32(vm));
|
||||
image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height));
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
|
|||
// FIXME: 1. If this's relevant Document is null, then return.
|
||||
|
||||
// 2. Parse the given value relative to the entry settings object. If that failed, throw a TypeError exception.
|
||||
auto new_href = TRY(vm.argument(0).to_string(global_object));
|
||||
auto new_href = TRY(vm.argument(0).to_string(vm));
|
||||
auto href_url = window.impl().associated_document().parse_url(new_href);
|
||||
if (!href_url.is_valid())
|
||||
return vm.throw_completion<JS::URIError>(String::formatted("Invalid URL '{}'", new_href));
|
||||
|
@ -227,7 +227,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
|
|||
JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto url = TRY(vm.argument(0).to_string(global_object));
|
||||
auto url = TRY(vm.argument(0).to_string(vm));
|
||||
// FIXME: This needs spec compliance work.
|
||||
window.impl().did_call_location_replace({}, move(url));
|
||||
return JS::js_undefined();
|
||||
|
|
|
@ -38,6 +38,8 @@ JS::ThrowCompletionOr<JS::Value> OptionConstructor::call()
|
|||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option
|
||||
JS::ThrowCompletionOr<JS::Object*> OptionConstructor::construct(FunctionObject&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let document be the current global object's associated Document.
|
||||
auto& window = static_cast<WindowObject&>(HTML::current_global_object());
|
||||
auto& document = window.impl().associated_document();
|
||||
|
@ -46,8 +48,8 @@ JS::ThrowCompletionOr<JS::Object*> OptionConstructor::construct(FunctionObject&)
|
|||
auto option_element = static_ptr_cast<HTML::HTMLOptionElement>(DOM::create_element(document, HTML::TagNames::option, Namespace::HTML));
|
||||
|
||||
// 3. If text is not the empty string, then append to option a new Text node whose data is text.
|
||||
if (vm().argument_count() > 0) {
|
||||
auto text = TRY(vm().argument(0).to_string(global_object()));
|
||||
if (vm.argument_count() > 0) {
|
||||
auto text = TRY(vm.argument(0).to_string(vm));
|
||||
if (!text.is_empty()) {
|
||||
auto new_text_node = adopt_ref(*new DOM::Text(document, text));
|
||||
option_element->append_child(new_text_node);
|
||||
|
@ -55,21 +57,21 @@ JS::ThrowCompletionOr<JS::Object*> OptionConstructor::construct(FunctionObject&)
|
|||
}
|
||||
|
||||
// 4. If value is given, then set an attribute value for option using "value" and value.
|
||||
if (vm().argument_count() > 1) {
|
||||
auto value = TRY(vm().argument(1).to_string(global_object()));
|
||||
if (vm.argument_count() > 1) {
|
||||
auto value = TRY(vm.argument(1).to_string(vm));
|
||||
option_element->set_attribute(HTML::AttributeNames::value, value);
|
||||
}
|
||||
|
||||
// 5. If defaultSelected is true, then set an attribute value for option using "selected" and the empty string.
|
||||
if (vm().argument_count() > 2) {
|
||||
auto default_selected = vm().argument(2).to_boolean();
|
||||
if (vm.argument_count() > 2) {
|
||||
auto default_selected = vm.argument(2).to_boolean();
|
||||
if (default_selected) {
|
||||
option_element->set_attribute(HTML::AttributeNames::selected, "");
|
||||
}
|
||||
}
|
||||
|
||||
// 6. If selected is true, then set option's selectedness to true; otherwise set its selectedness to false (even if defaultSelected is true).
|
||||
option_element->m_selected = vm().argument(3).to_boolean();
|
||||
option_element->m_selected = vm.argument(3).to_boolean();
|
||||
|
||||
// 7. Return option.
|
||||
return wrap(global_object(), option_element);
|
||||
|
|
|
@ -184,7 +184,7 @@ static JS::ThrowCompletionOr<HTML::Window*> impl_from(JS::VM& vm, JS::GlobalObje
|
|||
if (this_value.is_nullish())
|
||||
this_value = &global_object;
|
||||
|
||||
auto* this_object = MUST(this_value.to_object(global_object));
|
||||
auto* this_object = MUST(this_value.to_object(vm));
|
||||
|
||||
if (!is<WindowObject>(*this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WindowObject");
|
||||
|
@ -200,7 +200,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::alert)
|
|||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
String message = "";
|
||||
if (vm.argument_count())
|
||||
message = TRY(vm.argument(0).to_string(global_object));
|
||||
message = TRY(vm.argument(0).to_string(vm));
|
||||
impl->alert(message);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::confirm)
|
|||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
String message = "";
|
||||
if (!vm.argument(0).is_undefined())
|
||||
message = TRY(vm.argument(0).to_string(global_object));
|
||||
message = TRY(vm.argument(0).to_string(vm));
|
||||
return JS::Value(impl->confirm(message));
|
||||
}
|
||||
|
||||
|
@ -220,9 +220,9 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::prompt)
|
|||
String message = "";
|
||||
String default_ = "";
|
||||
if (!vm.argument(0).is_undefined())
|
||||
message = TRY(vm.argument(0).to_string(global_object));
|
||||
message = TRY(vm.argument(0).to_string(vm));
|
||||
if (!vm.argument(1).is_undefined())
|
||||
default_ = TRY(vm.argument(1).to_string(global_object));
|
||||
default_ = TRY(vm.argument(1).to_string(vm));
|
||||
auto response = impl->prompt(message, default_);
|
||||
if (response.is_null())
|
||||
return JS::js_null();
|
||||
|
@ -231,9 +231,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::prompt)
|
|||
|
||||
static JS::ThrowCompletionOr<TimerHandler> make_timer_handler(JS::GlobalObject& global_object, JS::Value handler)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
if (handler.is_function())
|
||||
return Bindings::CallbackType(JS::make_handle<JS::Object>(handler.as_function()), HTML::incumbent_settings_object());
|
||||
return TRY(handler.to_string(global_object));
|
||||
return TRY(handler.to_string(vm));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout
|
||||
|
@ -248,7 +249,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout)
|
|||
|
||||
i32 timeout = 0;
|
||||
if (vm.argument_count() >= 2)
|
||||
timeout = TRY(vm.argument(1).to_i32(global_object));
|
||||
timeout = TRY(vm.argument(1).to_i32(vm));
|
||||
|
||||
JS::MarkedVector<JS::Value> arguments { vm.heap() };
|
||||
for (size_t i = 2; i < vm.argument_count(); ++i)
|
||||
|
@ -270,7 +271,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_interval)
|
|||
|
||||
i32 timeout = 0;
|
||||
if (vm.argument_count() >= 2)
|
||||
timeout = TRY(vm.argument(1).to_i32(global_object));
|
||||
timeout = TRY(vm.argument(1).to_i32(vm));
|
||||
|
||||
JS::MarkedVector<JS::Value> arguments { vm.heap() };
|
||||
for (size_t i = 2; i < vm.argument_count(); ++i)
|
||||
|
@ -287,7 +288,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_timeout)
|
|||
|
||||
i32 id = 0;
|
||||
if (vm.argument_count())
|
||||
id = TRY(vm.argument(0).to_i32(global_object));
|
||||
id = TRY(vm.argument(0).to_i32(vm));
|
||||
|
||||
impl->clear_timeout(id);
|
||||
return JS::js_undefined();
|
||||
|
@ -300,7 +301,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_interval)
|
|||
|
||||
i32 id = 0;
|
||||
if (vm.argument_count())
|
||||
id = TRY(vm.argument(0).to_i32(global_object));
|
||||
id = TRY(vm.argument(0).to_i32(vm));
|
||||
|
||||
impl->clear_interval(id);
|
||||
return JS::js_undefined();
|
||||
|
@ -311,7 +312,7 @@ 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>(JS::ErrorType::BadArgCountOne, "requestAnimationFrame");
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(vm));
|
||||
if (!callback_object->is_function())
|
||||
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()));
|
||||
|
@ -323,7 +324,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>(JS::ErrorType::BadArgCountOne, "cancelAnimationFrame");
|
||||
auto id = TRY(vm.argument(0).to_i32(global_object));
|
||||
auto id = TRY(vm.argument(0).to_i32(vm));
|
||||
impl->cancel_animation_frame(id);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
@ -333,7 +334,7 @@ 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>(JS::ErrorType::BadArgCountAtLeastOne, "queueMicrotask");
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(vm));
|
||||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
|
||||
|
@ -348,7 +349,7 @@ 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>(JS::ErrorType::BadArgCountAtLeastOne, "requestIdleCallback");
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* callback_object = TRY(vm.argument(0).to_object(vm));
|
||||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
// FIXME: accept options object
|
||||
|
@ -363,7 +364,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>(JS::ErrorType::BadArgCountOne, "cancelIdleCallback");
|
||||
auto id = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto id = TRY(vm.argument(0).to_u32(vm));
|
||||
impl->cancel_idle_callback(id);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
@ -372,7 +373,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
|||
{
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "atob");
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_string(vm));
|
||||
auto decoded = decode_base64(StringView(string));
|
||||
if (decoded.is_error())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidFormat, "Base64");
|
||||
|
@ -387,7 +388,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
|||
{
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "btoa");
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
Vector<u8> byte_string;
|
||||
byte_string.ensure_capacity(string.length());
|
||||
|
@ -515,7 +516,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::device_pixel_ratio_getter)
|
|||
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));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
if (!is<ElementWrapper>(object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
|
||||
|
||||
|
@ -534,7 +535,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_selection)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::match_media)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
auto media = TRY(vm.argument(0).to_string(global_object));
|
||||
auto media = TRY(vm.argument(0).to_string(vm));
|
||||
return wrap(global_object, impl->match_media(move(media)));
|
||||
}
|
||||
|
||||
|
@ -579,7 +580,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
|
|||
String behavior_string = "auto";
|
||||
|
||||
if (vm.argument_count() == 1) {
|
||||
auto* options = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* options = TRY(vm.argument(0).to_object(vm));
|
||||
auto left = TRY(options->get("left"));
|
||||
if (!left.is_undefined())
|
||||
x_value = left;
|
||||
|
@ -590,7 +591,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
|
|||
|
||||
auto behavior_string_value = TRY(options->get("behavior"));
|
||||
if (!behavior_string_value.is_undefined())
|
||||
behavior_string = TRY(behavior_string_value.to_string(global_object));
|
||||
behavior_string = TRY(behavior_string_value.to_string(vm));
|
||||
if (behavior_string != "smooth" && behavior_string != "auto")
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'");
|
||||
|
||||
|
@ -602,10 +603,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
|
|||
|
||||
ScrollBehavior behavior = (behavior_string == "smooth") ? ScrollBehavior::Smooth : ScrollBehavior::Auto;
|
||||
|
||||
double x = TRY(x_value.to_double(global_object));
|
||||
double x = TRY(x_value.to_double(vm));
|
||||
x = JS::Value(x).is_finite_number() ? x : 0.0;
|
||||
|
||||
double y = TRY(y_value.to_double(global_object));
|
||||
double y = TRY(y_value.to_double(vm));
|
||||
y = JS::Value(y).is_finite_number() ? y : 0.0;
|
||||
|
||||
// FIXME: Are we calculating the viewport in the way this function expects?
|
||||
|
@ -630,7 +631,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
|
|||
if (vm.argument_count() == 0) {
|
||||
options = JS::Object::create(realm, nullptr);
|
||||
} else if (vm.argument_count() == 1) {
|
||||
options = TRY(vm.argument(0).to_object(global_object));
|
||||
options = TRY(vm.argument(0).to_object(vm));
|
||||
} else if (vm.argument_count() >= 2) {
|
||||
// We ignore arguments 2+ in line with behavior of Chrome and Firefox
|
||||
options = JS::Object::create(realm, nullptr);
|
||||
|
@ -640,10 +641,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
|
|||
}
|
||||
|
||||
auto left_value = TRY(options->get("left"));
|
||||
auto left = TRY(left_value.to_double(global_object));
|
||||
auto left = TRY(left_value.to_double(vm));
|
||||
|
||||
auto top_value = TRY(options->get("top"));
|
||||
auto top = TRY(top_value.to_double(global_object));
|
||||
auto top = TRY(top_value.to_double(vm));
|
||||
|
||||
left = JS::Value(left).is_finite_number() ? left : 0.0;
|
||||
top = JS::Value(top).is_finite_number() ? top : 0.0;
|
||||
|
@ -653,7 +654,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
|
|||
top = top + current_scroll_position.y();
|
||||
|
||||
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));
|
||||
auto behavior_string = behavior_string_value.is_undefined() ? "auto" : TRY(behavior_string_value.to_string(vm));
|
||||
if (behavior_string != "smooth" && behavior_string != "auto")
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'");
|
||||
ScrollBehavior behavior = (behavior_string == "smooth") ? ScrollBehavior::Smooth : ScrollBehavior::Auto;
|
||||
|
@ -698,7 +699,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_y_getter)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::post_message)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
auto target_origin = TRY(vm.argument(1).to_string(global_object));
|
||||
auto target_origin = TRY(vm.argument(1).to_string(vm));
|
||||
impl->post_message(vm.argument(0), target_origin);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
@ -733,7 +734,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::name_getter)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::name_setter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
impl->set_name(TRY(vm.argument(0).to_string(global_object)));
|
||||
impl->set_name(TRY(vm.argument(0).to_string(vm)));
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> NodeIterator::filter(Node& node)
|
|||
{
|
||||
VERIFY(wrapper());
|
||||
auto& global_object = wrapper()->global_object();
|
||||
auto& vm = wrapper()->vm();
|
||||
|
||||
// 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException.
|
||||
if (m_active)
|
||||
|
@ -150,7 +151,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> NodeIterator::filter(Node& node)
|
|||
m_active = false;
|
||||
|
||||
// 8. Return result.
|
||||
auto result_value = TRY(result.value()->to_i32(global_object));
|
||||
auto result_value = TRY(result.value()->to_i32(vm));
|
||||
return static_cast<NodeFilter::Result>(result_value);
|
||||
}
|
||||
|
||||
|
|
|
@ -222,6 +222,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
|
|||
{
|
||||
VERIFY(wrapper());
|
||||
auto& global_object = wrapper()->global_object();
|
||||
auto& vm = wrapper()->vm();
|
||||
|
||||
// 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException.
|
||||
if (m_active)
|
||||
|
@ -253,7 +254,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
|
|||
m_active = false;
|
||||
|
||||
// 8. Return result.
|
||||
auto result_value = TRY(result.value()->to_i32(global_object));
|
||||
auto result_value = TRY(result.value()->to_i32(vm));
|
||||
return static_cast<NodeFilter::Result>(result_value);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(Fun
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* module_argument = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* module_argument = TRY(vm.argument(0).to_object(vm));
|
||||
if (!is<WebAssemblyModuleObject>(module_argument))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
|
||||
|
|
|
@ -19,7 +19,7 @@ void WebAssemblyInstancePrototype::initialize(JS::Realm& realm)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)
|
||||
{
|
||||
auto this_value = vm.this_value();
|
||||
auto* this_object = TRY(this_value.to_object(global_object));
|
||||
auto* this_object = TRY(this_value.to_object(vm));
|
||||
if (!is<WebAssemblyInstanceObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Instance");
|
||||
auto object = static_cast<WebAssemblyInstanceObject*>(this_object);
|
||||
|
|
|
@ -30,19 +30,19 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto descriptor = TRY(vm.argument(0).to_object(global_object));
|
||||
auto descriptor = TRY(vm.argument(0).to_object(vm));
|
||||
auto initial_value = TRY(descriptor->get("initial"));
|
||||
auto maximum_value = TRY(descriptor->get("maximum"));
|
||||
|
||||
if (!initial_value.is_number())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Number");
|
||||
|
||||
u32 initial = TRY(initial_value.to_u32(global_object));
|
||||
u32 initial = TRY(initial_value.to_u32(vm));
|
||||
|
||||
Optional<u32> maximum;
|
||||
|
||||
if (!maximum_value.is_undefined())
|
||||
maximum = TRY(maximum_value.to_u32(global_object));
|
||||
maximum = TRY(maximum_value.to_u32(vm));
|
||||
|
||||
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
|
||||
if (!address.has_value())
|
||||
|
|
|
@ -19,8 +19,8 @@ void WebAssemblyMemoryPrototype::initialize(JS::Realm& realm)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
||||
{
|
||||
auto page_count = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto page_count = TRY(vm.argument(0).to_u32(vm));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||
|
@ -40,7 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||
|
|
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyModuleConstructor::construct(Funct
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* buffer_object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* buffer_object = TRY(vm.argument(0).to_object(vm));
|
||||
auto result = TRY(parse_module(global_object, buffer_object));
|
||||
|
||||
return heap().allocate<WebAssemblyModuleObject>(realm, realm, result);
|
||||
|
|
|
@ -92,7 +92,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::validate)
|
|||
{
|
||||
// 1. Let stableBytes be a copy of the bytes held by the buffer bytes.
|
||||
// Note: There's no need to copy the bytes here as the buffer data cannot change while we're compiling the module.
|
||||
auto buffer = TRY(vm.argument(0).to_object(global_object));
|
||||
auto buffer = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 2. Compile stableBytes as a WebAssembly module and store the results as module.
|
||||
auto maybe_module = parse_module(global_object, buffer);
|
||||
|
@ -159,7 +159,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
|
|||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// FIXME: This shouldn't block!
|
||||
auto buffer_or_error = vm.argument(0).to_object(global_object);
|
||||
auto buffer_or_error = vm.argument(0).to_object(vm);
|
||||
JS::Value rejection_value;
|
||||
if (buffer_or_error.is_error())
|
||||
rejection_value = *buffer_or_error.throw_completion().value();
|
||||
|
@ -184,7 +184,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
HashMap<Wasm::Linker::Name, Wasm::ExternValue> resolved_imports;
|
||||
auto import_argument = vm.argument(1);
|
||||
if (!import_argument.is_undefined()) {
|
||||
auto* import_object = TRY(import_argument.to_object(global_object));
|
||||
auto* import_object = TRY(import_argument.to_object(vm));
|
||||
dbgln("Trying to resolve stuff because import object was specified");
|
||||
for (Wasm::Linker::Name const& import_name : linker.unresolved_imports()) {
|
||||
dbgln("Trying to resolve {}::{}", import_name.module, import_name.name);
|
||||
|
@ -192,7 +192,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
if (value_or_error.is_error())
|
||||
break;
|
||||
auto value = value_or_error.release_value();
|
||||
auto object_or_error = value.to_object(global_object);
|
||||
auto object_or_error = value.to_object(vm);
|
||||
if (object_or_error.is_error())
|
||||
break;
|
||||
auto* object = object_or_error.release_value();
|
||||
|
@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
|
|||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// FIXME: This shouldn't block!
|
||||
auto buffer_or_error = vm.argument(0).to_object(global_object);
|
||||
auto buffer_or_error = vm.argument(0).to_object(vm);
|
||||
auto promise = JS::Promise::create(realm);
|
||||
bool should_return_module = false;
|
||||
if (buffer_or_error.is_error()) {
|
||||
|
@ -398,7 +398,7 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::GlobalObject& global
|
|||
|
||||
switch (type.kind()) {
|
||||
case Wasm::ValueType::I64: {
|
||||
auto bigint = TRY(value.to_bigint(global_object));
|
||||
auto bigint = TRY(value.to_bigint(vm));
|
||||
auto value = bigint->big_integer().divided_by(two_64).remainder;
|
||||
VERIFY(value.unsigned_value().trimmed_length() <= 2);
|
||||
i64 integer = static_cast<i64>(value.unsigned_value().to_u64());
|
||||
|
@ -407,15 +407,15 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::GlobalObject& global
|
|||
return Wasm::Value { integer };
|
||||
}
|
||||
case Wasm::ValueType::I32: {
|
||||
auto _i32 = TRY(value.to_i32(global_object));
|
||||
auto _i32 = TRY(value.to_i32(vm));
|
||||
return Wasm::Value { static_cast<i32>(_i32) };
|
||||
}
|
||||
case Wasm::ValueType::F64: {
|
||||
auto number = TRY(value.to_double(global_object));
|
||||
auto number = TRY(value.to_double(vm));
|
||||
return Wasm::Value { static_cast<double>(number) };
|
||||
}
|
||||
case Wasm::ValueType::F32: {
|
||||
auto number = TRY(value.to_double(global_object));
|
||||
auto number = TRY(value.to_double(vm));
|
||||
return Wasm::Value { static_cast<float>(number) };
|
||||
}
|
||||
case Wasm::ValueType::FunctionReference:
|
||||
|
|
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto descriptor = TRY(vm.argument(0).to_object(global_object));
|
||||
auto descriptor = TRY(vm.argument(0).to_object(vm));
|
||||
auto element_value = TRY(descriptor->get("element"));
|
||||
if (!element_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidHint, element_value.to_string_without_side_effects());
|
||||
|
@ -50,12 +50,12 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
auto initial_value = TRY(descriptor->get("initial"));
|
||||
auto maximum_value = TRY(descriptor->get("maximum"));
|
||||
|
||||
auto initial = TRY(initial_value.to_u32(global_object));
|
||||
auto initial = TRY(initial_value.to_u32(vm));
|
||||
|
||||
Optional<u32> maximum;
|
||||
|
||||
if (!maximum_value.is_undefined())
|
||||
maximum = TRY(maximum_value.to_u32(global_object));
|
||||
maximum = TRY(maximum_value.to_u32(vm));
|
||||
|
||||
if (maximum.has_value() && maximum.value() < initial)
|
||||
return vm.throw_completion<JS::RangeError>("maximum should be larger than or equal to initial");
|
||||
|
|
|
@ -21,9 +21,9 @@ void WebAssemblyTablePrototype::initialize(JS::Realm& realm)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
|
||||
{
|
||||
auto delta = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto delta = TRY(vm.argument(0).to_u32(vm));
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
@ -51,9 +51,9 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
|
||||
{
|
||||
auto index = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto index = TRY(vm.argument(0).to_u32(vm));
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
@ -75,9 +75,9 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
|
||||
{
|
||||
auto index = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto index = TRY(vm.argument(0).to_u32(vm));
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
@ -105,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::length_getter)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
|
|
@ -100,7 +100,7 @@ JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attribute
|
|||
WebGLPowerPreference power_preference_value { WebGLPowerPreference::Default };
|
||||
|
||||
if (!power_preference.is_undefined()) {
|
||||
auto power_preference_string = TRY(power_preference.to_string(global_object));
|
||||
auto power_preference_string = TRY(power_preference.to_string(vm));
|
||||
|
||||
if (power_preference_string == "high-performance"sv)
|
||||
power_preference_value = WebGLPowerPreference::HighPerformance;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue