summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-06-13 00:22:35 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-13 00:33:28 +0100
commit7327a28ccc5d5d17f2f24da02b93f43ce92e2d31 (patch)
tree3ecb66481aa7cf756bfb345d242b22dee1f9d641 /Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
parent322c8a3995e3fab7c77b78b60348337e24a2d9e2 (diff)
downloadserenity-7327a28ccc5d5d17f2f24da02b93f43ce92e2d31.zip
LibJS: Add ECMA-262 section/title/URL comments almost everywhere
As mentioned on Discord earlier, we'll add these to all new functions going forward - this is the backfill. Reasons: - It makes you look at the spec, implementing based on MDN or V8 behavior is a no-go - It makes finding the various functions that are non-compliant easier, in the future everything should either have such a comment or, if it's not from the spec at all, a comment explaining why that is the case - It makes it easier to check whether a certain abstract operation is implemented in LibJS, not all of them use the same name as the spec. E.g. RejectPromise() is Promise::reject() - It makes it easier to reason about vm.arguments(), e.g. when the function has a rest parameter - It makes it easier to see whether a certain function is from a proposal or Annex B Also: - Add arguments to all functions and abstract operations that already had a comment - Fix some outdated section numbers - Replace some ecma-international.org URLs with tc39.es
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/GlobalObject.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index 08fe603084..7761f171e3 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -210,6 +210,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::gc)
return js_undefined();
}
+// 19.2.3 isNaN ( number ), https://tc39.es/ecma262/#sec-isnan-number
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_nan)
{
auto number = vm.argument(0).to_number(global_object);
@@ -218,6 +219,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_nan)
return Value(number.is_nan());
}
+// 19.2.2 isFinite ( number ), https://tc39.es/ecma262/#sec-isfinite-number
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_finite)
{
auto number = vm.argument(0).to_number(global_object);
@@ -226,6 +228,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_finite)
return Value(number.is_finite_number());
}
+// 19.2.4 parseFloat ( string ), https://tc39.es/ecma262/#sec-parsefloat-string
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
{
if (vm.argument(0).is_number())
@@ -243,9 +246,9 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
return js_nan();
}
+// 19.2.5 parseInt ( string, radix ), https://tc39.es/ecma262/#sec-parseint-string-radix
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int)
{
- // 18.2.5 parseInt ( string, radix )
auto input_string = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
@@ -333,6 +336,7 @@ Value GlobalObject::get_this_binding(GlobalObject&) const
return Value(this);
}
+// 19.2.1 eval ( x ), https://tc39.es/ecma262/#sec-eval-x
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval)
{
if (!vm.argument(0).is_string())
@@ -354,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval)
return interpreter.execute_statement(global_object, program).value_or(js_undefined());
}
-// 19.2.6.1.1 Encode ( string, unescapedSet )
+// 19.2.6.1.1 Encode ( string, unescapedSet ), https://tc39.es/ecma262/#sec-encode
static String encode([[maybe_unused]] JS::GlobalObject& global_object, const String& string, StringView unescaped_set)
{
StringBuilder encoded_builder;
@@ -369,7 +373,7 @@ static String encode([[maybe_unused]] JS::GlobalObject& global_object, const Str
return encoded_builder.build();
}
-// 19.2.6.1.2 Decode ( string, reservedSet )
+// 19.2.6.1.2 Decode ( string, reservedSet ), https://tc39.es/ecma262/#sec-decode
static String decode(JS::GlobalObject& global_object, const String& string, StringView reserved_set)
{
StringBuilder decoded_builder;
@@ -423,6 +427,7 @@ static String decode(JS::GlobalObject& global_object, const String& string, Stri
return decoded_builder.build();
}
+// 19.2.6.4 encodeURI ( uri ), https://tc39.es/ecma262/#sec-encodeuri-uri
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri)
{
auto uri_string = vm.argument(0).to_string(global_object);
@@ -434,6 +439,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri)
return js_string(vm, move(encoded));
}
+// 19.2.6.2 decodeURI ( encodedURI ), https://tc39.es/ecma262/#sec-decodeuri-encodeduri
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri)
{
auto uri_string = vm.argument(0).to_string(global_object);
@@ -445,6 +451,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri)
return js_string(vm, move(decoded));
}
+// 19.2.6.5 encodeURIComponent ( uriComponent ), https://tc39.es/ecma262/#sec-encodeuricomponent-uricomponent
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
{
auto uri_string = vm.argument(0).to_string(global_object);
@@ -456,6 +463,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
return js_string(vm, move(encoded));
}
+// 19.2.6.3 decodeURIComponent ( encodedURIComponent ), https://tc39.es/ecma262/#sec-decodeuricomponent-encodeduricomponent
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
{
auto uri_string = vm.argument(0).to_string(global_object);
@@ -467,6 +475,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
return js_string(vm, move(decoded));
}
+// B.2.1.1 escape ( string ), https://tc39.es/ecma262/#sec-escape-string
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::escape)
{
auto string = vm.argument(0).to_string(global_object);
@@ -486,6 +495,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::escape)
return js_string(vm, escaped.build());
}
+// B.2.1.2 unescape ( string ), https://tc39.es/ecma262/#sec-unescape-string
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::unescape)
{
auto string = vm.argument(0).to_string(global_object);