diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-13 00:22:35 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-13 00:33:28 +0100 |
commit | 7327a28ccc5d5d17f2f24da02b93f43ce92e2d31 (patch) | |
tree | 3ecb66481aa7cf756bfb345d242b22dee1f9d641 /Userland/Libraries | |
parent | 322c8a3995e3fab7c77b78b60348337e24a2d9e2 (diff) | |
download | serenity-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')
52 files changed, 480 insertions, 101 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp index 233de0db29..3985d03ed4 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp @@ -22,16 +22,20 @@ void AggregateErrorConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 20.5.7.2.1 AggregateError.prototype, https://tc39.es/ecma262/#sec-aggregate-error.prototype define_property(vm.names.prototype, global_object.aggregate_error_prototype(), 0); + define_property(vm.names.length, Value(2), Attribute::Configurable); } +// 20.5.7.1.1 AggregateError ( errors, message ), https://tc39.es/ecma262/#sec-aggregate-error Value AggregateErrorConstructor::call() { return construct(*this); } -// 20.5.7.1 The AggregateError Constructor, https://tc39.es/ecma262/#sec-aggregate-error-constructor +// 20.5.7.1.1 AggregateError ( errors, message ), https://tc39.es/ecma262/#sec-aggregate-error Value AggregateErrorConstructor::construct(Function&) { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index d8ab3b4236..232a5a42e2 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -12,9 +12,10 @@ namespace JS { -// 10.4.2.2 ArrayCreate, https://tc39.es/ecma262/#sec-arraycreate +// 10.4.2.2 ArrayCreate ( length [ , proto ] ), https://tc39.es/ecma262/#sec-arraycreate Array* Array::create(GlobalObject& global_object, size_t length) { + // FIXME: Support proto parameter if (length > NumericLimits<u32>::max()) { auto& vm = global_object.vm(); vm.throw_exception<RangeError>(global_object, ErrorType::InvalidLength, "array"); @@ -25,12 +26,12 @@ Array* Array::create(GlobalObject& global_object, size_t length) return array; } -// 7.3.17 CreateArrayFromList, https://tc39.es/ecma262/#sec-createarrayfromlist -Array* Array::create_from(GlobalObject& global_object, const Vector<Value>& values) +// 7.3.17 CreateArrayFromList ( elements ), https://tc39.es/ecma262/#sec-createarrayfromlist +Array* Array::create_from(GlobalObject& global_object, const Vector<Value>& elements) { auto* array = Array::create(global_object); - for (size_t i = 0; i < values.size(); ++i) - array->define_property(i, values[i]); + for (size_t i = 0; i < elements.size(); ++i) + array->define_property(i, elements[i]); return array; } diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp index bedb89a2d0..2b28e49bd5 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp @@ -21,11 +21,16 @@ void ArrayBufferConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); - u8 attr = Attribute::Writable | Attribute::Configurable; + + // 25.1.4.2 ArrayBuffer.prototype, https://tc39.es/ecma262/#sec-arraybuffer.prototype define_property(vm.names.prototype, global_object.array_buffer_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); + + u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.isView, is_view, 1, attr); + // 25.1.5.4 ArrayBuffer.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-arraybuffer.prototype-@@tostringtag define_native_accessor(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); } @@ -33,6 +38,7 @@ ArrayBufferConstructor::~ArrayBufferConstructor() { } +// 25.1.3.1 ArrayBuffer ( length ), https://tc39.es/ecma262/#sec-arraybuffer-length Value ArrayBufferConstructor::call() { auto& vm = this->vm(); @@ -40,6 +46,7 @@ Value ArrayBufferConstructor::call() return {}; } +// 25.1.3.1 ArrayBuffer ( length ), https://tc39.es/ecma262/#sec-arraybuffer-length Value ArrayBufferConstructor::construct(Function&) { auto& vm = this->vm(); @@ -55,6 +62,7 @@ Value ArrayBufferConstructor::construct(Function&) return ArrayBuffer::create(global_object(), byte_length); } +// 25.1.4.1 ArrayBuffer.isView ( arg ), https://tc39.es/ecma262/#sec-arraybuffer.isview JS_DEFINE_NATIVE_FUNCTION(ArrayBufferConstructor::is_view) { auto arg = vm.argument(0); @@ -66,6 +74,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferConstructor::is_view) return Value(false); } +// 25.1.4.3 get ArrayBuffer [ @@species ], https://tc39.es/ecma262/#sec-get-arraybuffer-@@species JS_DEFINE_NATIVE_GETTER(ArrayBufferConstructor::symbol_species_getter) { return vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp index 5a039b65d4..b690d7fa95 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp @@ -27,6 +27,7 @@ void ArrayBufferPrototype::initialize(GlobalObject& global_object) // FIXME: This should be an accessor property define_native_property(vm.names.byteLength, byte_length_getter, {}, Attribute::Configurable); + // 25.1.5.4 ArrayBuffer.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-arraybuffer.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "ArrayBuffer"), Attribute::Configurable); } @@ -45,7 +46,7 @@ static ArrayBuffer* array_buffer_object_from(VM& vm, GlobalObject& global_object return static_cast<ArrayBuffer*>(&this_value.as_object()); } -// 25.1.5.3 ArrayBuffer.prototype.slice, https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice +// 25.1.5.3 ArrayBuffer.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice) { auto array_buffer_object = array_buffer_object_from(vm, global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index aa54b55f94..384d12776f 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -30,7 +30,9 @@ void ArrayConstructor::initialize(GlobalObject& global_object) auto& vm = this->vm(); NativeFunction::initialize(global_object); + // 23.1.2.4 Array.prototype, https://tc39.es/ecma262/#sec-array.prototype define_property(vm.names.prototype, global_object.array_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -38,9 +40,11 @@ void ArrayConstructor::initialize(GlobalObject& global_object) define_native_function(vm.names.isArray, is_array, 1, attr); define_native_function(vm.names.of, of, 0, attr); + // 23.1.2.5 get Array [ @@species ], https://tc39.es/ecma262/#sec-get-array-@@species define_native_accessor(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); } +// 23.1.1.1 Array ( ...values ), https://tc39.es/ecma262/#sec-array Value ArrayConstructor::call() { if (vm().argument_count() <= 0) @@ -63,11 +67,13 @@ Value ArrayConstructor::call() return array; } +// 23.1.1.1 Array ( ...values ), https://tc39.es/ecma262/#sec-array Value ArrayConstructor::construct(Function&) { return call(); } +// 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) { auto value = vm.argument(0); @@ -139,12 +145,14 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) return array; } +// 23.1.2.2 Array.isArray ( arg ), https://tc39.es/ecma262/#sec-array.isarray JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array) { auto value = vm.argument(0); return Value(value.is_array(global_object)); } +// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of) { auto* array = Array::create(global_object); @@ -153,6 +161,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of) return array; } +// 23.1.2.5 get Array [ @@species ], https://tc39.es/ecma262/#sec-get-array-@@species JS_DEFINE_NATIVE_GETTER(ArrayConstructor::symbol_species_getter) { return vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index eefa3ddcd3..9662b7557d 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -24,6 +24,8 @@ void ArrayIteratorPrototype::initialize(GlobalObject& global_object) Object::initialize(global_object); define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); + + // 23.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Array Iterator"), Attribute::Configurable); } @@ -31,6 +33,7 @@ ArrayIteratorPrototype::~ArrayIteratorPrototype() { } +// 23.1.5.2.1 %ArrayIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) { auto this_value = vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index d547b64fc4..630bf86d25 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -67,6 +67,7 @@ void ArrayPrototype::initialize(GlobalObject& global_object) // Use define_property here instead of define_native_function so that // Object.is(Array.prototype[Symbol.iterator], Array.prototype.values) // evaluates to true + // 23.1.3.33 Array.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-array.prototype-@@iterator define_property(vm.well_known_symbol_iterator(), get(vm.names.values), attr); } @@ -124,6 +125,7 @@ static void for_each_item(VM& vm, GlobalObject& global_object, const String& nam } } +// 23.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.filter JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter) { auto* new_array = Array::create(global_object); @@ -135,6 +137,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter) return Value(new_array); } +// 23.1.3.12 Array.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.foreach JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each) { for_each_item(vm, global_object, "forEach", [](auto, auto, auto) { @@ -143,6 +146,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each) return js_undefined(); } +// 23.1.3.18 Array.prototype.map ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.map JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -163,6 +167,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map) return Value(new_array); } +// 23.1.3.20 Array.prototype.push ( ...items ), https://tc39.es/ecma262/#sec-array.prototype.push JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -195,6 +200,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push) return new_length_value; } +// 23.1.3.31 Array.prototype.unshift ( ...items ), https://tc39.es/ecma262/#sec-array.prototype.unshift JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift) { auto* array = Array::typed_this(vm, global_object); @@ -205,6 +211,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift) return Value(static_cast<i32>(array->indexed_properties().array_like_size())); } +// 23.1.3.19 Array.prototype.pop ( ), https://tc39.es/ecma262/#sec-array.prototype.pop JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -236,6 +243,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop) return element; } +// 23.1.3.24 Array.prototype.shift ( ), https://tc39.es/ecma262/#sec-array.prototype.shift JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift) { auto* array = Array::typed_this(vm, global_object); @@ -249,6 +257,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift) return result.value.value_or(js_undefined()); } +// 23.1.3.30 Array.prototype.toString ( ), https://tc39.es/ecma262/#sec-array.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -262,6 +271,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) return vm.call(join_function.as_function(), this_object); } +// 23.1.3.29 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-array.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -303,6 +313,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) return js_string(vm, builder.to_string()); } +// 23.1.3.15 Array.prototype.join ( separator ), https://tc39.es/ecma262/#sec-array.prototype.join JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -346,6 +357,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) return js_string(vm, builder.to_string()); } +// 23.1.3.1 Array.prototype.concat ( ...items ), https://tc39.es/ecma262/#sec-array.prototype.concat JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat) { auto* array = Array::typed_this(vm, global_object); @@ -372,6 +384,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat) return Value(new_array); } +// 23.1.3.25 Array.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-array.prototype.slice JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice) { auto* array = Array::typed_this(vm, global_object); @@ -417,6 +430,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice) return new_array; } +// 23.1.3.14 Array.prototype.indexOf ( searchElement [ , fromIndex ] ), https://tc39.es/ecma262/#sec-array.prototype.indexof JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -448,6 +462,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of) return Value(-1); } +// 23.1.3.21 Array.prototype.reduce ( callbackfn [ , initialValue ] ), https://tc39.es/ecma262/#sec-array.prototype.reduce JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -501,6 +516,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce) return accumulator; } +// 23.1.3.22 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ), https://tc39.es/ecma262/#sec-array.prototype.reduceright JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -554,6 +570,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right) return accumulator; } +// 23.1.3.23 Array.prototype.reverse ( ), https://tc39.es/ecma262/#sec-array.prototype.reverse JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse) { auto* array = Array::typed_this(vm, global_object); @@ -685,6 +702,7 @@ static void array_merge_sort(VM& vm, GlobalObject& global_object, Function* comp } } +// 23.1.3.27 Array.prototype.sort ( comparefn ), https://tc39.es/ecma262/#sec-array.prototype.sort JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort) { auto* array = vm.this_value(global_object).to_object(global_object); @@ -739,6 +757,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort) return array; } +// 23.1.3.17 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ), https://tc39.es/ecma262/#sec-array.prototype.lastindexof JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -770,6 +789,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of) return Value(-1); } +// 23.1.3.13 Array.prototype.includes ( searchElement [ , fromIndex ] ), https://tc39.es/ecma262/#sec-array.prototype.includes JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::includes) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -801,6 +821,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::includes) return Value(false); } +// 23.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.find JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find) { auto result = js_undefined(); @@ -816,6 +837,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find) return result; } +// 23.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.findindex JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index) { auto result_index = -1; @@ -831,6 +853,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index) return Value(result_index); } +// 23.1.3.26 Array.prototype.some ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.some JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some) { auto result = false; @@ -844,6 +867,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some) return Value(result); } +// 23.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.every JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every) { auto result = true; @@ -857,7 +881,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every) return Value(result); } -// 23.1.3.28 Array.prototype.splice, https://tc39.es/ecma262#sec-array.prototype.splice +// 23.1.3.28 Array.prototype.splice ( start, deleteCount, ...items ), https://tc39.es/ecma262#sec-array.prototype.splice JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -979,6 +1003,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) return removed_elements; } +// 23.1.3.6 Array.prototype.fill ( value [ , start [ , end ] ] ), https://tc39.es/ecma262/#sec-array.prototype.fill JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -1025,6 +1050,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill) return this_object; } +// 23.1.3.32 Array.prototype.values ( ), https://tc39.es/ecma262/#sec-array.prototype.values JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -1069,6 +1095,7 @@ static void recursive_array_flat(VM& vm, GlobalObject& global_object, Array& new } } +// 23.1.3.10 Array.prototype.flat ( [ depth ] ), https://tc39.es/ecma262/#sec-array.prototype.flat JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -1094,6 +1121,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat) return new_array; } +// 1.1 Array.prototype.at ( index ), https://tc39.es/proposal-relative-indexing-method/#sec-array.prototype.at JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::at) { auto* this_object = vm.this_value(global_object).to_object(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp index 49e2da55fb..b475092a48 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp @@ -23,7 +23,10 @@ void BigIntConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 21.2.2.3 BigInt.prototype, https://tc39.es/ecma262/#sec-bigint.prototype define_property(vm.names.prototype, global_object.bigint_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); // TODO: Implement these functions below and uncomment this. @@ -36,6 +39,7 @@ BigIntConstructor::~BigIntConstructor() { } +// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value Value BigIntConstructor::call() { auto primitive = vm().argument(0).to_primitive(global_object(), Value::PreferredType::Number); @@ -54,17 +58,20 @@ Value BigIntConstructor::call() return bigint; } +// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value Value BigIntConstructor::construct(Function&) { vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "BigInt"); return {}; } +// 21.2.2.1 BigInt.asIntN ( bits, bigint ), https://tc39.es/ecma262/#sec-bigint.asintn JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_int_n) { TODO(); } +// 21.2.2.2 BigInt.asUintN ( bits, bigint ), https://tc39.es/ecma262/#sec-bigint.asuintn JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_uint_n) { TODO(); diff --git a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp index 74b7f592ef..1086c2bd51 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -26,6 +26,7 @@ void BigIntPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.toLocaleString, to_locale_string, 0, attr); define_native_function(vm.names.valueOf, value_of, 0, attr); + // 21.2.3.5 BigInt.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-bigint.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "BigInt"), Attribute::Configurable); } @@ -33,7 +34,7 @@ BigIntPrototype::~BigIntPrototype() { } -// thisBigIntValue, https://tc39.es/ecma262/#thisbigintvalue +// thisBigIntValue ( value ), https://tc39.es/ecma262/#thisbigintvalue static Value this_bigint_value(GlobalObject& global_object, Value value) { if (value.is_bigint()) @@ -45,6 +46,7 @@ static Value this_bigint_value(GlobalObject& global_object, Value value) return {}; } +// 21.2.3.3 BigInt.prototype.toString ( [ radix ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) { auto bigint_value = this_bigint_value(global_object, vm.this_value(global_object)); @@ -54,11 +56,13 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) return js_string(vm, bigint_value.as_bigint().big_integer().to_base10()); } +// 21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) { return to_string(vm, global_object); } +// 21.2.3.4 BigInt.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-bigint.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::value_of) { return this_bigint_value(global_object, vm.this_value(global_object)); diff --git a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp index 5269948555..c10fc476e3 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -28,6 +28,7 @@ BooleanPrototype::~BooleanPrototype() { } +// 20.3.3.2 Boolean.prototype.toString ( ), https://tc39.es/ecma262/#sec-boolean.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string) { auto this_value = vm.this_value(global_object); @@ -42,6 +43,7 @@ JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string) return js_string(vm, bool_value ? "true" : "false"); } +// 20.3.3.3 Boolean.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-boolean.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::value_of) { auto this_value = vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp index 7ce538163b..02e4f3ae0c 100644 --- a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -37,51 +37,61 @@ ConsoleObject::~ConsoleObject() { } +// 1.1.6. log(...data), https://console.spec.whatwg.org/#log JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log) { return global_object.console().log(); } +// 1.1.3. debug(...data), https://console.spec.whatwg.org/#debug JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug) { return global_object.console().debug(); } +// 1.1.5. info(...data), https://console.spec.whatwg.org/#info JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info) { return global_object.console().info(); } +// 1.1.9. warn(...data), https://console.spec.whatwg.org/#warn JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn) { return global_object.console().warn(); } +// 1.1.4. error(...data), https://console.spec.whatwg.org/#error JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error) { return global_object.console().error(); } +// 1.1.8. trace(...data), https://console.spec.whatwg.org/#trace JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace) { return global_object.console().trace(); } +// 1.2.1. count(label), https://console.spec.whatwg.org/#count JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count) { return global_object.console().count(); } +// 1.2.2. countReset(label), https://console.spec.whatwg.org/#countreset JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset) { return global_object.console().count_reset(); } +// 1.1.2. clear(), https://console.spec.whatwg.org/#clear JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear) { return global_object.console().clear(); } +// 1.1.1. assert(condition, ...data), https://console.spec.whatwg.org/#assert JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::assert_) { return global_object.console().assert_(); diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index b4b0330368..08f0f511ba 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -18,10 +18,11 @@ namespace JS { +// 21.4.3.2 Date.parse ( string ), https://tc39.es/ecma262/#sec-date.parse static Value parse_simplified_iso8601(const String& iso_8601) { // Date.parse() is allowed to accept many formats. We strictly only accept things matching - // http://www.ecma-international.org/ecma-262/#sec-date-time-string-format + // 21.4.1.15 Date Time String Format, https://tc39.es/ecma262/#sec-date-time-string-format GenericLexer lexer(iso_8601); auto lex_n_digits = [&](size_t n, int& out) { if (lexer.tell_remaining() < n) @@ -98,7 +99,7 @@ static Value parse_simplified_iso8601(const String& iso_8601) tm.tm_min = minutes == -1 ? 0 : minutes; tm.tm_sec = seconds == -1 ? 0 : seconds; - // http://www.ecma-international.org/ecma-262/#sec-date.parse: + // https://tc39.es/ecma262/#sec-date.parse: // "When the UTC offset representation is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time." time_t timestamp; if (timezone != -1 || hours == -1) @@ -127,7 +128,10 @@ void DateConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 21.4.3.3 Date.prototype, https://tc39.es/ecma262/#sec-date.prototype define_property(vm.names.prototype, global_object.date_prototype(), 0); + define_property(vm.names.length, Value(7), Attribute::Configurable); define_native_function(vm.names.now, now, 0, Attribute::Writable | Attribute::Configurable); @@ -139,11 +143,13 @@ DateConstructor::~DateConstructor() { } +// 21.4.2.1 Date ( ...values ), https://tc39.es/ecma262/#sec-date Value DateConstructor::call() { return js_string(heap(), Date::now(global_object())->string()); } +// 21.4.2.1 Date ( ...values ), https://tc39.es/ecma262/#sec-date Value DateConstructor::construct(Function&) { auto& vm = this->vm(); @@ -255,6 +261,7 @@ Value DateConstructor::construct(Function&) return date; } +// 21.4.3.1 Date.now ( ), https://tc39.es/ecma262/#sec-date.now JS_DEFINE_NATIVE_FUNCTION(DateConstructor::now) { struct timeval tv; @@ -262,6 +269,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::now) return Value(tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0); } +// 21.4.3.2 Date.parse ( string ), https://tc39.es/ecma262/#sec-date.parse JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse) { if (!vm.argument_count()) @@ -274,6 +282,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse) return parse_simplified_iso8601(iso_8601); } +// 21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ), https://tc39.es/ecma262/#sec-date.utc JS_DEFINE_NATIVE_FUNCTION(DateConstructor::utc) { auto arg_or = [&vm, &global_object](size_t i, i32 fallback) { return vm.argument_count() > i ? vm.argument(i).to_i32(global_object) : fallback; }; @@ -293,4 +302,5 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::utc) int milliseconds = arg_or(6, 0); return Value(1000.0 * timegm(&tm) + milliseconds); } + } diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 1fdeac5cdd..fb36c9e963 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -84,12 +84,13 @@ void DatePrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.toString, to_string, 0, attr); define_native_function(vm.names.toJSON, to_json, 1, attr); + // 21.4.4.45 Date.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive define_native_function(vm.well_known_symbol_to_primitive(), symbol_to_primitive, 1, Attribute::Configurable); // Aliases. define_native_function(vm.names.valueOf, get_time, 0, attr); - // https://tc39.es/ecma262/#sec-date.prototype.togmtstring + // B.2.4.3 Date.prototype.toGMTString ( ), https://tc39.es/ecma262/#sec-date.prototype.togmtstring // The function object that is the initial value of Date.prototype.toGMTString // is the same function object that is the initial value of Date.prototype.toUTCString. define_property(vm.names.toGMTString, get(vm.names.toUTCString), attr); @@ -99,6 +100,7 @@ DatePrototype::~DatePrototype() { } +// 21.4.4.2 Date.prototype.getDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getdate JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date) { auto* this_object = typed_this(vm, global_object); @@ -111,6 +113,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date) return Value(this_object->date()); } +// 21.4.4.20 Date.prototype.setDate ( date ), https://tc39.es/ecma262/#sec-date.prototype.setdate JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date) { auto* this_object = typed_this(vm, global_object); @@ -138,6 +141,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date) return Value(this_object->time()); } +// 21.4.4.3 Date.prototype.getDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getday JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day) { auto* this_object = typed_this(vm, global_object); @@ -150,6 +154,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day) return Value(this_object->day()); } +// 21.4.4.4 Date.prototype.getFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getfullyear JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year) { auto* this_object = typed_this(vm, global_object); @@ -162,6 +167,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year) return Value(this_object->year()); } +// 21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setfullyear JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year) { auto* this_object = typed_this(vm, global_object); @@ -210,6 +216,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year) return Value(this_object->time()); } +// B.2.4.1 Date.prototype.getYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getyear JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_year) { auto* this_object = typed_this(vm, global_object); @@ -222,6 +229,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_year) return Value(this_object->year() - 1900); } +// B.2.4.2 Date.prototype.setYear ( year ), https://tc39.es/ecma262/#sec-date.prototype.setyear JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year) { auto* this_object = typed_this(vm, global_object); @@ -252,6 +260,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year) return Value(this_object->time()); } +// 21.4.4.5 Date.prototype.getHours ( ), https://tc39.es/ecma262/#sec-date.prototype.gethours JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours) { auto* this_object = typed_this(vm, global_object); @@ -264,6 +273,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours) return Value(this_object->hours()); } +// 21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ), https://tc39.es/ecma262/#sec-date.prototype.sethours JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours) { auto* this_object = typed_this(vm, global_object); @@ -323,6 +333,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours) return Value(this_object->time()); } +// 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds) { auto* this_object = typed_this(vm, global_object); @@ -335,6 +346,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds) return Value(this_object->milliseconds()); } +// 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds) { auto* this_object = typed_this(vm, global_object); @@ -370,6 +382,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds) return Value(this_object->time()); } +// 21.4.4.7 Date.prototype.getMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getminutes JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes) { auto* this_object = typed_this(vm, global_object); @@ -382,6 +395,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes) return Value(this_object->minutes()); } +// 21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setminutes JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes) { auto* this_object = typed_this(vm, global_object); @@ -432,6 +446,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes) return Value(this_object->time()); } +// 21.4.4.8 Date.prototype.getMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getmonth JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month) { auto* this_object = typed_this(vm, global_object); @@ -444,6 +459,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month) return Value(this_object->month()); } +// 21.4.4.25 Date.prototype.setMonth ( month [ , date ] ), https://tc39.es/ecma262/#sec-date.prototype.setmonth JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month) { auto* this_object = typed_this(vm, global_object); @@ -482,6 +498,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month) return Value(this_object->time()); } +// 21.4.4.9 Date.prototype.getSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getseconds JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds) { auto* this_object = typed_this(vm, global_object); @@ -494,6 +511,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds) return Value(this_object->seconds()); } +// 21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] ), https://tc39.es/ecma262/#sec-date.prototype.setseconds JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds) { auto* this_object = typed_this(vm, global_object); @@ -535,6 +553,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds) return Value(this_object->time()); } +// 21.4.4.10 Date.prototype.getTime ( ), https://tc39.es/ecma262/#sec-date.prototype.gettime JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time) { auto* this_object = typed_this(vm, global_object); @@ -547,6 +566,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time) return Value(this_object->time()); } +// 21.4.4.27 Date.prototype.setTime ( time ), https://tc39.es/ecma262/#sec-date.prototype.settime JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time) { auto* this_object = typed_this(vm, global_object); @@ -575,6 +595,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time) return Value(this_object->time()); } +// 21.4.4.11 Date.prototype.getTimezoneOffset ( ), https://tc39.es/ecma262/#sec-date.prototype.gettimezoneoffset JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset) { auto* this_object = typed_this(vm, global_object); @@ -588,6 +609,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset) return Value(0); } +// 21.4.4.12 Date.prototype.getUTCDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcdate JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date) { auto* this_object = typed_this(vm, global_object); @@ -600,6 +622,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date) return Value(this_object->utc_date()); } +// 21.4.4.13 Date.prototype.getUTCDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcday JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_day) { auto* this_object = typed_this(vm, global_object); @@ -612,6 +635,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_day) return Value(this_object->utc_day()); } +// 21.4.4.14 Date.prototype.getUTCFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcfullyear JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_full_year) { auto* this_object = typed_this(vm, global_object); @@ -624,6 +648,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_full_year) return Value(this_object->utc_full_year()); } +// 21.4.4.15 Date.prototype.getUTCHours ( ), https://tc39.es/ecma262/#sec-date.prototype.getutchours JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_hours) { auto* this_object = typed_this(vm, global_object); @@ -636,6 +661,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_hours) return Value(this_object->utc_hours()); } +// 21.4.4.16 Date.prototype.getUTCMilliseconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmilliseconds JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds) { auto* this_object = typed_this(vm, global_object); @@ -648,6 +674,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds) return Value(this_object->utc_milliseconds()); } +// 21.4.4.18 Date.prototype.getUTCMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmonth JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_month) { auto* this_object = typed_this(vm, global_object); @@ -660,6 +687,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_month) return Value(this_object->utc_month()); } +// 21.4.4.17 Date.prototype.getUTCMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcminutes JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_minutes) { auto* this_object = typed_this(vm, global_object); @@ -672,6 +700,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_minutes) return Value(this_object->utc_minutes()); } +// 21.4.4.19 Date.prototype.getUTCSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcseconds JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_seconds) { auto* this_object = typed_this(vm, global_object); @@ -684,6 +713,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_seconds) return Value(this_object->utc_seconds()); } +// 21.4.4.35 Date.prototype.toDateString ( ), https://tc39.es/ecma262/#sec-date.prototype.todatestring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string) { auto* this_object = typed_this(vm, global_object); @@ -697,13 +727,14 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string) return js_string(vm, move(string)); } +// B.2.4.3 Date.prototype.toGMTString ( ), https://tc39.es/ecma262/#sec-date.prototype.togmtstring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string) { - // toGMTString is deprecated but kept for compatibility. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toGMTString + // NOTE: The toUTCString method is preferred. The toGMTString method is provided principally for compatibility with old code. return to_utc_string(vm, global_object); } +// 21.4.4.43 Date.prototype.toUTCString ( ), https://tc39.es/ecma262/#sec-date.prototype.toutcstring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string) { auto* this_object = typed_this(vm, global_object); @@ -718,6 +749,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string) return js_string(vm, move(string)); } +// 21.4.4.36 Date.prototype.toISOString ( ), https://tc39.es/ecma262/#sec-date.prototype.toisostring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string) { auto* this_object = typed_this(vm, global_object); @@ -733,6 +765,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string) return js_string(vm, move(string)); } +// 21.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaledatestring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string) { auto* this_object = typed_this(vm, global_object); @@ -747,6 +780,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string) return js_string(vm, move(string)); } +// 21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string) { auto* this_object = typed_this(vm, global_object); @@ -761,6 +795,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string) return js_string(vm, move(string)); } +// 21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaletimestring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string) { auto* this_object = typed_this(vm, global_object); @@ -775,6 +810,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string) return js_string(vm, move(string)); } +// 21.4.4.42 Date.prototype.toTimeString ( ), https://tc39.es/ecma262/#sec-date.prototype.totimestring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string) { auto* this_object = typed_this(vm, global_object); @@ -788,6 +824,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string) return js_string(vm, move(string)); } +// 21.4.4.41 Date.prototype.toString ( ), https://tc39.es/ecma262/#sec-date.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string) { auto* this_object = typed_this(vm, global_object); @@ -801,6 +838,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string) return js_string(vm, move(string)); } +// 21.4.4.37 Date.prototype.toJSON ( key ), https://tc39.es/ecma262/#sec-date.prototype.tojson JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -814,6 +852,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json) return this_object->invoke(vm.names.toISOString); } +// 21.4.4.45 Date.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive JS_DEFINE_NATIVE_FUNCTION(DatePrototype::symbol_to_primitive) { auto this_value = vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp index c12dca2d9d..a902cd5bf3 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -29,7 +29,7 @@ void ErrorPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.toString, to_string, 0, attr); } -// 20.5.3.4 Error.prototype.toString, https://tc39.es/ecma262/#sec-error.prototype.tostring +// 20.5.3.4 Error.prototype.toString ( ), https://tc39.es/ecma262/#sec-error.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string) { auto this_value = vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 77cad5c748..85c7b2e1fc 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -42,6 +42,7 @@ FunctionPrototype::~FunctionPrototype() { } +// 20.2.3.1 Function.prototype.apply ( thisArg, argArray ), https://tc39.es/ecma262/#sec-function.prototype.apply JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -62,6 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply) return vm.call(function, this_arg, move(arguments)); } +// 20.2.3.2 Function.prototype.bind ( thisArg, ...args ), https://tc39.es/ecma262/#sec-function.prototype.bind JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -83,6 +85,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind) return this_function.bind(bound_this_arg, move(arguments)); } +// 20.2.3.3 Function.prototype.call ( thisArg, ...args ), https://tc39.es/ecma262/#sec-function.prototype.call JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::call) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -102,6 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::call) return vm.call(function, this_arg, move(arguments)); } +// 20.2.3.5 Function.prototype.toString ( ), https://tc39.es/ecma262/#sec-function.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -154,6 +158,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) return js_string(vm, function_source); } +// 20.2.3.6 Function.prototype [ @@hasInstance ] ( V ), https://tc39.es/ecma262/#sec-function.prototype-@@hasinstance JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::symbol_has_instance) { auto* this_object = vm.this_value(global_object).to_object(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index 9422ed168c..8fb800bf39 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -29,6 +29,9 @@ GeneratorObject::GeneratorObject(GlobalObject& global_object) void GeneratorObject::initialize(GlobalObject& global_object) { + // FIXME: These should be on a separate Generator prototype object! + // https://tc39.es/ecma262/#sec-generator-objects + auto& vm = this->vm(); Object::initialize(global_object); define_native_function(vm.names.next, next); 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); diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 2087564dc1..92cba45ab2 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -10,6 +10,7 @@ namespace JS { +// 7.4.1 GetIterator ( obj [ , hint [ , method ] ] ), https://tc39.es/ecma262/#sec-getiterator Object* get_iterator(GlobalObject& global_object, Value value, IteratorHint hint, Value method) { auto& vm = global_object.vm(); @@ -37,6 +38,7 @@ Object* get_iterator(GlobalObject& global_object, Value value, IteratorHint hint return &iterator.as_object(); } +// 7.4.2 IteratorNext ( iteratorRecord [ , value ] ), https://tc39.es/ecma262/#sec-iteratornext Object* iterator_next(Object& iterator, Value value) { auto& vm = iterator.vm(); @@ -66,11 +68,13 @@ Object* iterator_next(Object& iterator, Value value) return &result.as_object(); } +// 7.4.6 IteratorClose ( iteratorRecord, completion ), https://tc39.es/ecma262/#sec-iteratorclose void iterator_close([[maybe_unused]] Object& iterator) { TODO(); } +// 7.4.10 IterableToList ( items [ , method ] ), https://tc39.es/ecma262/#sec-iterabletolist MarkedValueList iterable_to_list(GlobalObject& global_object, Value iterable, Value method) { auto& vm = global_object.vm(); @@ -86,6 +90,7 @@ MarkedValueList iterable_to_list(GlobalObject& global_object, Value iterable, Va return values; } +// 7.4.8 CreateIterResultObject ( value, done ), https://tc39.es/ecma262/#sec-createiterresultobject Value create_iterator_result_object(GlobalObject& global_object, Value value, bool done) { auto& vm = global_object.vm(); diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h index 53ec962f73..10e08bf96c 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h @@ -11,8 +11,7 @@ namespace JS { -// Common iterator operations defined in ECMA262 7.4 -// https://tc39.es/ecma262/#sec-operations-on-iterator-objects +// 7.4 Operations on Iterator Objects, https://tc39.es/ecma262/#sec-operations-on-iterator-objects enum class IteratorHint { Sync, diff --git a/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp index 4f3093809a..8f55186e51 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp @@ -25,6 +25,7 @@ IteratorPrototype::~IteratorPrototype() { } +// 27.1.2.1 %IteratorPrototype% [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator JS_DEFINE_NATIVE_FUNCTION(IteratorPrototype::symbol_iterator) { auto* this_object = vm.this_value(global_object).to_object(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index e10cb9c87e..4830176608 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -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()) diff --git a/Userland/Libraries/LibJS/Runtime/JobCallback.h b/Userland/Libraries/LibJS/Runtime/JobCallback.h index 72b4f37da1..5cd67b5ee2 100644 --- a/Userland/Libraries/LibJS/Runtime/JobCallback.h +++ b/Userland/Libraries/LibJS/Runtime/JobCallback.h @@ -11,18 +11,18 @@ namespace JS { -// 9.4.1 JobCallback Records, https://tc39.es/ecma262/#sec-jobcallback-records +// 9.5.1 JobCallback Records, https://tc39.es/ecma262/#sec-jobcallback-records struct JobCallback { Function* callback; }; -// 9.4.2 HostMakeJobCallback, https://tc39.es/ecma262/#sec-hostmakejobcallback +// 9.5.2 HostMakeJobCallback ( callback ), https://tc39.es/ecma262/#sec-hostmakejobcallback inline JobCallback make_job_callback(Function& callback) { return { &callback }; } -// 9.4.3 HostCallJobCallback, https://tc39.es/ecma262/#sec-hostcalljobcallback +// 9.5.3 HostCallJobCallback ( jobCallback, V, argumentsList ), https://tc39.es/ecma262/#sec-hostcalljobcallback template<typename... Args> [[nodiscard]] inline Value call_job_callback(VM& vm, JobCallback& job_callback, Value this_value, Args... args) { diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.cpp b/Userland/Libraries/LibJS/Runtime/MathObject.cpp index b44ba830dd..38849e58ae 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/MathObject.cpp @@ -60,6 +60,7 @@ void MathObject::initialize(GlobalObject& global_object) define_native_function(vm.names.cosh, cosh, 1, attr); define_native_function(vm.names.tanh, tanh, 1, attr); + // 21.3.1 Value Properties of the Math Object, https://tc39.es/ecma262/#sec-value-properties-of-the-math-object define_property(vm.names.E, Value(M_E), 0); define_property(vm.names.LN2, Value(M_LN2), 0); define_property(vm.names.LN10, Value(M_LN10), 0); @@ -69,6 +70,7 @@ void MathObject::initialize(GlobalObject& global_object) define_property(vm.names.SQRT1_2, Value(M_SQRT1_2), 0); define_property(vm.names.SQRT2, Value(M_SQRT2), 0); + // 21.3.1.9 Math [ @@toStringTag ], https://tc39.es/ecma262/#sec-math-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Math"), Attribute::Configurable); } @@ -76,6 +78,7 @@ MathObject::~MathObject() { } +// 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.abs JS_DEFINE_NATIVE_FUNCTION(MathObject::abs) { auto number = vm.argument(0).to_number(global_object); @@ -90,6 +93,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::abs) return Value(number.as_double() < 0 ? -number.as_double() : number.as_double()); } +// 21.3.2.27 Math.random ( ), https://tc39.es/ecma262/#sec-math.random JS_DEFINE_NATIVE_FUNCTION(MathObject::random) { #ifdef __serenity__ @@ -100,6 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::random) return Value(r); } +// 21.3.2.32 Math.sqrt ( x ), https://tc39.es/ecma262/#sec-math.sqrt JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt) { auto number = vm.argument(0).to_number(global_object); @@ -110,6 +115,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt) return Value(::sqrt(number.as_double())); } +// 21.3.2.16 Math.floor ( x ), https://tc39.es/ecma262/#sec-math.floor JS_DEFINE_NATIVE_FUNCTION(MathObject::floor) { auto number = vm.argument(0).to_number(global_object); @@ -120,6 +126,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::floor) return Value(::floor(number.as_double())); } +// 21.3.2.10 Math.ceil ( x ), https://tc39.es/ecma262/#sec-math.ceil JS_DEFINE_NATIVE_FUNCTION(MathObject::ceil) { auto number = vm.argument(0).to_number(global_object); @@ -133,6 +140,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::ceil) return Value(::ceil(number.as_double())); } +// 21.3.2.28 Math.round ( x ), https://tc39.es/ecma262/#sec-math.round JS_DEFINE_NATIVE_FUNCTION(MathObject::round) { auto number = vm.argument(0).to_number(global_object); @@ -152,6 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::round) return Value(intpart); } +// 21.3.2.24 Math.max ( ...args ), https://tc39.es/ecma262/#sec-math.max JS_DEFINE_NATIVE_FUNCTION(MathObject::max) { Vector<Value> coerced; @@ -172,6 +181,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::max) return highest; } +// 21.3.2.25 Math.min ( ...args ), https://tc39.es/ecma262/#sec-math.min JS_DEFINE_NATIVE_FUNCTION(MathObject::min) { Vector<Value> coerced; @@ -192,6 +202,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::min) return lowest; } +// 21.3.2.35 Math.trunc ( x ), https://tc39.es/ecma262/#sec-math.trunc JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc) { auto number = vm.argument(0).to_number(global_object); @@ -204,6 +215,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc) return MathObject::floor(vm, global_object); } +// 21.3.2.30 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin JS_DEFINE_NATIVE_FUNCTION(MathObject::sin) { auto number = vm.argument(0).to_number(global_object); @@ -214,6 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sin) return Value(::sin(number.as_double())); } +// 21.3.2.12 Math.cos ( x ), https://tc39.es/ecma262/#sec-math.cos JS_DEFINE_NATIVE_FUNCTION(MathObject::cos) { auto number = vm.argument(0).to_number(global_object); @@ -224,6 +237,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cos) return Value(::cos(number.as_double())); } +// 21.3.2.33 Math.tan ( x ), https://tc39.es/ecma262/#sec-math.tan JS_DEFINE_NATIVE_FUNCTION(MathObject::tan) { auto number = vm.argument(0).to_number(global_object); @@ -234,6 +248,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::tan) return Value(::tan(number.as_double())); } +// 21.3.2.26 Math.pow ( base, exponent ), https://tc39.es/ecma262/#sec-math.pow JS_DEFINE_NATIVE_FUNCTION(MathObject::pow) { auto base = vm.argument(0).to_number(global_object); @@ -291,6 +306,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::pow) return Value(::pow(base.as_double(), exponent.as_double())); } +// 21.3.2.14 Math.exp ( x ), https://tc39.es/ecma262/#sec-math.exp JS_DEFINE_NATIVE_FUNCTION(MathObject::exp) { auto number = vm.argument(0).to_number(global_object); @@ -301,6 +317,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::exp) return Value(::exp(number.as_double())); } +// 21.3.2.15 Math.expm1 ( x ), https://tc39.es/ecma262/#sec-math.expm1 JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1) { auto number = vm.argument(0).to_number(global_object); @@ -311,6 +328,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1) return Value(::expm1(number.as_double())); } +// 21.3.2.29 Math.sign ( x ), https://tc39.es/ecma262/#sec-math.sign JS_DEFINE_NATIVE_FUNCTION(MathObject::sign) { auto number = vm.argument(0).to_number(global_object); @@ -327,6 +345,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sign) return js_nan(); } +// 21.3.2.11 Math.clz32 ( x ), https://tc39.es/ecma262/#sec-math.clz32 JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32) { auto number = vm.argument(0).to_number(global_object); @@ -337,6 +356,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32) return Value(__builtin_clz((unsigned)number.as_double())); } +// 21.3.2.2 Math.acos ( x ), https://tc39.es/ecma262/#sec-math.acos JS_DEFINE_NATIVE_FUNCTION(MathObject::acos) { auto number = vm.argument(0).to_number(global_object); @@ -349,6 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acos) return Value(::acos(number.as_double())); } +// 21.3.2.3 Math.acosh ( x ), https://tc39.es/ecma262/#sec-math.acosh JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh) { auto number = vm.argument(0).to_number(global_object); @@ -359,6 +380,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh) return Value(::acosh(number.as_double())); } +// 21.3.2.4 Math.asin ( x ), https://tc39.es/ecma262/#sec-math.asin JS_DEFINE_NATIVE_FUNCTION(MathObject::asin) { auto number = vm.argument(0).to_number(global_object); @@ -369,6 +391,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::asin) return Value(::asin(number.as_double())); } +// 21.3.2.5 Math.asinh ( x ), https://tc39.es/ecma262/#sec-math.asinh JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh) { auto number = vm.argument(0).to_number(global_object); @@ -377,6 +400,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh) return Value(::asinh(number.as_double())); } +// 21.3.2.6 Math.atan ( x ), https://tc39.es/ecma262/#sec-math.atan JS_DEFINE_NATIVE_FUNCTION(MathObject::atan) { auto number = vm.argument(0).to_number(global_object); @@ -391,6 +415,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atan) return Value(::atan(number.as_double())); } +// 21.3.2.7 Math.atanh ( x ), https://tc39.es/ecma262/#sec-math.atanh JS_DEFINE_NATIVE_FUNCTION(MathObject::atanh) { auto number = vm.argument(0).to_number(global_object); @@ -401,6 +426,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atanh) return Value(::atanh(number.as_double())); } +// 21.3.2.21 Math.log1p ( x ), https://tc39.es/ecma262/#sec-math.log1p JS_DEFINE_NATIVE_FUNCTION(MathObject::log1p) { auto number = vm.argument(0).to_number(global_object); @@ -411,6 +437,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log1p) return Value(::log1p(number.as_double())); } +// 21.3.2.9 Math.cbrt ( x ), https://tc39.es/ecma262/#sec-math.cbrt JS_DEFINE_NATIVE_FUNCTION(MathObject::cbrt) { auto number = vm.argument(0).to_number(global_object); @@ -419,6 +446,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cbrt) return Value(::cbrt(number.as_double())); } +// 21.3.2.8 Math.atan2 ( y, x ), https://tc39.es/ecma262/#sec-math.atan2 JS_DEFINE_NATIVE_FUNCTION(MathObject::atan2) { auto constexpr three_quarters_pi = M_PI_4 + M_PI_2; @@ -481,6 +509,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atan2) return Value(::atan2(y.as_double(), x.as_double())); } +// 21.3.2.17 Math.fround ( x ), https://tc39.es/ecma262/#sec-math.fround JS_DEFINE_NATIVE_FUNCTION(MathObject::fround) { auto number = vm.argument(0).to_number(global_object); @@ -491,6 +520,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::fround) return Value((float)number.as_double()); } +// 21.3.2.18 Math.hypot ( ...args ), https://tc39.es/ecma262/#sec-math.hypot JS_DEFINE_NATIVE_FUNCTION(MathObject::hypot) { Vector<Value> coerced; @@ -522,6 +552,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::hypot) return Value(::sqrt(sum_of_squares)); } +// 21.3.2.19 Math.imul ( x, y ), https://tc39.es/ecma262/#sec-math.imul JS_DEFINE_NATIVE_FUNCTION(MathObject::imul) { auto a = vm.argument(0).to_u32(global_object); @@ -533,6 +564,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::imul) return Value(static_cast<i32>(a * b)); } +// 21.3.2.20 Math.log ( x ), https://tc39.es/ecma262/#sec-math.log JS_DEFINE_NATIVE_FUNCTION(MathObject::log) { auto number = vm.argument(0).to_number(global_object); @@ -543,6 +575,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log) return Value(::log(number.as_double())); } +// 21.3.2.23 Math.log2 ( x ), https://tc39.es/ecma262/#sec-math.log2 JS_DEFINE_NATIVE_FUNCTION(MathObject::log2) { auto number = vm.argument(0).to_number(global_object); @@ -553,6 +586,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log2) return Value(::log2(number.as_double())); } +// 21.3.2.22 Math.log10 ( x ), https://tc39.es/ecma262/#sec-math.log10 JS_DEFINE_NATIVE_FUNCTION(MathObject::log10) { auto number = vm.argument(0).to_number(global_object); @@ -563,6 +597,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log10) return Value(::log10(number.as_double())); } +// 21.3.2.31 Math.sinh ( x ), https://tc39.es/ecma262/#sec-math.sinh JS_DEFINE_NATIVE_FUNCTION(MathObject::sinh) { auto number = vm.argument(0).to_number(global_object); @@ -573,6 +608,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sinh) return Value(::sinh(number.as_double())); } +// 21.3.2.13 Math.cosh ( x ), https://tc39.es/ecma262/#sec-math.cosh JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh) { auto number = vm.argument(0).to_number(global_object); @@ -583,6 +619,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh) return Value(::cosh(number.as_double())); } +// 21.3.2.34 Math.tanh ( x ), https://tc39.es/ecma262/#sec-math.tanh JS_DEFINE_NATIVE_FUNCTION(MathObject::tanh) { auto number = vm.argument(0).to_number(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index 57d07fb555..14cd4d4e1f 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -31,14 +31,18 @@ void NumberConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 21.1.2.15 Number.prototype, https://tc39.es/ecma262/#sec-number.prototype + define_property(vm.names.prototype, global_object.number_prototype(), 0); + + define_property(vm.names.length, Value(1), Attribute::Configurable); + u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.isFinite, is_finite, 1, attr); define_native_function(vm.names.isInteger, is_integer, 1, attr); define_native_function(vm.names.isNaN, is_nan, 1, attr); define_native_function(vm.names.isSafeInteger, is_safe_integer, 1, attr); define_property(vm.names.parseFloat, global_object.get(vm.names.parseFloat)); - define_property(vm.names.prototype, global_object.number_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); define_property(vm.names.EPSILON, Value(EPSILON_VALUE), 0); define_property(vm.names.MAX_VALUE, Value(NumericLimits<double>::max()), 0); define_property(vm.names.MIN_VALUE, Value(NumericLimits<double>::min()), 0); @@ -53,6 +57,7 @@ NumberConstructor::~NumberConstructor() { } +// 21.1.1.1 Number ( value ), https://tc39.es/ecma262/#sec-number-constructor-number-value Value NumberConstructor::call() { if (!vm().argument_count()) @@ -60,6 +65,7 @@ Value NumberConstructor::call() return vm().argument(0).to_number(global_object()); } +// 21.1.1.1 Number ( value ), https://tc39.es/ecma262/#sec-number-constructor-number-value Value NumberConstructor::construct(Function&) { double number = 0; @@ -71,21 +77,25 @@ Value NumberConstructor::construct(Function&) return NumberObject::create(global_object(), number); } +// 21.1.2.2 Number.isFinite ( number ), https://tc39.es/ecma262/#sec-number.isfinite JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_finite) { return Value(vm.argument(0).is_finite_number()); } +// 21.1.2.3 Number.isInteger ( number ), https://tc39.es/ecma262/#sec-number.isinteger JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_integer) { return Value(vm.argument(0).is_integer()); } +// 21.1.2.4 Number.isNaN ( number ), https://tc39.es/ecma262/#sec-number.isnan JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_nan) { return Value(vm.argument(0).is_nan()); } +// 21.1.2.5 Number.isSafeInteger ( number ), https://tc39.es/ecma262/#sec-number.issafeinteger JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_safe_integer) { if (!vm.argument(0).is_number()) diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index fcf42d8721..c5304443fd 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -42,7 +42,7 @@ NumberPrototype::~NumberPrototype() { } -// thisNumberValue, https://tc39.es/ecma262/#thisnumbervalue +// thisNumberValue ( value ), https://tc39.es/ecma262/#thisnumbervalue static Value this_number_value(GlobalObject& global_object, Value value) { if (value.is_number()) @@ -54,6 +54,7 @@ static Value this_number_value(GlobalObject& global_object, Value value) return {}; } +// 21.1.3.6 Number.prototype.toString ( [ radix ] ), https://tc39.es/ecma262/#sec-number.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) { auto number_value = this_number_value(global_object, vm.this_value(global_object)); @@ -131,6 +132,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) return js_string(vm, String(characters.data(), characters.size())); } +// 21.1.3.7 Number.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-number.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::value_of) { return this_number_value(global_object, vm.this_value(global_object)); diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index d9867e51c5..f84ef98ded 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -111,7 +111,7 @@ const Object* Object::prototype() const return shape().prototype(); } -// 10.1.2.1 OrdinarySetPrototypeOf, https://tc39.es/ecma262/#sec-ordinarysetprototypeof +// 10.1.2.1 OrdinarySetPrototypeOf ( O, V ), https://tc39.es/ecma262/#sec-ordinarysetprototypeof bool Object::set_prototype(Object* new_prototype) { if (prototype() == new_prototype) @@ -157,7 +157,7 @@ bool Object::prevent_extensions() return true; } -// 7.3.15 SetIntegrityLevel, https://tc39.es/ecma262/#sec-setintegritylevel +// 7.3.15 SetIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-setintegritylevel bool Object::set_integrity_level(IntegrityLevel level) { // FIXME: This feels clunky and should get nicer abstractions. @@ -225,7 +225,7 @@ bool Object::set_integrity_level(IntegrityLevel level) return true; } -// 7.3.16 TestIntegrityLevel, https://tc39.es/ecma262/#sec-testintegritylevel +// 7.3.16 TestIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-testintegritylevel bool Object::test_integrity_level(IntegrityLevel level) { auto& vm = this->vm(); @@ -369,7 +369,7 @@ MarkedValueList Object::get_own_properties(PropertyKind kind, bool only_enumerab return properties; } -// 7.3.23 EnumerableOwnPropertyNames, https://tc39.es/ecma262/#sec-enumerableownpropertynames +// 7.3.23 EnumerableOwnPropertyNames ( O, kind ), https://tc39.es/ecma262/#sec-enumerableownpropertynames MarkedValueList Object::get_enumerable_own_property_names(PropertyKind kind) const { return get_own_properties(kind, true, Object::GetOwnPropertyReturnType::StringOnly); @@ -419,7 +419,7 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN } // Equivalent to: -// 6.2.5.4 FromPropertyDescriptor, https://tc39.es/ecma262/#sec-frompropertydescriptor +// 6.2.5.4 FromPropertyDescriptor ( Desc ), https://tc39.es/ecma262/#sec-frompropertydescriptor Value Object::get_own_property_descriptor_object(const PropertyName& property_name) const { VERIFY(property_name.is_valid()); @@ -934,7 +934,7 @@ bool Object::define_native_property(const StringOrSymbol& property_name, AK::Fun return define_property(property_name, heap().allocate_without_global_object<NativeProperty>(move(getter), move(setter)), attribute); } -// 20.1.2.3.1 ObjectDefineProperties, https://tc39.es/ecma262/#sec-objectdefineproperties +// 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties void Object::define_properties(Value properties) { auto& vm = this->vm(); @@ -1051,7 +1051,7 @@ Value Object::ordinary_to_primitive(Value::PreferredType preferred_type) const return {}; } -// 20.5.8.1 InstallErrorCause, https://tc39.es/proposal-error-cause/#sec-errorobjects-install-error-cause +// 20.5.8.1 InstallErrorCause ( O, options ), https://tc39.es/proposal-error-cause/#sec-errorobjects-install-error-cause void Object::install_error_cause(Value options) { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 489335fa28..54982e4bd7 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -24,7 +24,10 @@ void ObjectConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 20.1.2.19 Object.prototype, https://tc39.es/ecma262/#sec-object.prototype define_property(vm.names.prototype, global_object.object_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -54,6 +57,7 @@ ObjectConstructor::~ObjectConstructor() { } +// 20.1.1.1 Object ( [ value ] ), https://tc39.es/ecma262/#sec-object-value Value ObjectConstructor::call() { auto value = vm().argument(0); @@ -62,11 +66,13 @@ Value ObjectConstructor::call() return value.to_object(global_object()); } +// 20.1.1.1 Object ( [ value ] ), https://tc39.es/ecma262/#sec-object-value Value ObjectConstructor::construct(Function&) { return call(); } +// 20.1.2.10 Object.getOwnPropertyNames ( O ), https://tc39.es/ecma262/#sec-object.getownpropertynames JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) { auto* object = vm.argument(0).to_object(global_object); @@ -75,6 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) return Array::create_from(global_object, object->get_own_properties(PropertyKind::Key, false, GetOwnPropertyReturnType::StringOnly)); } +// 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols) { auto* object = vm.argument(0).to_object(global_object); @@ -83,6 +90,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols) return Array::create_from(global_object, object->get_own_properties(PropertyKind::Key, false, GetOwnPropertyReturnType::SymbolOnly)); } +// 20.1.2.12 Object.getPrototypeOf ( O ), https://tc39.es/ecma262/#sec-object.getprototypeof JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of) { auto* object = vm.argument(0).to_object(global_object); @@ -91,6 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of) return object->prototype(); } +// 20.1.2.21 Object.setPrototypeOf ( O, proto ), https://tc39.es/ecma262/#sec-object.setprototypeof JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) { auto* object = vm.argument(0).to_object(global_object); @@ -114,6 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) return object; } +// 20.1.2.14 Object.isExtensible ( O ), https://tc39.es/ecma262/#sec-object.isextensible JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible) { auto argument = vm.argument(0); @@ -122,7 +132,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible) return Value(argument.as_object().is_extensible()); } -// 20.1.2.15 Object.isFrozen, https://tc39.es/ecma262/#sec-object.isfrozen +// 20.1.2.15 Object.isFrozen ( O ), https://tc39.es/ecma262/#sec-object.isfrozen JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_frozen) { auto argument = vm.argument(0); @@ -131,7 +141,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_frozen) return Value(argument.as_object().test_integrity_level(Object::IntegrityLevel::Frozen)); } -// 20.1.2.16 Object.isSealed, https://tc39.es/ecma262/#sec-object.issealed +// 20.1.2.16 Object.isSealed ( O ), https://tc39.es/ecma262/#sec-object.issealed JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_sealed) { auto argument = vm.argument(0); @@ -140,6 +150,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_sealed) return Value(argument.as_object().test_integrity_level(Object::IntegrityLevel::Sealed)); } +// 20.1.2.18 Object.preventExtensions ( O ), https://tc39.es/ecma262/#sec-object.preventextensions JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions) { auto argument = vm.argument(0); @@ -155,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions) return argument; } -// 20.1.2.6 Object.freeze, https://tc39.es/ecma262/#sec-object.freeze +// 20.1.2.6 Object.freeze ( O ), https://tc39.es/ecma262/#sec-object.freeze JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::freeze) { auto argument = vm.argument(0); @@ -171,7 +182,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::freeze) return argument; } -// 20.1.2.20 Object.seal, https://tc39.es/ecma262/#sec-object.seal +// 20.1.2.20 Object.seal ( O ), https://tc39.es/ecma262/#sec-object.seal JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::seal) { auto argument = vm.argument(0); @@ -187,6 +198,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::seal) return argument; } +// 20.1.2.8 Object.getOwnPropertyDescriptor ( O, P ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptor JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) { auto* object = vm.argument(0).to_object(global_object); @@ -198,6 +210,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) return object->get_own_property_descriptor_object(property_key); } +// 20.1.2.4 Object.defineProperty ( O, P, Attributes ), https://tc39.es/ecma262/#sec-object.defineproperty JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property_) { if (!vm.argument(0).is_object()) { @@ -226,7 +239,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property_) return &object; } -// 20.1.2.3 Object.defineProperties, https://tc39.es/ecma262/#sec-object.defineproperties +// 20.1.2.3 Object.defineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-object.defineproperties JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_properties) { if (!vm.argument(0).is_object()) { @@ -241,11 +254,13 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_properties) return &object; } +// 20.1.2.13 Object.is ( value1, value2 ), https://tc39.es/ecma262/#sec-object.is JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is) { return Value(same_value(vm.argument(0), vm.argument(1))); } +// 20.1.2.17 Object.keys ( O ), https://tc39.es/ecma262/#sec-object.keys JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) { auto* obj_arg = vm.argument(0).to_object(global_object); @@ -255,6 +270,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) return Array::create_from(global_object, obj_arg->get_enumerable_own_property_names(PropertyKind::Key)); } +// 20.1.2.22 Object.values ( O ), https://tc39.es/ecma262/#sec-object.values JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) { auto* obj_arg = vm.argument(0).to_object(global_object); @@ -264,6 +280,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) return Array::create_from(global_object, obj_arg->get_enumerable_own_property_names(PropertyKind::Value)); } +// 20.1.2.5 Object.entries ( O ), https://tc39.es/ecma262/#sec-object.entries JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) { auto* obj_arg = vm.argument(0).to_object(global_object); @@ -273,7 +290,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) return Array::create_from(global_object, obj_arg->get_enumerable_own_property_names(PropertyKind::KeyAndValue)); } -// 20.1.2.2 Object.create, https://tc39.es/ecma262/#sec-object.create +// 20.1.2.2 Object.create ( O, Properties ), https://tc39.es/ecma262/#sec-object.create JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create) { auto prototype_value = vm.argument(0); @@ -300,6 +317,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create) return object; } +// 1 Object.hasOwn ( O, P ), https://tc39.es/proposal-accessible-object-hasownproperty/#sec-object.hasown JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own) { auto* object = vm.argument(0).to_object(global_object); @@ -311,7 +329,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own) return Value(object->has_own_property(property_key)); } -// 20.1.2.1 Object.assign, https://tc39.es/ecma262/#sec-object.assign +// 20.1.2.1 Object.assign ( target, ...sources ), https://tc39.es/ecma262/#sec-object.assign JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::assign) { auto* to = vm.argument(0).to_object(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp index 1bb29d459e..df88e1bbb1 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -41,6 +41,7 @@ ObjectPrototype::~ObjectPrototype() { } +// 20.1.3.2 Object.prototype.hasOwnProperty ( V ), https://tc39.es/ecma262/#sec-object.prototype.hasownproperty JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property) { auto property_key = vm.argument(0).to_property_key(global_object); @@ -52,6 +53,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property) return Value(this_object->has_own_property(property_key)); } +// 20.1.3.6 Object.prototype.toString ( ), https://tc39.es/ecma262/#sec-object.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string) { auto this_value = vm.this_value(global_object); @@ -93,6 +95,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string) return js_string(vm, String::formatted("[object {}]", tag)); } +// 20.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-object.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -101,6 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string) return this_object->invoke(vm.names.toString); } +// 20.1.3.7 Object.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-object.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::value_of) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -109,6 +113,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::value_of) return this_object->value_of(); } +// 20.1.3.4 Object.prototype.propertyIsEnumerable ( V ), https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::property_is_enumerable) { auto property_key = vm.argument(0).to_property_key(global_object); @@ -123,6 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::property_is_enumerable) return Value(property_descriptor.value().attributes.is_enumerable()); } +// 20.1.3.3 Object.prototype.isPrototypeOf ( V ), https://tc39.es/ecma262/#sec-object.prototype.isprototypeof JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::is_prototype_of) { auto object_argument = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index f3c76cb043..ed5be2ed35 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -17,7 +17,7 @@ namespace JS { -// 27.2.4.7.1 PromiseResolve, https://tc39.es/ecma262/#sec-promise-resolve +// 27.2.4.7.1 PromiseResolve ( C, x ), https://tc39.es/ecma262/#sec-promise-resolve Object* promise_resolve(GlobalObject& global_object, Object& constructor, Value value) { auto& vm = global_object.vm(); @@ -47,7 +47,7 @@ Promise::Promise(Object& prototype) { } -// 27.2.1.3 CreateResolvingFunctions, https://tc39.es/ecma262/#sec-createresolvingfunctions +// 27.2.1.3 CreateResolvingFunctions ( promise ), https://tc39.es/ecma262/#sec-createresolvingfunctions Promise::ResolvingFunctions Promise::create_resolving_functions() { dbgln_if(PROMISE_DEBUG, "[Promise @ {} / create_resolving_functions()]", this); @@ -107,7 +107,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() return { *resolve_function, *reject_function }; } -// 27.2.1.4 FulfillPromise, https://tc39.es/ecma262/#sec-fulfillpromise +// 27.2.1.4 FulfillPromise ( promise, value ), https://tc39.es/ecma262/#sec-fulfillpromise Value Promise::fulfill(Value value) { dbgln_if(PROMISE_DEBUG, "[Promise @ {} / fulfill()]: Fulfilling promise with value {}", this, value); @@ -121,7 +121,7 @@ Value Promise::fulfill(Value value) return js_undefined(); } -// 27.2.1.7 RejectPromise, https://tc39.es/ecma262/#sec-rejectpromise +// 27.2.1.7 RejectPromise ( promise, reason ), https://tc39.es/ecma262/#sec-rejectpromise Value Promise::reject(Value reason) { dbgln_if(PROMISE_DEBUG, "[Promise @ {} / reject()]: Rejecting promise with reason {}", this, reason); @@ -138,7 +138,7 @@ Value Promise::reject(Value reason) return js_undefined(); } -// 27.2.1.8 TriggerPromiseReactions, https://tc39.es/ecma262/#sec-triggerpromisereactions +// 27.2.1.8 TriggerPromiseReactions ( reactions, argument ), https://tc39.es/ecma262/#sec-triggerpromisereactions void Promise::trigger_reactions() const { VERIFY(is_settled()); @@ -158,7 +158,7 @@ void Promise::trigger_reactions() const } } -// 27.2.5.4.1 PerformPromiseThen, https://tc39.es/ecma262/#sec-performpromisethen +// 27.2.5.4.1 PerformPromiseThen ( promise, onFulfilled, onRejected [ , resultCapability ] ), https://tc39.es/ecma262/#sec-performpromisethen Value Promise::perform_then(Value on_fulfilled, Value on_rejected, Optional<PromiseCapability> result_capability) { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index fb637981e9..1c619bcb24 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -24,7 +24,9 @@ void PromiseConstructor::initialize(GlobalObject& global_object) auto& vm = this->vm(); NativeFunction::initialize(global_object); + // 27.2.4.4 Promise.prototype, https://tc39.es/ecma262/#sec-promise.prototype define_property(vm.names.prototype, global_object.promise_prototype(), 0); + define_property(vm.names.length, Value(1)); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -39,6 +41,7 @@ void PromiseConstructor::initialize(GlobalObject& global_object) define_native_accessor(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); } +// 27.2.3.1 Promise ( executor ), https://tc39.es/ecma262/#sec-promise-executor Value PromiseConstructor::call() { auto& vm = this->vm(); @@ -46,7 +49,7 @@ Value PromiseConstructor::call() return {}; } -// 27.2.3.1 Promise, https://tc39.es/ecma262/#sec-promise-executor +// 27.2.3.1 Promise ( executor ), https://tc39.es/ecma262/#sec-promise-executor Value PromiseConstructor::construct(Function&) { auto& vm = this->vm(); @@ -67,31 +70,31 @@ Value PromiseConstructor::construct(Function&) return promise; } -// 27.2.4.1 Promise.all, https://tc39.es/ecma262/#sec-promise.all +// 27.2.4.1 Promise.all ( iterable ), https://tc39.es/ecma262/#sec-promise.all JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all) { TODO(); } -// 27.2.4.2 Promise.allSettled, https://tc39.es/ecma262/#sec-promise.allsettled +// 27.2.4.2 Promise.allSettled ( iterable ), https://tc39.es/ecma262/#sec-promise.allsettled JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all_settled) { TODO(); } -// 27.2.4.3 Promise.any, https://tc39.es/ecma262/#sec-promise.any +// 27.2.4.3 Promise.any ( iterable ), https://tc39.es/ecma262/#sec-promise.any JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::any) { TODO(); } -// 27.2.4.5 Promise.race, https://tc39.es/ecma262/#sec-promise.race +// 27.2.4.5 Promise.race ( iterable ), https://tc39.es/ecma262/#sec-promise.race JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::race) { TODO(); } -// 27.2.4.6 Promise.reject, https://tc39.es/ecma262/#sec-promise.reject +// 27.2.4.6 Promise.reject ( r ), https://tc39.es/ecma262/#sec-promise.reject JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::reject) { auto* constructor = vm.this_value(global_object).to_object(global_object); @@ -105,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::reject) return promise_capability.promise; } -// 27.2.4.7 Promise.resolve, https://tc39.es/ecma262/#sec-promise.resolve +// 27.2.4.7 Promise.resolve ( x ), https://tc39.es/ecma262/#sec-promise.resolve JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::resolve) { auto* constructor = vm.this_value(global_object).to_object(global_object); @@ -115,6 +118,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::resolve) return promise_resolve(global_object, *constructor, value); } +// 27.2.4.8 get Promise [ @@species ], https://tc39.es/ecma262/#sec-get-promise-@@species JS_DEFINE_NATIVE_GETTER(PromiseConstructor::symbol_species_getter) { return vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp b/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp index f7986f3530..4aef8c5753 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp @@ -25,7 +25,7 @@ PromiseReactionJob::PromiseReactionJob(PromiseReaction& reaction, Value argument { } -// 27.2.2.1 NewPromiseReactionJob, https://tc39.es/ecma262/#sec-newpromisereactionjob +// 27.2.2.1 NewPromiseReactionJob ( reaction, argument ), https://tc39.es/ecma262/#sec-newpromisereactionjob Value PromiseReactionJob::call() { auto& vm = this->vm(); @@ -91,7 +91,7 @@ PromiseResolveThenableJob::PromiseResolveThenableJob(Promise& promise_to_resolve { } -// 27.2.2.2 NewPromiseResolveThenableJob, https://tc39.es/ecma262/#sec-newpromiseresolvethenablejob +// 27.2.2.2 NewPromiseResolveThenableJob ( promiseToResolve, thenable, then ), https://tc39.es/ecma262/#sec-newpromiseresolvethenablejob Value PromiseResolveThenableJob::call() { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp index b1bddfed4c..a3024aa011 100644 --- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp @@ -29,6 +29,8 @@ void PromisePrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.then, then, 2, attr); define_native_function(vm.names.catch_, catch_, 1, attr); define_native_function(vm.names.finally, finally, 1, attr); + + // 27.2.5.5 Promise.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-promise.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Promise"), Attribute::Configurable); } @@ -44,7 +46,7 @@ static Promise* promise_from(VM& vm, GlobalObject& global_object) return static_cast<Promise*>(this_object); } -// 27.2.5.4 Promise.prototype.then, https://tc39.es/ecma262/#sec-promise.prototype.then +// 27.2.5.4 Promise.prototype.then ( onFulfilled, onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.then JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then) { auto* promise = promise_from(vm, global_object); @@ -61,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then) return promise->perform_then(on_fulfilled, on_rejected, result_capability); } -// 27.2.5.1 Promise.prototype.catch, https://tc39.es/ecma262/#sec-promise.prototype.catch +// 27.2.5.1 Promise.prototype.catch ( onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.catch JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_) { auto* this_object = vm.this_value(global_object).to_object(global_object); @@ -71,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_) return this_object->invoke(vm.names.then, js_undefined(), on_rejected); } -// 27.2.5.3 Promise.prototype.finally, https://tc39.es/ecma262/#sec-promise.prototype.finally +// 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) { auto* promise = vm.this_value(global_object).to_object(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp index 05e7593010..36f2efc64e 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp @@ -11,7 +11,7 @@ namespace JS { -// 27.2.1.5 NewPromiseCapability, https://tc39.es/ecma262/#sec-newpromisecapability +// 27.2.1.5 NewPromiseCapability ( C ), https://tc39.es/ecma262/#sec-newpromisecapability PromiseCapability new_promise_capability(GlobalObject& global_object, Value constructor) { auto& vm = global_object.vm(); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h index 70b0aefb6c..c960ba2d63 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h +++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h @@ -19,10 +19,10 @@ struct PromiseCapability { Function* reject; }; -// 27.2.1.5 NewPromiseCapability, https://tc39.es/ecma262/#sec-newpromisecapability +// 27.2.1.5 NewPromiseCapability ( C ), https://tc39.es/ecma262/#sec-newpromisecapability PromiseCapability new_promise_capability(GlobalObject& global_object, Value constructor); -// https://tc39.es/ecma262/#sec-promisereaction-records +// 27.2.1.2 PromiseReaction Records, https://tc39.es/ecma262/#sec-promisereaction-records class PromiseReaction final : public Cell { public: enum class Type { diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp index b02948d33d..2e14800e42 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -13,6 +13,7 @@ namespace JS { +// 10.5.14 ProxyCreate ( target, handler ), https://tc39.es/ecma262/#sec-proxycreate static ProxyObject* proxy_create(GlobalObject& global_object, Value target, Value handler) { auto& vm = global_object.vm(); @@ -45,6 +46,7 @@ ProxyConstructor::~ProxyConstructor() { } +// 28.2.1.1 Proxy ( target, handler ), https://tc39.es/ecma262/#sec-proxy-target-handler Value ProxyConstructor::call() { auto& vm = this->vm(); @@ -52,20 +54,21 @@ Value ProxyConstructor::call() return {}; } +// 28.2.1.1 Proxy ( target, handler ), https://tc39.es/ecma262/#sec-proxy-target-handler Value ProxyConstructor::construct(Function&) { auto& vm = this->vm(); return proxy_create(global_object(), vm.argument(0), vm.argument(1)); } -// 28.2.2.1 Proxy.revocable, https://tc39.es/ecma262/multipage/reflection.html#sec-proxy.revocable +// 28.2.2.1 Proxy.revocable ( target, handler ), https://tc39.es/ecma262/#sec-proxy.revocable JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable) { auto* proxy = proxy_create(global_object, vm.argument(0), vm.argument(1)); if (vm.exception()) return {}; - // 28.2.2.1.1 Proxy Revocation Functions, https://tc39.es/ecma262/multipage/reflection.html#sec-proxy-revocation-functions + // 28.2.2.1.1 Proxy Revocation Functions, https://tc39.es/ecma262/#sec-proxy-revocation-functions auto* revoker = NativeFunction::create(global_object, "", [proxy_handle = make_handle(proxy)](auto&, auto&) -> Value { auto& proxy = const_cast<ProxyObject&>(*proxy_handle.cell()); if (proxy.is_revoked()) diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index b61e99eea0..376848bcbb 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -59,6 +59,8 @@ void ReflectObject::initialize(GlobalObject& global_object) define_native_function(vm.names.preventExtensions, prevent_extensions, 1, attr); define_native_function(vm.names.set, set, 3, attr); define_native_function(vm.names.setPrototypeOf, set_prototype_of, 2, attr); + + // 28.1.14 Reflect [ @@toStringTag ], https://tc39.es/ecma262/#sec-reflect-@@tostringtag Object::define_property(vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Reflect"), Attribute::Configurable); } @@ -66,6 +68,7 @@ ReflectObject::~ReflectObject() { } +// 28.1.1 Reflect.apply ( target, thisArgument, argumentsList ), https://tc39.es/ecma262/#sec-reflect.apply JS_DEFINE_NATIVE_FUNCTION(ReflectObject::apply) { auto* target = get_target_function_from(global_object, "apply"); @@ -78,6 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::apply) return vm.call(*target, this_arg, move(arguments)); } +// 28.1.2 Reflect.construct ( target, argumentsList [ , newTarget ] ), https://tc39.es/ecma262/#sec-reflect.construct JS_DEFINE_NATIVE_FUNCTION(ReflectObject::construct) { auto* target = get_target_function_from(global_object, "construct"); @@ -99,6 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::construct) return vm.construct(*target, *new_target, move(arguments)); } +// 28.1.3 Reflect.defineProperty ( target, propertyKey, attributes ), https://tc39.es/ecma262/#sec-reflect.defineproperty JS_DEFINE_NATIVE_FUNCTION(ReflectObject::define_property) { auto* target = get_target_object_from(global_object, "defineProperty"); @@ -118,6 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::define_property) return Value(success); } +// 28.1.4 Reflect.deleteProperty ( target, propertyKey ), https://tc39.es/ecma262/#sec-reflect.deleteproperty JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property) { auto* target = get_target_object_from(global_object, "deleteProperty"); @@ -129,6 +135,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property) return Value(target->delete_property(property_key)); } +// 28.1.5 Reflect.get ( target, propertyKey [ , receiver ] ), https://tc39.es/ecma262/#sec-reflect.get JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get) { auto* target = get_target_object_from(global_object, "get"); @@ -143,6 +150,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get) return target->get(property_key, receiver).value_or(js_undefined()); } +// 28.1.6 Reflect.getOwnPropertyDescriptor ( target, propertyKey ), https://tc39.es/ecma262/#sec-reflect.getownpropertydescriptor JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor) { auto* target = get_target_object_from(global_object, "getOwnPropertyDescriptor"); @@ -154,6 +162,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor) return target->get_own_property_descriptor_object(property_key); } +// 28.1.7 Reflect.getPrototypeOf ( target ), https://tc39.es/ecma262/#sec-reflect.getprototypeof JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_prototype_of) { auto* target = get_target_object_from(global_object, "getPrototypeOf"); @@ -162,6 +171,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_prototype_of) return target->prototype(); } +// 28.1.8 Reflect.has ( target, propertyKey ), https://tc39.es/ecma262/#sec-reflect.has JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has) { auto* target = get_target_object_from(global_object, "has"); @@ -173,6 +183,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has) return Value(target->has_property(property_key)); } +// 28.1.9 Reflect.isExtensible ( target ), https://tc39.es/ecma262/#sec-reflect.isextensible JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible) { auto* target = get_target_object_from(global_object, "isExtensible"); @@ -181,6 +192,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible) return Value(target->is_extensible()); } +// 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys) { auto* target = get_target_object_from(global_object, "ownKeys"); @@ -189,6 +201,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys) return Array::create_from(global_object, target->get_own_properties(PropertyKind::Key)); } +// 28.1.11 Reflect.preventExtensions ( target ), https://tc39.es/ecma262/#sec-reflect.preventextensions JS_DEFINE_NATIVE_FUNCTION(ReflectObject::prevent_extensions) { auto* target = get_target_object_from(global_object, "preventExtensions"); @@ -197,6 +210,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::prevent_extensions) return Value(target->prevent_extensions()); } +// 28.1.12 Reflect.set ( target, propertyKey, V [ , receiver ] ), https://tc39.es/ecma262/#sec-reflect.set JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set) { auto* target = get_target_object_from(global_object, "set"); @@ -212,6 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set) return Value(target->put(property_key, value, receiver)); } +// 28.1.13 Reflect.setPrototypeOf ( target, proto ), https://tc39.es/ecma262/#sec-reflect.setprototypeof JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set_prototype_of) { auto* target = get_target_object_from(global_object, "setPrototypeOf"); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp index f2734ff8d6..608ad3950d 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp @@ -149,9 +149,9 @@ JS_DEFINE_NATIVE_SETTER(RegExpObject::set_last_index) regexp_object->regex().start_offset = index; } +// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value flags) { - // https://tc39.es/ecma262/#sec-regexpcreate String p; if (pattern.is_undefined()) { p = String::empty(); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index e22e06198c..363394bcd0 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -82,6 +82,12 @@ static String escape_regexp_pattern(const RegExpObject& regexp_object) return pattern; } +// 22.2.5.3 get RegExp.prototype.dotAll, https://tc39.es/ecma262/#sec-get-regexp.prototype.dotAll +// 22.2.5.5 get RegExp.prototype.global, https://tc39.es/ecma262/#sec-get-regexp.prototype.global +// 22.2.5.6 get RegExp.prototype.ignoreCase, https://tc39.es/ecma262/#sec-get-regexp.prototype.ignorecase +// 22.2.5.9 get RegExp.prototype.multiline, https://tc39.es/ecma262/#sec-get-regexp.prototype.multiline +// 22.2.5.14 get RegExp.prototype.sticky, https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky +// 22.2.5.17 get RegExp.prototype.unicode, https://tc39.es/ecma262/#sec-get-regexp.prototype.unicode #define __JS_ENUMERATE(flagName, flag_name, flag_char, ECMAScriptFlagName) \ JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flag_name) \ { \ @@ -94,6 +100,7 @@ static String escape_regexp_pattern(const RegExpObject& regexp_object) JS_ENUMERATE_REGEXP_FLAGS #undef __JS_ENUMERATE +// 22.2.5.4 get RegExp.prototype.flags, https://tc39.es/ecma262/#sec-get-regexp.prototype.flags JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flags) { auto this_object = this_object_from(vm, global_object); @@ -114,6 +121,7 @@ JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flags) return js_string(vm, builder.to_string()); } +// 22.2.5.12 get RegExp.prototype.source, https://tc39.es/ecma262/#sec-get-regexp.prototype.source JS_DEFINE_NATIVE_GETTER(RegExpPrototype::source) { auto this_object = this_object_from(vm, global_object); @@ -141,6 +149,7 @@ RegexResult RegExpPrototype::do_match(const Regex<ECMA262>& re, const StringView return result; } +// 22.2.5.2 RegExp.prototype.exec ( string ), https://tc39.es/ecma262/#sec-regexp.prototype.exec JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::exec) { // FIXME: This should try using dynamic properties for 'lastIndex', @@ -194,6 +203,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::exec) return array; } +// 22.2.5.15 RegExp.prototype.test ( S ), https://tc39.es/ecma262/#sec-regexp.prototype.test JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::test) { // FIXME: This should try using dynamic properties for 'exec' first, @@ -214,6 +224,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::test) return Value(result.success); } +// 22.2.5.16 RegExp.prototype.toString ( ), https://tc39.es/ecma262/#sec-regexp.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::to_string) { auto this_object = this_object_from(vm, global_object); @@ -237,9 +248,9 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::to_string) return js_string(vm, String::formatted("/{}/{}", pattern, flags)); } +// 22.2.5.7 RegExp.prototype [ @@match ] ( string ), https://tc39.es/ecma262/#sec-regexp.prototype-@@match JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) { - // https://tc39.es/ecma262/#sec-regexp.prototype-@@match auto* rx = this_object_from(vm, global_object); if (!rx) return {}; @@ -262,12 +273,12 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) return vm.call(*exec, rx, js_string(vm, s)); } +// 22.2.5.10 RegExp.prototype [ @@replace ] ( string, replaceValue ), https://tc39.es/ecma262/#sec-regexp.prototype-@@replace JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) { auto string_value = vm.argument(0); auto replace_value = vm.argument(1); - // https://tc39.es/ecma262/#sec-regexp.prototype-@@replace auto rx = regexp_object_from(vm, global_object); if (!rx) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp index 89db9a9cf4..b1d9f3e0dd 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp @@ -25,6 +25,8 @@ void SetIteratorPrototype::initialize(GlobalObject& global_object) Object::initialize(global_object); define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); + + // 24.2.5.2.2 %SetIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%setiteratorprototype%-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Set Iterator"), Attribute::Configurable); } @@ -32,6 +34,7 @@ SetIteratorPrototype::~SetIteratorPrototype() { } +// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next) { auto this_value = vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp index ac6c731260..ab61917fda 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp @@ -32,7 +32,11 @@ void SetPrototype::initialize(GlobalObject& global_object) define_native_property(vm.names.size, size_getter, {}, attr); define_property(vm.names.keys, get(vm.names.values), attr); + + // 24.2.3.11 Set.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-set.prototype-@@iterator define_property(vm.well_known_symbol_iterator(), get(vm.names.values), attr); + + // 24.2.3.12 Set.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-set.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.Set), Attribute::Configurable); } @@ -52,6 +56,7 @@ Set* SetPrototype::typed_this(VM& vm, GlobalObject& global_object) return static_cast<Set*>(this_object); } +// 24.2.3.1 Set.prototype.add ( value ), https://tc39.es/ecma262/#sec-set.prototype.add JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add) { auto* set = typed_this(vm, global_object); @@ -64,6 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add) return set; } +// 24.2.3.2 Set.prototype.clear ( ), https://tc39.es/ecma262/#sec-set.prototype.clear JS_DEFINE_NATIVE_FUNCTION(SetPrototype::clear) { auto* set = typed_this(vm, global_object); @@ -73,6 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::clear) return js_undefined(); } +// 24.2.3.4 Set.prototype.delete ( value ), https://tc39.es/ecma262/#sec-set.prototype.delete JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_) { auto* set = typed_this(vm, global_object); @@ -81,6 +88,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_) return Value(set->values().remove(vm.argument(0))); } +// 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries) { auto* set = typed_this(vm, global_object); @@ -90,6 +98,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries) return SetIterator::create(global_object, *set, Object::PropertyKind::KeyAndValue); } +// 24.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-set.prototype.foreach JS_DEFINE_NATIVE_FUNCTION(SetPrototype::for_each) { auto* set = typed_this(vm, global_object); @@ -108,6 +117,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::for_each) return js_undefined(); } +// 24.2.3.7 Set.prototype.has ( value ), https://tc39.es/ecma262/#sec-set.prototype.has JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has) { auto* set = typed_this(vm, global_object); @@ -117,6 +127,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has) return Value(values.find(vm.argument(0)) != values.end()); } +// 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values) { auto* set = typed_this(vm, global_object); @@ -126,6 +137,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values) return SetIterator::create(global_object, *set, Object::PropertyKind::Value); } +// 24.2.3.9 get Set.prototype.size, https://tc39.es/ecma262/#sec-get-set.prototype.size JS_DEFINE_NATIVE_GETTER(SetPrototype::size_getter) { auto* set = typed_this(vm, global_object); diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index f27a47be6f..ed23df20bc 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -23,7 +23,10 @@ void StringConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 22.1.2.3 String.prototype, https://tc39.es/ecma262/#sec-string.prototype define_property(vm.names.prototype, global_object.string_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -35,6 +38,7 @@ StringConstructor::~StringConstructor() { } +// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value Value StringConstructor::call() { if (!vm().argument_count()) @@ -47,6 +51,7 @@ Value StringConstructor::call() return string; } +// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value Value StringConstructor::construct(Function&) { PrimitiveString* primitive_string = nullptr; @@ -59,6 +64,7 @@ Value StringConstructor::construct(Function&) return StringObject::create(global_object(), *primitive_string); } +// 22.1.2.4 String.raw ( template, ...substitutions ), https://tc39.es/ecma262/#sec-string.raw JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw) { auto* template_object = vm.argument(0).to_object(global_object); @@ -99,6 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw) return js_string(vm, builder.build()); } +// 22.1.2.1 String.fromCharCode ( ...codeUnits ), https://tc39.es/ecma262/#sec-string.fromcharcode JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code) { StringBuilder builder; diff --git a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp index b4b6cbaf86..8aa0163494 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp @@ -23,6 +23,8 @@ void StringIteratorPrototype::initialize(GlobalObject& global_object) auto& vm = this->vm(); Object::initialize(global_object); define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); + + // 22.1.5.1.2 %StringIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%stringiteratorprototype%-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "String Iterator"), Attribute::Configurable); } @@ -30,6 +32,7 @@ StringIteratorPrototype::~StringIteratorPrototype() { } +// 22.1.5.1.1 %StringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next) { auto this_value = vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index e3dcbc2d2a..0dddb7f8bc 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -99,7 +99,7 @@ StringPrototype::~StringPrototype() { } -// thisStringValue, https://tc39.es/ecma262/#thisstringvalue +// thisStringValue ( value ), https://tc39.es/ecma262/#thisstringvalue static Value this_string_value(GlobalObject& global_object, Value value) { if (value.is_string()) @@ -111,6 +111,7 @@ static Value this_string_value(GlobalObject& global_object, Value value) return {}; } +// 22.1.3.1 String.prototype.charAt ( pos ), https://tc39.es/ecma262/#sec-string.prototype.charat JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at) { auto string = ak_string_from(vm, global_object); @@ -128,6 +129,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at) return js_string(vm, string.substring(index, 1)); } +// 22.1.3.2 String.prototype.charCodeAt ( pos ), https://tc39.es/ecma262/#sec-string.prototype.charcodeat JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_code_at) { auto string = ak_string_from(vm, global_object); @@ -145,6 +147,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_code_at) return Value((i32)string[index]); } +// 22.1.3.16 String.prototype.repeat ( count ), https://tc39.es/ecma262/#sec-string.prototype.repeat JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat) { auto string = ak_string_from(vm, global_object); @@ -169,6 +172,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat) return js_string(vm, builder.to_string()); } +// 22.1.3.22 String.prototype.startsWith ( searchString [ , position ] ), https://tc39.es/ecma262/#sec-string.prototype.startswith JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with) { auto string = ak_string_from(vm, global_object); @@ -205,6 +209,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with) return Value(string.substring(start, search_string_length) == search_string); } +// 22.1.3.6 String.prototype.endsWith ( searchString [ , endPosition ] ), https://tc39.es/ecma262/#sec-string.prototype.endswith JS_DEFINE_NATIVE_FUNCTION(StringPrototype::ends_with) { auto string = ak_string_from(vm, global_object); @@ -247,6 +252,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::ends_with) return Value(string.substring(start, search_string_length) == search_string); } +// 22.1.3.8 String.prototype.indexOf ( searchString [ , position ] ), https://tc39.es/ecma262/#sec-string.prototype.indexof JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of) { auto string = ak_string_from(vm, global_object); @@ -258,6 +264,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of) return Value((i32)string.find(needle).value_or(-1)); } +// 22.1.3.26 String.prototype.toLowerCase ( ), https://tc39.es/ecma262/#sec-string.prototype.tolowercase JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase) { auto string = ak_string_from(vm, global_object); @@ -266,6 +273,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase) return js_string(vm, string.to_lowercase()); } +// 22.1.3.28 String.prototype.toUpperCase ( ), https://tc39.es/ecma262/#sec-string.prototype.touppercase JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase) { auto string = ak_string_from(vm, global_object); @@ -274,11 +282,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase) return js_string(vm, string.to_uppercase()); } +// 22.1.3.27 String.prototype.toString ( ), https://tc39.es/ecma262/#sec-string.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_string) { return this_string_value(global_object, vm.this_value(global_object)); } +// 22.1.3.32 String.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-string.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(StringPrototype::value_of) { return this_string_value(global_object, vm.this_value(global_object)); @@ -289,6 +299,7 @@ enum class PadPlacement { End, }; +// 22.1.3.15.1 StringPad ( O, maxLength, fillString, placement ), https://tc39.es/ecma262/#sec-stringpad static Value pad_string(GlobalObject& global_object, const String& string, PadPlacement placement) { auto& vm = global_object.vm(); @@ -320,6 +331,7 @@ static Value pad_string(GlobalObject& global_object, const String& string, PadPl return js_string(vm, formatted); } +// 22.1.3.15 String.prototype.padStart ( maxLength [ , fillString ] ), https://tc39.es/ecma262/#sec-string.prototype.padstart JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_start) { auto string = ak_string_from(vm, global_object); @@ -328,6 +340,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_start) return pad_string(global_object, string, PadPlacement::Start); } +// 22.1.3.14 String.prototype.padEnd ( maxLength [ , fillString ] ), https://tc39.es/ecma262/#sec-string.prototype.padend JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_end) { auto string = ak_string_from(vm, global_object); @@ -336,6 +349,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_end) return pad_string(global_object, string, PadPlacement::End); } +// 22.1.3.29 String.prototype.trim ( ), https://tc39.es/ecma262/#sec-string.prototype.trim JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim) { auto string = ak_string_from(vm, global_object); @@ -344,6 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim) return js_string(vm, string.trim_whitespace(TrimMode::Both)); } +// 22.1.3.31 String.prototype.trimStart ( ), https://tc39.es/ecma262/#sec-string.prototype.trimstart JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_start) { auto string = ak_string_from(vm, global_object); @@ -352,6 +367,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_start) return js_string(vm, string.trim_whitespace(TrimMode::Left)); } +// 22.1.3.30 String.prototype.trimEnd ( ), https://tc39.es/ecma262/#sec-string.prototype.trimend JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_end) { auto string = ak_string_from(vm, global_object); @@ -360,6 +376,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_end) return js_string(vm, string.trim_whitespace(TrimMode::Right)); } +// 22.1.3.23 String.prototype.substring ( start, end ), https://tc39.es/ecma262/#sec-string.prototype.substring JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat) { auto string = ak_string_from(vm, global_object); @@ -376,6 +393,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat) return js_string(vm, builder.to_string()); } +// 22.1.3.23 String.prototype.substring ( start, end ), https://tc39.es/ecma262/#sec-string.prototype.substring JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring) { auto string = ak_string_from(vm, global_object); @@ -414,6 +432,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring) return js_string(vm, string_part); } +// B.2.3.1 String.prototype.substr ( start, length ), https://tc39.es/ecma262/#sec-string.prototype.substr JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substr) { auto string = ak_string_from(vm, global_object); @@ -451,6 +470,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substr) return js_string(vm, string_part); } +// 22.1.3.7 String.prototype.includes ( searchString [ , position ] ), https://tc39.es/ecma262/#sec-string.prototype.includes JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes) { auto string = ak_string_from(vm, global_object); @@ -475,6 +495,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes) return Value(substring_search.contains(search_string)); } +// 22.1.3.20 String.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-string.prototype.slice JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice) { auto string = ak_string_from(vm, global_object); @@ -519,6 +540,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice) return js_string(vm, string_part); } +// 22.1.3.21 String.prototype.split ( separator, limit ), https://tc39.es/ecma262/#sec-string.prototype.split JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split) { // FIXME Implement the @@split part @@ -587,6 +609,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split) return result; } +// 22.1.3.9 String.prototype.lastIndexOf ( searchString [ , position ] ), https://tc39.es/ecma262/#sec-string.prototype.lastindexof JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of) { auto string = ak_string_from(vm, global_object); @@ -619,6 +642,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of) return Value(-1); } +// 3.1 String.prototype.at ( index ), https://tc39.es/proposal-relative-indexing-method/#sec-string.prototype.at JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at) { auto string = ak_string_from(vm, global_object); @@ -642,6 +666,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at) return js_string(vm, String::formatted("{}", string[index.value()])); } +// 22.1.3.33 String.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-string.prototype-@@iterator JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator) { auto this_object = require_object_coercible(global_object, vm.this_value(global_object)); @@ -653,9 +678,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator) return StringIterator::create(global_object, string); } +// 22.1.3.11 String.prototype.match ( regexp ), https://tc39.es/ecma262/#sec-string.prototype.match JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match) { - // https://tc39.es/ecma262/#sec-string.prototype.match auto this_object = require_object_coercible(global_object, vm.this_value(global_object)); if (vm.exception()) return {}; @@ -673,9 +698,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match) return rx->invoke(vm.well_known_symbol_match(), js_string(vm, s)); } +// 22.1.3.17 String.prototype.replace ( searchValue, replaceValue ), https://tc39.es/ecma262/#sec-string.prototype.replace JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace) { - // https://tc39.es/ecma262/#sec-string.prototype.replace auto this_object = require_object_coercible(global_object, vm.this_value(global_object)); if (vm.exception()) return {}; @@ -723,7 +748,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace) return js_string(vm, builder.build()); } -// B.2.3.2.1 +// B.2.3.2.1 CreateHTML ( string, tag, attribute, value ), https://tc39.es/ecma262/#sec-createhtml static Value create_html(GlobalObject& global_object, Value string, const String& tag, const String& attribute, Value value) { auto& vm = global_object.vm(); @@ -755,66 +780,79 @@ static Value create_html(GlobalObject& global_object, Value string, const String return js_string(vm, builder.build()); } +// B.2.3.2 String.prototype.anchor ( name ), https://tc39.es/ecma262/#sec-string.prototype.anchor JS_DEFINE_NATIVE_FUNCTION(StringPrototype::anchor) { return create_html(global_object, vm.this_value(global_object), "a", "name", vm.argument(0)); } +// B.2.3.3 String.prototype.big ( ), https://tc39.es/ecma262/#sec-string.prototype.big JS_DEFINE_NATIVE_FUNCTION(StringPrototype::big) { return create_html(global_object, vm.this_value(global_object), "big", String::empty(), Value()); } +// B.2.3.4 String.prototype.blink ( ), https://tc39.es/ecma262/#sec-string.prototype.blink JS_DEFINE_NATIVE_FUNCTION(StringPrototype::blink) { return create_html(global_object, vm.this_value(global_object), "blink", String::empty(), Value()); } +// B.2.3.5 String.prototype.bold ( ), https://tc39.es/ecma262/#sec-string.prototype.bold JS_DEFINE_NATIVE_FUNCTION(StringPrototype::bold) { return create_html(global_object, vm.this_value(global_object), "b", String::empty(), Value()); } +// B.2.3.6 String.prototype.fixed ( ), https://tc39.es/ecma262/#sec-string.prototype.fixed JS_DEFINE_NATIVE_FUNCTION(StringPrototype::fixed) { return create_html(global_object, vm.this_value(global_object), "tt", String::empty(), Value()); } +// B.2.3.7 String.prototype.fontcolor ( color ), https://tc39.es/ecma262/#sec-string.prototype.fontcolor JS_DEFINE_NATIVE_FUNCTION(StringPrototype::fontcolor) { return create_html(global_object, vm.this_value(global_object), "font", "color", vm.argument(0)); } +// B.2.3.8 String.prototype.fontsize ( size ), https://tc39.es/ecma262/#sec-string.prototype.fontsize JS_DEFINE_NATIVE_FUNCTION(StringPrototype::fontsize) { return create_html(global_object, vm.this_value(global_object), "font", "size", vm.argument(0)); } +// B.2.3.9 String.prototype.italics ( ), https://tc39.es/ecma262/#sec-string.prototype.italics JS_DEFINE_NATIVE_FUNCTION(StringPrototype::italics) { return create_html(global_object, vm.this_value(global_object), "i", String::empty(), Value()); } +// B.2.3.10 String.prototype.link ( url ), https://tc39.es/ecma262/#sec-string.prototype.link JS_DEFINE_NATIVE_FUNCTION(StringPrototype::link) { return create_html(global_object, vm.this_value(global_object), "a", "href", vm.argument(0)); } +// B.2.3.11 String.prototype.small ( ), https://tc39.es/ecma262/#sec-string.prototype.small JS_DEFINE_NATIVE_FUNCTION(StringPrototype::small) { return create_html(global_object, vm.this_value(global_object), "small", String::empty(), Value()); } +// B.2.3.12 String.prototype.strike ( ), https://tc39.es/ecma262/#sec-string.prototype.strike JS_DEFINE_NATIVE_FUNCTION(StringPrototype::strike) { return create_html(global_object, vm.this_value(global_object), "strike", String::empty(), Value()); } +// B.2.3.13 String.prototype.sub ( ), https://tc39.es/ecma262/#sec-string.prototype.sub JS_DEFINE_NATIVE_FUNCTION(StringPrototype::sub) { return create_html(global_object, vm.this_value(global_object), "sub", String::empty(), Value()); } +// B.2.3.14 String.prototype.sup ( ), https://tc39.es/ecma262/#sec-string.prototype.sup JS_DEFINE_NATIVE_FUNCTION(StringPrototype::sup) { return create_html(global_object, vm.this_value(global_object), "sup", String::empty(), Value()); diff --git a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp index 3d50ca8d90..cb2a98e7e5 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp @@ -19,7 +19,10 @@ void SymbolConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 20.4.2.9 Symbol.prototype, https://tc39.es/ecma262/#sec-symbol.prototype define_property(vm.names.prototype, global_object.symbol_prototype(), 0); + define_property(vm.names.length, Value(0), Attribute::Configurable); define_native_function(vm.names.for_, for_, 1, Attribute::Writable | Attribute::Configurable); @@ -35,6 +38,7 @@ SymbolConstructor::~SymbolConstructor() { } +// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description Value SymbolConstructor::call() { if (!vm().argument_count()) @@ -42,12 +46,14 @@ Value SymbolConstructor::call() return js_symbol(heap(), vm().argument(0).to_string(global_object()), false); } +// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description Value SymbolConstructor::construct(Function&) { vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "Symbol"); return {}; } +// 20.4.2.2 Symbol.for ( key ), https://tc39.es/ecma262/#sec-symbol.for JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_) { String description; @@ -60,6 +66,7 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_) return global_object.vm().get_global_symbol(description); } +// 20.4.2.6 Symbol.keyFor ( sym ), https://tc39.es/ecma262/#sec-symbol.keyfor JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::key_for) { auto argument = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp index aba05876af..a77dacf970 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -30,6 +30,8 @@ void SymbolPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.toString, to_string, 0, Attribute::Writable | Attribute::Configurable); define_native_function(vm.names.valueOf, value_of, 0, Attribute::Writable | Attribute::Configurable); define_native_function(vm.well_known_symbol_to_primitive(), symbol_to_primitive, 1, Attribute::Configurable); + + // 20.4.3.6 Symbol.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Symbol"), Attribute::Configurable); } @@ -37,7 +39,7 @@ SymbolPrototype::~SymbolPrototype() { } -// thisSymbolValue, https://tc39.es/ecma262/#thissymbolvalue +// thisSymbolValue ( value ), https://tc39.es/ecma262/#thissymbolvalue static Value this_symbol_value(GlobalObject& global_object, Value value) { if (value.is_symbol()) @@ -49,6 +51,7 @@ static Value this_symbol_value(GlobalObject& global_object, Value value) return {}; } +// 20.4.3.2 get Symbol.prototype.description, https://tc39.es/ecma262/#sec-symbol.prototype.description JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter) { auto symbol_value = this_symbol_value(global_object, vm.this_value(global_object)); @@ -57,6 +60,7 @@ JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter) return js_string(vm, symbol_value.as_symbol().description()); } +// 20.4.3.3 Symbol.prototype.toString ( ), https://tc39.es/ecma262/#sec-symbol.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string) { auto symbol_value = this_symbol_value(global_object, vm.this_value(global_object)); @@ -65,11 +69,13 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string) return js_string(vm, symbol_value.as_symbol().to_string()); } +// 20.4.3.4 Symbol.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-symbol.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of) { return this_symbol_value(global_object, vm.this_value(global_object)); } +// 20.4.3.5 Symbol.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::symbol_to_primitive) { // The hint argument is ignored. diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 63c4da2158..eb10d24ace 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -45,6 +45,7 @@ static TypedArrayBase* typed_array_from(VM& vm, GlobalObject& global_object) return static_cast<TypedArrayBase*>(this_object); } +// 23.2.3.18 get %TypedArray%.prototype.length, https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.length JS_DEFINE_NATIVE_GETTER(TypedArrayPrototype::length_getter) { auto typed_array = typed_array_from(vm, global_object); @@ -57,6 +58,7 @@ JS_DEFINE_NATIVE_GETTER(TypedArrayPrototype::length_getter) return Value(typed_array->array_length()); } +// 4.1 %TypedArray%.prototype.at ( index ), https://tc39.es/proposal-relative-indexing-method/#sec-%typedarray%.prototype.at JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::at) { auto typed_array = typed_array_from(vm, global_object); @@ -80,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::at) return typed_array->get(index.value()); } -// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.buffer +// 23.2.3.1 get %TypedArray%.prototype.buffer, https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.buffer JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::buffer_getter) { auto typed_array = typed_array_from(vm, global_object); @@ -91,7 +93,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::buffer_getter) return Value(array_buffer); } -// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.bytelength +// 23.2.3.2 get %TypedArray%.prototype.byteLength, https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.bytelength JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::byte_length_getter) { auto typed_array = typed_array_from(vm, global_object); @@ -104,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::byte_length_getter) return Value(typed_array->byte_length()); } -// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.byteoffset +// 23.2.3.3 get %TypedArray%.prototype.byteOffset, https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.byteoffset JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::byte_offset_getter) { auto typed_array = typed_array_from(vm, global_object); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 34dec185b9..558dc48cd3 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -551,13 +551,13 @@ void VM::run_queued_promise_jobs() VERIFY(!m_exception); } -// 9.4.4 HostEnqueuePromiseJob, https://tc39.es/ecma262/#sec-hostenqueuepromisejob +// 9.5.4 HostEnqueuePromiseJob ( job, realm ), https://tc39.es/ecma262/#sec-hostenqueuepromisejob void VM::enqueue_promise_job(NativeFunction& job) { m_promise_jobs.append(&job); } -// 27.2.1.9 HostPromiseRejectionTracker, https://tc39.es/ecma262/#sec-host-promise-rejection-tracker +// 27.2.1.9 HostPromiseRejectionTracker ( promise, operation ), https://tc39.es/ecma262/#sec-host-promise-rejection-tracker void VM::promise_rejection_tracker(const Promise& promise, Promise::RejectionOperation operation) const { switch (operation) { diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index ded9689eaf..fd8752ef5c 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -70,9 +70,9 @@ ALWAYS_INLINE bool both_bigint(const Value& lhs, const Value& rhs) return lhs.is_bigint() && rhs.is_bigint(); } +// 6.1.6.1.20 Number::toString ( x ), https://tc39.es/ecma262/#sec-numeric-types-number-tostring static String double_to_string(double d) { - // https://tc39.es/ecma262/#sec-numeric-types-number-tostring if (isnan(d)) return "NaN"; if (d == +0.0 || d == -0.0) @@ -198,7 +198,7 @@ static String double_to_string(double d) return builder.to_string(); } -// 7.2.2 IsArray, https://tc39.es/ecma262/#sec-isarray +// 7.2.2 IsArray ( argument ), https://tc39.es/ecma262/#sec-isarray bool Value::is_array(GlobalObject& global_object) const { if (!is_object()) @@ -224,6 +224,7 @@ Array& Value::as_array() return static_cast<Array&>(*m_value.as_object); } +// 7.2.3 IsCallable ( argument ), https://tc39.es/ecma262/#sec-iscallable bool Value::is_function() const { return is_object() && as_object().is_function(); @@ -235,7 +236,7 @@ Function& Value::as_function() return static_cast<Function&>(as_object()); } -// 7.2.4 IsConstructor, https://tc39.es/ecma262/#sec-isconstructor +// 7.2.4 IsConstructor ( argument ), https://tc39.es/ecma262/#sec-isconstructor bool Value::is_constructor() const { if (!is_function()) @@ -246,7 +247,7 @@ bool Value::is_constructor() const return true; } -// 7.2.8 IsRegExp, https://tc39.es/ecma262/#sec-isregexp +// 7.2.8 IsRegExp ( argument ), https://tc39.es/ecma262/#sec-isregexp bool Value::is_regexp(GlobalObject& global_object) const { if (!is_object()) @@ -261,6 +262,7 @@ bool Value::is_regexp(GlobalObject& global_object) const return is<RegExpObject>(as_object()); } +// 13.5.3 The typeof Operator, https://tc39.es/ecma262/#sec-typeof-operator String Value::typeof() const { switch (m_type) { @@ -328,6 +330,7 @@ PrimitiveString* Value::to_primitive_string(GlobalObject& global_object) return js_string(global_object.heap(), string); } +// 7.1.17 ToString ( argument ), https://tc39.es/ecma262/#sec-tostring String Value::to_string(GlobalObject& global_object, bool legacy_null_to_empty_string) const { switch (m_type) { @@ -359,6 +362,7 @@ String Value::to_string(GlobalObject& global_object, bool legacy_null_to_empty_s } } +// 7.1.2 ToBoolean ( argument ), https://tc39.es/ecma262/#sec-toboolean bool Value::to_boolean() const { switch (m_type) { @@ -386,6 +390,7 @@ bool Value::to_boolean() const } } +// 7.1.1 ToPrimitive ( input [ , preferredType ] ), https://tc39.es/ecma262/#sec-toprimitive Value Value::to_primitive(GlobalObject& global_object, PreferredType preferred_type) const { auto get_hint_for_preferred_type = [&]() -> String { @@ -422,6 +427,7 @@ Value Value::to_primitive(GlobalObject& global_object, PreferredType preferred_t return *this; } +// 7.1.18 ToObject ( argument ), https://tc39.es/ecma262/#sec-toobject Object* Value::to_object(GlobalObject& global_object) const { switch (m_type) { @@ -448,6 +454,7 @@ Object* Value::to_object(GlobalObject& global_object) const } } +// 7.1.3 ToNumeric ( value ), https://tc39.es/ecma262/#sec-tonumeric FLATTEN Value Value::to_numeric(GlobalObject& global_object) const { auto primitive = to_primitive(global_object, Value::PreferredType::Number); @@ -458,6 +465,7 @@ FLATTEN Value Value::to_numeric(GlobalObject& global_object) const return primitive.to_number(global_object); } +// 7.1.4 ToNumber ( argument ), https://tc39.es/ecma262/#sec-tonumber Value Value::to_number(GlobalObject& global_object) const { switch (m_type) { @@ -501,6 +509,7 @@ Value Value::to_number(GlobalObject& global_object) const } } +// 7.1.13 ToBigInt ( argument ), https://tc39.es/ecma262/#sec-tobigint BigInt* Value::to_bigint(GlobalObject& global_object) const { auto& vm = global_object.vm(); @@ -560,6 +569,7 @@ double Value::to_double(GlobalObject& global_object) const return number.as_double(); } +// 7.1.19 ToPropertyKey ( argument ), https://tc39.es/ecma262/#sec-topropertykey StringOrSymbol Value::to_property_key(GlobalObject& global_object) const { auto key = to_primitive(global_object, PreferredType::String); @@ -590,9 +600,9 @@ i32 Value::to_i32_slow_case(GlobalObject& global_object) const return static_cast<i32>(int32bit); } +// 7.1.7 ToUint32 ( argument ), https://tc39.es/ecma262/#sec-touint32 u32 Value::to_u32(GlobalObject& global_object) const { - // 7.1.7 ToUint32, https://tc39.es/ecma262/#sec-touint32 auto number = to_number(global_object); if (global_object.vm().exception()) return INVALID; @@ -606,10 +616,9 @@ u32 Value::to_u32(GlobalObject& global_object) const return static_cast<u32>(int32bit); } +// 7.1.20 ToLength ( argument ), https://tc39.es/ecma262/#sec-tolength size_t Value::to_length(GlobalObject& global_object) const { - // 7.1.20 ToLength, https://tc39.es/ecma262/#sec-tolength - auto& vm = global_object.vm(); auto len = to_integer_or_infinity(global_object); @@ -620,10 +629,9 @@ size_t Value::to_length(GlobalObject& global_object) const return min(len, MAX_ARRAY_LIKE_INDEX); } +// 7.1.22 ToIndex ( argument ), https://tc39.es/ecma262/#sec-toindex size_t Value::to_index(GlobalObject& global_object) const { - // 7.1.22 ToIndex, https://tc39.es/ecma262/#sec-toindex - auto& vm = global_object.vm(); if (is_undefined()) @@ -644,10 +652,9 @@ size_t Value::to_index(GlobalObject& global_object) const return index; } +// 7.1.5 ToIntegerOrInfinity ( argument ), https://tc39.es/ecma262/#sec-tointegerorinfinity double Value::to_integer_or_infinity(GlobalObject& global_object) const { - // 7.1.5 ToIntegerOrInfinity, https://tc39.es/ecma262/#sec-tointegerorinfinity - auto& vm = global_object.vm(); auto number = to_number(global_object); @@ -663,6 +670,7 @@ double Value::to_integer_or_infinity(GlobalObject& global_object) const return integer; } +// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators Value greater_than(GlobalObject& global_object, Value lhs, Value rhs) { TriState relation = abstract_relation(global_object, false, lhs, rhs); @@ -671,6 +679,7 @@ Value greater_than(GlobalObject& global_object, Value lhs, Value rhs) return Value(relation == TriState::True); } +// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators Value greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs) { TriState relation = abstract_relation(global_object, true, lhs, rhs); @@ -679,6 +688,7 @@ Value greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs) return Value(true); } +// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators Value less_than(GlobalObject& global_object, Value lhs, Value rhs) { TriState relation = abstract_relation(global_object, true, lhs, rhs); @@ -687,6 +697,7 @@ Value less_than(GlobalObject& global_object, Value lhs, Value rhs) return Value(relation == TriState::True); } +// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators Value less_than_equals(GlobalObject& global_object, Value lhs, Value rhs) { TriState relation = abstract_relation(global_object, false, lhs, rhs); @@ -695,6 +706,7 @@ Value less_than_equals(GlobalObject& global_object, Value lhs, Value rhs) return Value(true); } +// 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators Value bitwise_and(GlobalObject& global_object, Value lhs, Value rhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -714,6 +726,7 @@ Value bitwise_and(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators Value bitwise_or(GlobalObject& global_object, Value lhs, Value rhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -737,6 +750,7 @@ Value bitwise_or(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators Value bitwise_xor(GlobalObject& global_object, Value lhs, Value rhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -760,6 +774,7 @@ Value bitwise_xor(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.5.6 Bitwise NOT Operator ( ~ ), https://tc39.es/ecma262/#sec-bitwise-not-operator Value bitwise_not(GlobalObject& global_object, Value lhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -773,11 +788,13 @@ Value bitwise_not(GlobalObject& global_object, Value lhs) return js_bigint(global_object.heap(), big_integer_bitwise_not); } +// 13.5.4 Unary + Operator, https://tc39.es/ecma262/#sec-unary-plus-operator Value unary_plus(GlobalObject& global_object, Value lhs) { return lhs.to_number(global_object); } +// 13.5.5 Unary - Operator, https://tc39.es/ecma262/#sec-unary-minus-operator Value unary_minus(GlobalObject& global_object, Value lhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -795,10 +812,9 @@ Value unary_minus(GlobalObject& global_object, Value lhs) return js_bigint(global_object.heap(), big_integer_negated); } +// 13.9.1 The Left Shift Operator ( << ), https://tc39.es/ecma262/#sec-left-shift-operator Value left_shift(GlobalObject& global_object, Value lhs, Value rhs) { - // 6.1.6.1.9 Number::leftShift - // https://tc39.es/ecma262/#sec-numeric-types-number-leftShift auto lhs_numeric = lhs.to_numeric(global_object); if (global_object.vm().exception()) return {}; @@ -826,10 +842,9 @@ Value left_shift(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.9.2 The Signed Right Shift Operator ( >> ), https://tc39.es/ecma262/#sec-signed-right-shift-operator Value right_shift(GlobalObject& global_object, Value lhs, Value rhs) { - // 6.1.6.1.11 Number::signedRightShift - // https://tc39.es/ecma262/#sec-numeric-types-number-signedRightShift auto lhs_numeric = lhs.to_numeric(global_object); if (global_object.vm().exception()) return {}; @@ -841,7 +856,6 @@ Value right_shift(GlobalObject& global_object, Value lhs, Value rhs) return Value(0); if (!rhs_numeric.is_finite_number()) return lhs_numeric; - // Ok, so this performs toNumber() again but that "can't" throw auto lhs_i32 = lhs_numeric.to_i32(global_object); auto rhs_u32 = rhs_numeric.to_u32(global_object); return Value(lhs_i32 >> rhs_u32); @@ -855,10 +869,9 @@ Value right_shift(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.9.3 The Unsigned Right Shift Operator ( >>> ), https://tc39.es/ecma262/#sec-unsigned-right-shift-operator Value unsigned_right_shift(GlobalObject& global_object, Value lhs, Value rhs) { - // 6.1.6.1.11 Number::unsignedRightShift - // https://tc39.es/ecma262/#sec-numeric-types-number-unsignedRightShift auto lhs_numeric = lhs.to_numeric(global_object); if (global_object.vm().exception()) return {}; @@ -879,6 +892,7 @@ Value unsigned_right_shift(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.8.1 The Addition Operator ( + ), https://tc39.es/ecma262/#sec-addition-operator-plus Value add(GlobalObject& global_object, Value lhs, Value rhs) { if (both_number(lhs, rhs)) { @@ -926,6 +940,7 @@ Value add(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.8.2 The Subtraction Operator ( - ), https://tc39.es/ecma262/#sec-subtraction-operator-minus Value sub(GlobalObject& global_object, Value lhs, Value rhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -942,6 +957,7 @@ Value sub(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.7 Multiplicative Operators, https://tc39.es/ecma262/#sec-multiplicative-operators Value mul(GlobalObject& global_object, Value lhs, Value rhs) { auto lhs_numeric = lhs.to_numeric(global_object); @@ -958,6 +974,7 @@ Value mul(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.7 Multiplicative Operators, https://tc39.es/ecma262/#sec-multiplicative-operators Value div(GlobalObject& global_object, Value lhs, Value rhs) { auto& vm = global_object.vm(); @@ -980,6 +997,7 @@ Value div(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.7 Multiplicative Operators, https://tc39.es/ecma262/#sec-multiplicative-operators Value mod(GlobalObject& global_object, Value lhs, Value rhs) { auto& vm = global_object.vm(); @@ -1008,6 +1026,7 @@ Value mod(GlobalObject& global_object, Value lhs, Value rhs) return {}; } +// 13.6 Exponentiation Operator, https://tc39.es/ecma262/#sec-exp-operator Value exp(GlobalObject& global_object, Value lhs, Value rhs) { auto& vm = global_object.vm(); @@ -1042,6 +1061,7 @@ Value in(GlobalObject& global_object, Value lhs, Value rhs) return Value(rhs.as_object().has_property(lhs_property_key)); } +// 13.10.2 InstanceofOperator ( V, target ), https://tc39.es/ecma262/#sec-instanceofoperator Value instance_of(GlobalObject& global_object, Value lhs, Value rhs) { auto& vm = global_object.vm(); @@ -1100,6 +1120,7 @@ Value ordinary_has_instance(GlobalObject& global_object, Value lhs, Value rhs) } } +// 7.2.10 SameValue ( x, y ), https://tc39.es/ecma262/#sec-samevalue bool same_value(Value lhs, Value rhs) { if (!same_type_for_equality(lhs, rhs)) @@ -1126,6 +1147,7 @@ bool same_value(Value lhs, Value rhs) return same_value_non_numeric(lhs, rhs); } +// 7.2.11 SameValueZero ( x, y ), https://tc39.es/ecma262/#sec-samevaluezero bool same_value_zero(Value lhs, Value rhs) { if (!same_type_for_equality(lhs, rhs)) @@ -1143,6 +1165,7 @@ bool same_value_zero(Value lhs, Value rhs) return same_value_non_numeric(lhs, rhs); } +// 7.2.12 SameValueNonNumeric ( x, y ), https://tc39.es/ecma262/#sec-samevaluenonnumeric bool same_value_non_numeric(Value lhs, Value rhs) { VERIFY(!lhs.is_number() && !lhs.is_bigint()); @@ -1165,6 +1188,7 @@ bool same_value_non_numeric(Value lhs, Value rhs) } } +// 7.2.15 IsStrictlyEqual ( x, y ), https://tc39.es/ecma262/#sec-isstrictlyequal bool strict_eq(Value lhs, Value rhs) { if (!same_type_for_equality(lhs, rhs)) @@ -1184,6 +1208,7 @@ bool strict_eq(Value lhs, Value rhs) return same_value_non_numeric(lhs, rhs); } +// 7.2.14 IsLooselyEqual ( x, y ), https://tc39.es/ecma262/#sec-islooselyequal bool abstract_eq(GlobalObject& global_object, Value lhs, Value rhs) { if (same_type_for_equality(lhs, rhs)) @@ -1242,6 +1267,7 @@ bool abstract_eq(GlobalObject& global_object, Value lhs, Value rhs) return false; } +// 7.2.13 IsLessThan ( x, y, LeftFirst ), https://tc39.es/ecma262/#sec-islessthan TriState abstract_relation(GlobalObject& global_object, bool left_first, Value lhs, Value rhs) { Value x_primitive; @@ -1357,7 +1383,7 @@ TriState abstract_relation(GlobalObject& global_object, bool left_first, Value l return TriState::False; } -// 7.3.10 GetMethod, https://tc39.es/ecma262/#sec-getmethod +// 7.3.10 GetMethod ( V, P ), https://tc39.es/ecma262/#sec-getmethod Function* get_method(GlobalObject& global_object, Value value, const PropertyName& property_name) { auto& vm = global_object.vm(); @@ -1376,7 +1402,7 @@ Function* get_method(GlobalObject& global_object, Value value, const PropertyNam return &property_value.as_function(); } -// 7.3.18 LengthOfArrayLike, https://tc39.es/ecma262/#sec-lengthofarraylike +// 7.3.18 LengthOfArrayLike ( obj ), https://tc39.es/ecma262/#sec-lengthofarraylike size_t length_of_array_like(GlobalObject& global_object, const Object& object) { auto& vm = global_object.vm(); @@ -1386,7 +1412,7 @@ size_t length_of_array_like(GlobalObject& global_object, const Object& object) return result.to_length(global_object); } -// 7.3.22 SpeciesConstructor, https://tc39.es/ecma262/#sec-speciesconstructor +// 7.3.22 SpeciesConstructor ( O, defaultConstructor ), https://tc39.es/ecma262/#sec-speciesconstructor Function* species_constructor(GlobalObject& global_object, const Object& object, Function& default_constructor) { auto& vm = global_object.vm(); @@ -1408,7 +1434,7 @@ Function* species_constructor(GlobalObject& global_object, const Object& object, return nullptr; } -// 7.2.1 RequireObjectCoercible, https://tc39.es/ecma262/#sec-requireobjectcoercible +// 7.2.1 RequireObjectCoercible ( argument ), https://tc39.es/ecma262/#sec-requireobjectcoercible Value require_object_coercible(GlobalObject& global_object, Value value) { auto& vm = global_object.vm(); @@ -1419,7 +1445,7 @@ Value require_object_coercible(GlobalObject& global_object, Value value) return value; } -// 7.3.19 CreateListFromArrayLike, https://tc39.es/ecma262/#sec-createlistfromarraylike +// 7.3.19 CreateListFromArrayLike ( obj [ , elementTypes ] ), https://tc39.es/ecma262/#sec-createlistfromarraylike MarkedValueList create_list_from_array_like(GlobalObject& global_object, Value value, AK::Function<Result<void, ErrorType>(Value)> check_value) { auto& vm = global_object.vm(); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp index 6b63c47115..41ea268ca8 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp @@ -25,6 +25,7 @@ void WeakMapPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.has, has, 1, attr); define_native_function(vm.names.set, set, 2, attr); + // 24.3.3.6 WeakMap.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-weakmap.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.WeakMap), Attribute::Configurable); } @@ -44,6 +45,7 @@ WeakMap* WeakMapPrototype::typed_this(VM& vm, GlobalObject& global_object) return static_cast<WeakMap*>(this_object); } +// 24.3.3.2 WeakMap.prototype.delete ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.delete JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::delete_) { auto* weak_map = typed_this(vm, global_object); @@ -55,6 +57,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::delete_) return Value(weak_map->values().remove(&value.as_object())); } +// 24.3.3.3 WeakMap.prototype.get ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.get JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::get) { auto* weak_map = typed_this(vm, global_object); @@ -70,6 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::get) return result->value; } +// 24.3.3.4 WeakMap.prototype.has ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.has JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::has) { auto* weak_map = typed_this(vm, global_object); @@ -82,6 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::has) return Value(values.find(&value.as_object()) != values.end()); } +// 24.3.3.5 WeakMap.prototype.set ( key, value ), https://tc39.es/ecma262/#sec-weakmap.prototype.set JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::set) { auto* weak_map = typed_this(vm, global_object); diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp index 6940580ecc..7cab7cfd10 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp @@ -20,7 +20,10 @@ void WeakRefConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 26.1.2.1 WeakRef.prototype, https://tc39.es/ecma262/#sec-weak-ref.prototype define_property(vm.names.prototype, global_object.weak_ref_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -28,6 +31,7 @@ WeakRefConstructor::~WeakRefConstructor() { } +// 26.1.1.1 WeakRef ( target ), https://tc39.es/ecma262/#sec-weak-ref-target Value WeakRefConstructor::call() { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp index 46bcde5f95..412f9a82e3 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp @@ -24,6 +24,7 @@ void WeakSetPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.delete_, delete_, 1, attr); define_native_function(vm.names.has, has, 1, attr); + // 24.4.3.5 WeakSet.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-weakset.prototype-@@tostringtag define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.WeakSet), Attribute::Configurable); } @@ -43,6 +44,7 @@ WeakSet* WeakSetPrototype::typed_this(VM& vm, GlobalObject& global_object) return static_cast<WeakSet*>(this_object); } +// 24.4.3.1 WeakSet.prototype.add ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.add JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::add) { auto* weak_set = typed_this(vm, global_object); @@ -57,6 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::add) return weak_set; } +// 24.4.3.3 WeakSet.prototype.delete ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.delete JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::delete_) { auto* weak_set = typed_this(vm, global_object); @@ -68,6 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::delete_) return Value(weak_set->values().remove(&value.as_object())); } +// 24.4.3.4 WeakSet.prototype.has ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.has JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::has) { auto* weak_set = typed_this(vm, global_object); diff --git a/Userland/Libraries/LibJS/Token.cpp b/Userland/Libraries/LibJS/Token.cpp index 3d928bbb1e..f500023ab6 100644 --- a/Userland/Libraries/LibJS/Token.cpp +++ b/Userland/Libraries/LibJS/Token.cpp @@ -203,7 +203,7 @@ bool Token::is_identifier_name() const { // IdentifierNames are Identifiers + ReservedWords // The standard defines this reversed: Identifiers are IdentifierNames except reserved words - // https://www.ecma-international.org/ecma-262/5.1/#sec-7.6 + // https://tc39.es/ecma262/#prod-Identifier return m_type == TokenType::Identifier || m_type == TokenType::Await || m_type == TokenType::BoolLiteral |