mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:57:35 +00:00
LibJS: Make native function/property callbacks take VM, not Interpreter
More work on decoupling the general runtime from Interpreter. The goal is becoming clearer. Interpreter should be one possible way to execute code inside a VM. In the future we might have other ways :^)
This commit is contained in:
parent
1ff9d33131
commit
340a115dfe
64 changed files with 1160 additions and 1114 deletions
|
@ -62,14 +62,14 @@ LocationObject::~LocationObject()
|
|||
JS_DEFINE_NATIVE_GETTER(LocationObject::href_getter)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
return JS::js_string(interpreter, window.impl().document().url().to_string());
|
||||
return JS::js_string(vm, window.impl().document().url().to_string());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_SETTER(LocationObject::href_setter)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto new_href = value.to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
auto new_href = value.to_string(global_object);
|
||||
if (vm.exception())
|
||||
return;
|
||||
window.impl().did_set_location_href({}, new_href);
|
||||
}
|
||||
|
@ -77,13 +77,13 @@ JS_DEFINE_NATIVE_SETTER(LocationObject::href_setter)
|
|||
JS_DEFINE_NATIVE_GETTER(LocationObject::pathname_getter)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
return JS::js_string(interpreter, window.impl().document().url().path());
|
||||
return JS::js_string(vm, window.impl().document().url().path());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(LocationObject::hostname_getter)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
return JS::js_string(interpreter, window.impl().document().url().host());
|
||||
return JS::js_string(vm, window.impl().document().url().host());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(LocationObject::host_getter)
|
||||
|
@ -94,7 +94,7 @@ JS_DEFINE_NATIVE_GETTER(LocationObject::host_getter)
|
|||
builder.append(url.host());
|
||||
builder.append(':');
|
||||
builder.appendf("%u", url.port());
|
||||
return JS::js_string(interpreter, builder.to_string());
|
||||
return JS::js_string(vm, builder.to_string());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(LocationObject::hash_getter)
|
||||
|
@ -102,11 +102,11 @@ JS_DEFINE_NATIVE_GETTER(LocationObject::hash_getter)
|
|||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto fragment = window.impl().document().url().fragment();
|
||||
if (!fragment.length())
|
||||
return JS::js_string(interpreter, "");
|
||||
return JS::js_string(vm, "");
|
||||
StringBuilder builder;
|
||||
builder.append('#');
|
||||
builder.append(fragment);
|
||||
return JS::js_string(interpreter, builder.to_string());
|
||||
return JS::js_string(vm, builder.to_string());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(LocationObject::search_getter)
|
||||
|
@ -114,11 +114,11 @@ JS_DEFINE_NATIVE_GETTER(LocationObject::search_getter)
|
|||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto query = window.impl().document().url().query();
|
||||
if (!query.length())
|
||||
return JS::js_string(interpreter, "");
|
||||
return JS::js_string(vm, "");
|
||||
StringBuilder builder;
|
||||
builder.append('?');
|
||||
builder.append(query);
|
||||
return JS::js_string(interpreter, builder.to_string());
|
||||
return JS::js_string(vm, builder.to_string());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(LocationObject::protocol_getter)
|
||||
|
@ -127,7 +127,7 @@ JS_DEFINE_NATIVE_GETTER(LocationObject::protocol_getter)
|
|||
StringBuilder builder;
|
||||
builder.append(window.impl().document().url().protocol());
|
||||
builder.append(':');
|
||||
return JS::js_string(interpreter, builder.to_string());
|
||||
return JS::js_string(vm, builder.to_string());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
|
||||
|
|
|
@ -62,7 +62,7 @@ NavigatorObject::~NavigatorObject()
|
|||
|
||||
JS_DEFINE_NATIVE_GETTER(NavigatorObject::user_agent_getter)
|
||||
{
|
||||
return JS::js_string(interpreter, ResourceLoader::the().user_agent());
|
||||
return JS::js_string(vm, ResourceLoader::the().user_agent());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -99,15 +99,15 @@ Origin WindowObject::origin() const
|
|||
return impl().document().origin();
|
||||
}
|
||||
|
||||
static DOM::Window* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)
|
||||
static DOM::Window* impl_from(JS::VM& vm, JS::GlobalObject& global_object)
|
||||
{
|
||||
auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object) {
|
||||
ASSERT_NOT_REACHED();
|
||||
return nullptr;
|
||||
}
|
||||
if (StringView("WindowObject") != this_object->class_name()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "WindowObject");
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "WindowObject");
|
||||
return nullptr;
|
||||
}
|
||||
return &static_cast<WindowObject*>(this_object)->impl();
|
||||
|
@ -115,13 +115,13 @@ static DOM::Window* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& gl
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::alert)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
String message = "";
|
||||
if (interpreter.argument_count()) {
|
||||
message = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
if (vm.argument_count()) {
|
||||
message = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
impl->alert(message);
|
||||
|
@ -130,13 +130,13 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::alert)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::confirm)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
String message = "";
|
||||
if (interpreter.argument_count()) {
|
||||
message = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
if (vm.argument_count()) {
|
||||
message = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
return JS::Value(impl->confirm(message));
|
||||
|
@ -144,24 +144,24 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::confirm)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_interval)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "setInterval");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "setInterval");
|
||||
return {};
|
||||
}
|
||||
auto* callback_object = interpreter.argument(0).to_object(interpreter, global_object);
|
||||
auto* callback_object = vm.argument(0).to_object(global_object);
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
return {};
|
||||
}
|
||||
i32 interval = 0;
|
||||
if (interpreter.argument_count() >= 2) {
|
||||
interval = interpreter.argument(1).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
if (vm.argument_count() >= 2) {
|
||||
interval = vm.argument(1).to_i32(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (interval < 0)
|
||||
interval = 0;
|
||||
|
@ -173,24 +173,24 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_interval)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "setTimeout");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "setTimeout");
|
||||
return {};
|
||||
}
|
||||
auto* callback_object = interpreter.argument(0).to_object(interpreter, global_object);
|
||||
auto* callback_object = vm.argument(0).to_object(global_object);
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
return {};
|
||||
}
|
||||
i32 interval = 0;
|
||||
if (interpreter.argument_count() >= 2) {
|
||||
interval = interpreter.argument(1).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
if (vm.argument_count() >= 2) {
|
||||
interval = vm.argument(1).to_i32(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (interval < 0)
|
||||
interval = 0;
|
||||
|
@ -202,15 +202,15 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_timeout)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "clearTimeout");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "clearTimeout");
|
||||
return {};
|
||||
}
|
||||
i32 timer_id = interpreter.argument(0).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
i32 timer_id = vm.argument(0).to_i32(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->clear_timeout(timer_id);
|
||||
return JS::js_undefined();
|
||||
|
@ -218,15 +218,15 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_timeout)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_interval)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "clearInterval");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "clearInterval");
|
||||
return {};
|
||||
}
|
||||
i32 timer_id = interpreter.argument(0).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
i32 timer_id = vm.argument(0).to_i32(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->clear_timeout(timer_id);
|
||||
return JS::js_undefined();
|
||||
|
@ -234,18 +234,18 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_interval)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_animation_frame)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "requestAnimationFrame");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "requestAnimationFrame");
|
||||
return {};
|
||||
}
|
||||
auto* callback_object = interpreter.argument(0).to_object(interpreter, global_object);
|
||||
auto* callback_object = vm.argument(0).to_object(global_object);
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAFunctionNoParam);
|
||||
return {};
|
||||
}
|
||||
return JS::Value(impl->request_animation_frame(*static_cast<JS::Function*>(callback_object)));
|
||||
|
@ -253,15 +253,15 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_animation_frame)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_animation_frame)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "cancelAnimationFrame");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "cancelAnimationFrame");
|
||||
return {};
|
||||
}
|
||||
auto id = interpreter.argument(0).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
auto id = vm.argument(0).to_i32(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->cancel_animation_frame(id);
|
||||
return JS::js_undefined();
|
||||
|
@ -269,52 +269,52 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_animation_frame)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "atob");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "atob");
|
||||
return {};
|
||||
}
|
||||
auto string = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
auto string = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto decoded = decode_base64(StringView(string));
|
||||
|
||||
// decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
|
||||
return JS::js_string(interpreter, TextCodec::decoder_for("iso-8859-1")->to_utf8(decoded));
|
||||
return JS::js_string(vm, TextCodec::decoder_for("iso-8859-1")->to_utf8(decoded));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "btoa");
|
||||
if (!vm.argument_count()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "btoa");
|
||||
return {};
|
||||
}
|
||||
auto string = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
auto string = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
Vector<u8> byte_string;
|
||||
byte_string.ensure_capacity(string.length());
|
||||
for (u32 code_point : Utf8View(string)) {
|
||||
if (code_point > 0xff) {
|
||||
interpreter.vm().throw_exception<JS::InvalidCharacterError>(global_object, JS::ErrorType::NotAByteString, "btoa");
|
||||
vm.throw_exception<JS::InvalidCharacterError>(global_object, JS::ErrorType::NotAByteString, "btoa");
|
||||
return {};
|
||||
}
|
||||
byte_string.append(code_point);
|
||||
}
|
||||
|
||||
auto encoded = encode_base64(byte_string.span());
|
||||
return JS::js_string(interpreter, move(encoded));
|
||||
return JS::js_string(vm, move(encoded));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
return wrap(global_object, impl->document());
|
||||
|
|
|
@ -58,13 +58,13 @@ XMLHttpRequestPrototype::~XMLHttpRequestPrototype()
|
|||
{
|
||||
}
|
||||
|
||||
static XMLHttpRequest* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)
|
||||
static XMLHttpRequest* impl_from(JS::VM& vm, JS::GlobalObject& global_object)
|
||||
{
|
||||
auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return nullptr;
|
||||
if (StringView("XMLHttpRequestWrapper") != this_object->class_name()) {
|
||||
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "XMLHttpRequest");
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "XMLHttpRequest");
|
||||
return nullptr;
|
||||
}
|
||||
return &static_cast<XMLHttpRequestWrapper*>(this_object)->impl();
|
||||
|
@ -72,14 +72,14 @@ static XMLHttpRequest* impl_from(JS::Interpreter& interpreter, JS::GlobalObject&
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::open)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto arg0 = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
auto arg0 = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto arg1 = interpreter.argument(1).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
auto arg1 = vm.argument(1).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->open(arg0, arg1);
|
||||
return JS::js_undefined();
|
||||
|
@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::open)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::send)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
impl->send();
|
||||
|
@ -96,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::send)
|
|||
|
||||
JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::ready_state_getter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
return JS::Value((i32)impl->ready_state());
|
||||
|
@ -104,10 +104,10 @@ JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::ready_state_getter)
|
|||
|
||||
JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::response_text_getter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter, global_object);
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
return JS::js_string(interpreter, impl->response_text());
|
||||
return JS::js_string(vm, impl->response_text());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -500,13 +500,13 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
|
||||
// Implementation: impl_from()
|
||||
if (!interface.attributes.is_empty() || !interface.functions.is_empty()) {
|
||||
out() << "static " << interface.fully_qualified_name << "* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)";
|
||||
out() << "static " << interface.fully_qualified_name << "* impl_from(JS::VM& vm, JS::GlobalObject& global_object)";
|
||||
out() << "{";
|
||||
out() << " auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);";
|
||||
out() << " auto* this_object = vm.this_value(global_object).to_object(global_object);";
|
||||
out() << " if (!this_object)";
|
||||
out() << " return {};";
|
||||
out() << " if (!this_object->inherits(\"" << wrapper_class << "\")) {";
|
||||
out() << " interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, \"" << interface.fully_qualified_name << "\");";
|
||||
out() << " vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, \"" << interface.fully_qualified_name << "\");";
|
||||
out() << " return nullptr;";
|
||||
out() << " }";
|
||||
out() << " return &static_cast<" << wrapper_class << "*>(this_object)->impl();";
|
||||
|
@ -521,27 +521,27 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
out() << " return {};";
|
||||
};
|
||||
if (parameter.type.name == "DOMString") {
|
||||
out() << " auto " << cpp_name << " = " << js_name << js_suffix << ".to_string(interpreter);";
|
||||
out() << " if (interpreter.exception())";
|
||||
out() << " auto " << cpp_name << " = " << js_name << js_suffix << ".to_string(global_object);";
|
||||
out() << " if (vm.exception())";
|
||||
generate_return();
|
||||
} else if (parameter.type.name == "EventListener") {
|
||||
out() << " if (!" << js_name << js_suffix << ".is_function()) {";
|
||||
out() << " interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, \"Function\");";
|
||||
out() << " vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, \"Function\");";
|
||||
generate_return();
|
||||
out() << " }";
|
||||
out() << " auto " << cpp_name << " = adopt(*new EventListener(JS::make_handle(&" << js_name << js_suffix << ".as_function())));";
|
||||
} else if (is_wrappable_type(parameter.type)) {
|
||||
out() << " auto " << cpp_name << "_object = " << js_name << js_suffix << ".to_object(interpreter, global_object);";
|
||||
out() << " if (interpreter.exception())";
|
||||
out() << " auto " << cpp_name << "_object = " << js_name << js_suffix << ".to_object(global_object);";
|
||||
out() << " if (vm.exception())";
|
||||
generate_return();
|
||||
out() << " if (!" << cpp_name << "_object->inherits(\"" << parameter.type.name << "Wrapper\")) {";
|
||||
out() << " interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, \"" << parameter.type.name << "\");";
|
||||
out() << " vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, \"" << parameter.type.name << "\");";
|
||||
generate_return();
|
||||
out() << " }";
|
||||
out() << " auto& " << cpp_name << " = static_cast<" << parameter.type.name << "Wrapper*>(" << cpp_name << "_object)->impl();";
|
||||
} else if (parameter.type.name == "double") {
|
||||
out() << " auto " << cpp_name << " = " << js_name << js_suffix << ".to_double(interpreter);";
|
||||
out() << " if (interpreter.exception())";
|
||||
out() << " auto " << cpp_name << " = " << js_name << js_suffix << ".to_double(global_object);";
|
||||
out() << " if (vm.exception())";
|
||||
generate_return();
|
||||
} else if (parameter.type.name == "boolean") {
|
||||
out() << " auto " << cpp_name << " = " << js_name << js_suffix << ".to_boolean();";
|
||||
|
@ -556,7 +556,7 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
size_t argument_index = 0;
|
||||
for (auto& parameter : parameters) {
|
||||
parameter_names.append(snake_name(parameter.name));
|
||||
out() << " auto arg" << argument_index << " = interpreter.argument(" << argument_index << ");";
|
||||
out() << " auto arg" << argument_index << " = vm.argument(" << argument_index << ");";
|
||||
generate_to_cpp(parameter, "arg", argument_index, snake_name(parameter.name), return_void);
|
||||
++argument_index;
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
}
|
||||
|
||||
if (return_type.name == "DOMString") {
|
||||
out() << " return JS::js_string(interpreter, retval);";
|
||||
out() << " return JS::js_string(vm, retval);";
|
||||
} else if (return_type.name == "ArrayFromVector") {
|
||||
// FIXME: Remove this fake type hack once it's no longer needed.
|
||||
// Basically once we have NodeList we can throw this out.
|
||||
|
@ -604,7 +604,7 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
for (auto& attribute : interface.attributes) {
|
||||
out() << "JS_DEFINE_NATIVE_GETTER(" << wrapper_class << "::" << attribute.getter_callback_name << ")";
|
||||
out() << "{";
|
||||
out() << " auto* impl = impl_from(interpreter, global_object);";
|
||||
out() << " auto* impl = impl_from(vm, global_object);";
|
||||
out() << " if (!impl)";
|
||||
out() << " return {};";
|
||||
|
||||
|
@ -629,7 +629,7 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
if (!attribute.readonly) {
|
||||
out() << "JS_DEFINE_NATIVE_SETTER(" << wrapper_class << "::" << attribute.setter_callback_name << ")";
|
||||
out() << "{";
|
||||
out() << " auto* impl = impl_from(interpreter, global_object);";
|
||||
out() << " auto* impl = impl_from(vm, global_object);";
|
||||
out() << " if (!impl)";
|
||||
out() << " return;";
|
||||
|
||||
|
@ -652,15 +652,15 @@ void generate_implementation(const IDL::Interface& interface)
|
|||
for (auto& function : interface.functions) {
|
||||
out() << "JS_DEFINE_NATIVE_FUNCTION(" << wrapper_class << "::" << snake_name(function.name) << ")";
|
||||
out() << "{";
|
||||
out() << " auto* impl = impl_from(interpreter, global_object);";
|
||||
out() << " auto* impl = impl_from(vm, global_object);";
|
||||
out() << " if (!impl)";
|
||||
out() << " return {};";
|
||||
if (function.length() > 0) {
|
||||
out() << " if (interpreter.argument_count() < " << function.length() << ") {";
|
||||
out() << " if (vm.argument_count() < " << function.length() << ") {";
|
||||
if (function.length() == 1)
|
||||
out() << " interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, \"" << function.name << "\");";
|
||||
out() << " vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, \"" << function.name << "\");";
|
||||
else
|
||||
out() << " interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountMany, \"" << function.name << "\", \"" << function.length() << "\");";
|
||||
out() << " vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountMany, \"" << function.name << "\", \"" << function.length() << "\");";
|
||||
out() << " return {};";
|
||||
out() << " }";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue