summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-10-29 17:04:01 -0400
committerIdan Horowitz <idan.horowitz@gmail.com>2021-10-31 07:50:30 +0200
commite92d14d4981d19ec9c2a5d3852b3ae5cfe0e1870 (patch)
tree0f19833c4e4020260e9f11687368e19c2f5e896e
parent875b5636641c65004e9799d0c55f56fc5d12a98b (diff)
downloadserenity-e92d14d4981d19ec9c2a5d3852b3ae5cfe0e1870.zip
LibJS: Convert GlobalObject to ThrowCompletionOr
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp80
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.h24
2 files changed, 52 insertions, 52 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index e7df4270dd..ae4ced6548 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -192,12 +192,12 @@ void GlobalObject::initialize_global_object()
#undef __JS_ENUMERATE
u8 attr = Attribute::Writable | Attribute::Configurable;
- define_old_native_function(vm.names.gc, gc, 0, attr);
- define_old_native_function(vm.names.isNaN, is_nan, 1, attr);
- define_old_native_function(vm.names.isFinite, is_finite, 1, attr);
- define_old_native_function(vm.names.parseFloat, parse_float, 1, attr);
- define_old_native_function(vm.names.parseInt, parse_int, 2, attr);
- define_old_native_function(vm.names.eval, eval, 1, attr);
+ define_native_function(vm.names.gc, gc, 0, attr);
+ define_native_function(vm.names.isNaN, is_nan, 1, attr);
+ define_native_function(vm.names.isFinite, is_finite, 1, attr);
+ define_native_function(vm.names.parseFloat, parse_float, 1, attr);
+ define_native_function(vm.names.parseInt, parse_int, 2, attr);
+ define_native_function(vm.names.eval, eval, 1, attr);
// 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
m_throw_type_error_function = NativeFunction::create(global_object(), {}, [](VM& vm, GlobalObject& global_object) {
@@ -211,12 +211,12 @@ void GlobalObject::initialize_global_object()
m_function_prototype->define_direct_accessor(vm.names.caller, m_throw_type_error_function, m_throw_type_error_function, Attribute::Configurable);
m_function_prototype->define_direct_accessor(vm.names.arguments, m_throw_type_error_function, m_throw_type_error_function, Attribute::Configurable);
- define_old_native_function(vm.names.encodeURI, encode_uri, 1, attr);
- define_old_native_function(vm.names.decodeURI, decode_uri, 1, attr);
- define_old_native_function(vm.names.encodeURIComponent, encode_uri_component, 1, attr);
- define_old_native_function(vm.names.decodeURIComponent, decode_uri_component, 1, attr);
- define_old_native_function(vm.names.escape, escape, 1, attr);
- define_old_native_function(vm.names.unescape, unescape, 1, attr);
+ define_native_function(vm.names.encodeURI, encode_uri, 1, attr);
+ define_native_function(vm.names.decodeURI, decode_uri, 1, attr);
+ define_native_function(vm.names.encodeURIComponent, encode_uri_component, 1, attr);
+ define_native_function(vm.names.decodeURIComponent, decode_uri_component, 1, attr);
+ define_native_function(vm.names.escape, escape, 1, attr);
+ define_native_function(vm.names.unescape, unescape, 1, attr);
define_direct_property(vm.names.NaN, js_nan(), 0);
define_direct_property(vm.names.Infinity, js_infinity(), 0);
@@ -328,7 +328,7 @@ void GlobalObject::set_associated_realm(Badge<Realm>, Realm& realm)
m_associated_realm = &realm;
}
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::gc)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::gc)
{
#ifdef __serenity__
dbgln("Forced garbage collection requested!");
@@ -338,23 +338,23 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::gc)
}
// 19.2.3 isNaN ( number ), https://tc39.es/ecma262/#sec-isnan-number
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::is_nan)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_nan)
{
- return Value(TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).is_nan());
+ return Value(TRY(vm.argument(0).to_number(global_object)).is_nan());
}
// 19.2.2 isFinite ( number ), https://tc39.es/ecma262/#sec-isfinite-number
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::is_finite)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_finite)
{
- return Value(TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).is_finite_number());
+ return Value(TRY(vm.argument(0).to_number(global_object)).is_finite_number());
}
// 19.2.4 parseFloat ( string ), https://tc39.es/ecma262/#sec-parsefloat-string
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::parse_float)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
{
if (vm.argument(0).is_number())
return vm.argument(0);
- auto input_string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
+ auto input_string = TRY(vm.argument(0).to_string(global_object));
auto trimmed_string = input_string.trim_whitespace(TrimMode::Left);
for (size_t length = trimmed_string.length(); length > 0; --length) {
auto number = MUST(Value(js_string(vm, trimmed_string.substring(0, length))).to_number(global_object));
@@ -365,9 +365,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::parse_float)
}
// 19.2.5 parseInt ( string, radix ), https://tc39.es/ecma262/#sec-parseint-string-radix
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::parse_int)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int)
{
- auto input_string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
+ auto input_string = TRY(vm.argument(0).to_string(global_object));
// FIXME: There's a bunch of unnecessary string copying here.
double sign = 1;
@@ -377,7 +377,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::parse_int)
if (!s.is_empty() && (s[0] == '+' || s[0] == '-'))
s = s.substring(1, s.length() - 1);
- auto radix = TRY_OR_DISCARD(vm.argument(1).to_i32(global_object));
+ auto radix = TRY(vm.argument(1).to_i32(global_object));
bool strip_prefix = true;
if (radix != 0) {
@@ -423,9 +423,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::parse_int)
}
// 19.2.1 eval ( x ), https://tc39.es/ecma262/#sec-eval-x
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::eval)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval)
{
- return TRY_OR_DISCARD(perform_eval(vm.argument(0), global_object, CallerMode::NonStrict, EvalMode::Indirect));
+ return perform_eval(vm.argument(0), global_object, CallerMode::NonStrict, EvalMode::Indirect);
}
// 19.2.6.1.1 Encode ( string, unescapedSet ), https://tc39.es/ecma262/#sec-encode
@@ -496,41 +496,41 @@ static ThrowCompletionOr<String> decode(JS::GlobalObject& global_object, const S
}
// 19.2.6.4 encodeURI ( uri ), https://tc39.es/ecma262/#sec-encodeuri-uri
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::encode_uri)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri)
{
- auto uri_string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
- auto encoded = TRY_OR_DISCARD(encode(global_object, uri_string, ";/?:@&=+$,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()#"sv));
+ auto uri_string = TRY(vm.argument(0).to_string(global_object));
+ auto encoded = TRY(encode(global_object, uri_string, ";/?:@&=+$,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()#"sv));
return js_string(vm, move(encoded));
}
// 19.2.6.2 decodeURI ( encodedURI ), https://tc39.es/ecma262/#sec-decodeuri-encodeduri
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::decode_uri)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri)
{
- auto uri_string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
- auto decoded = TRY_OR_DISCARD(decode(global_object, uri_string, ";/?:@&=+$,#"sv));
+ auto uri_string = TRY(vm.argument(0).to_string(global_object));
+ auto decoded = TRY(decode(global_object, uri_string, ";/?:@&=+$,#"sv));
return js_string(vm, move(decoded));
}
// 19.2.6.5 encodeURIComponent ( uriComponent ), https://tc39.es/ecma262/#sec-encodeuricomponent-uricomponent
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
{
- auto uri_string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
- auto encoded = TRY_OR_DISCARD(encode(global_object, uri_string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"sv));
+ auto uri_string = TRY(vm.argument(0).to_string(global_object));
+ auto encoded = TRY(encode(global_object, uri_string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"sv));
return js_string(vm, move(encoded));
}
// 19.2.6.3 decodeURIComponent ( encodedURIComponent ), https://tc39.es/ecma262/#sec-decodeuricomponent-encodeduricomponent
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
{
- auto uri_string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
- auto decoded = TRY_OR_DISCARD(decode(global_object, uri_string, ""sv));
+ auto uri_string = TRY(vm.argument(0).to_string(global_object));
+ auto decoded = TRY(decode(global_object, uri_string, ""sv));
return js_string(vm, move(decoded));
}
// B.2.1.1 escape ( string ), https://tc39.es/ecma262/#sec-escape-string
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::escape)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::escape)
{
- auto string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
+ auto string = TRY(vm.argument(0).to_string(global_object));
StringBuilder escaped;
for (auto code_point : Utf8View(string)) {
if (code_point < 256) {
@@ -546,9 +546,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::escape)
}
// B.2.1.2 unescape ( string ), https://tc39.es/ecma262/#sec-unescape-string
-JS_DEFINE_OLD_NATIVE_FUNCTION(GlobalObject::unescape)
+JS_DEFINE_NATIVE_FUNCTION(GlobalObject::unescape)
{
- auto string = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
+ auto string = TRY(vm.argument(0).to_string(global_object));
ssize_t length = string.length();
StringBuilder unescaped(length);
for (auto k = 0; k < length; ++k) {
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h
index eb6d2b3bad..f2da91e32c 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h
@@ -76,18 +76,18 @@ protected:
private:
virtual bool is_global_object() const final { return true; }
- JS_DECLARE_OLD_NATIVE_FUNCTION(gc);
- JS_DECLARE_OLD_NATIVE_FUNCTION(is_nan);
- JS_DECLARE_OLD_NATIVE_FUNCTION(is_finite);
- JS_DECLARE_OLD_NATIVE_FUNCTION(parse_float);
- JS_DECLARE_OLD_NATIVE_FUNCTION(parse_int);
- JS_DECLARE_OLD_NATIVE_FUNCTION(eval);
- JS_DECLARE_OLD_NATIVE_FUNCTION(encode_uri);
- JS_DECLARE_OLD_NATIVE_FUNCTION(decode_uri);
- JS_DECLARE_OLD_NATIVE_FUNCTION(encode_uri_component);
- JS_DECLARE_OLD_NATIVE_FUNCTION(decode_uri_component);
- JS_DECLARE_OLD_NATIVE_FUNCTION(escape);
- JS_DECLARE_OLD_NATIVE_FUNCTION(unescape);
+ JS_DECLARE_NATIVE_FUNCTION(gc);
+ JS_DECLARE_NATIVE_FUNCTION(is_nan);
+ JS_DECLARE_NATIVE_FUNCTION(is_finite);
+ JS_DECLARE_NATIVE_FUNCTION(parse_float);
+ JS_DECLARE_NATIVE_FUNCTION(parse_int);
+ JS_DECLARE_NATIVE_FUNCTION(eval);
+ JS_DECLARE_NATIVE_FUNCTION(encode_uri);
+ JS_DECLARE_NATIVE_FUNCTION(decode_uri);
+ JS_DECLARE_NATIVE_FUNCTION(encode_uri_component);
+ JS_DECLARE_NATIVE_FUNCTION(decode_uri_component);
+ JS_DECLARE_NATIVE_FUNCTION(escape);
+ JS_DECLARE_NATIVE_FUNCTION(unescape);
NonnullOwnPtr<Console> m_console;