mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
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
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 12:19:41 +09:00
@@ -33,6 +33,8 @@ void JSONObject::initialize(GlobalObject& global_object)
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.stringify, stringify, 3, attr);
|
||||
define_native_function(vm.names.parse, parse, 2, attr);
|
||||
|
||||
// 25.5.3 JSON [ @@toStringTag ], https://tc39.es/ecma262/#sec-json-@@tostringtag
|
||||
define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "JSON"), Attribute::Configurable);
|
||||
}
|
||||
|
||||
@@ -117,6 +119,7 @@ String JSONObject::stringify_impl(GlobalObject& global_object, Value value, Valu
|
||||
return result;
|
||||
}
|
||||
|
||||
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
|
||||
JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
|
||||
{
|
||||
if (!vm.argument_count())
|
||||
@@ -376,6 +379,7 @@ String JSONObject::quote_json_string(String string)
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
// 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse
|
||||
JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
|
||||
{
|
||||
if (!vm.argument_count())
|
||||
|
||||
Reference in New Issue
Block a user