1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:37:46 +00:00

LibJS: Add the Symbol.species getter to the appropriate built-ins

This commit is contained in:
Idan Horowitz 2021-06-07 19:31:32 +03:00 committed by Linus Groh
parent 39c3aefe5d
commit aefb7995f1
10 changed files with 45 additions and 0 deletions

View file

@ -25,6 +25,8 @@ void ArrayBufferConstructor::initialize(GlobalObject& global_object)
define_property(vm.names.prototype, global_object.array_buffer_prototype(), 0); define_property(vm.names.prototype, global_object.array_buffer_prototype(), 0);
define_property(vm.names.length, Value(1), Attribute::Configurable); define_property(vm.names.length, Value(1), Attribute::Configurable);
define_native_function(vm.names.isView, is_view, 1, attr); define_native_function(vm.names.isView, is_view, 1, attr);
define_native_property(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
} }
ArrayBufferConstructor::~ArrayBufferConstructor() ArrayBufferConstructor::~ArrayBufferConstructor()
@ -62,4 +64,9 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferConstructor::is_view)
return Value(false); return Value(false);
} }
JS_DEFINE_NATIVE_GETTER(ArrayBufferConstructor::symbol_species_getter)
{
return vm.this_value(global_object);
}
} }

View file

@ -25,6 +25,8 @@ private:
virtual bool has_constructor() const override { return true; } virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(is_view); JS_DECLARE_NATIVE_FUNCTION(is_view);
JS_DECLARE_NATIVE_GETTER(symbol_species_getter);
}; };
} }

View file

@ -37,6 +37,8 @@ void ArrayConstructor::initialize(GlobalObject& global_object)
define_native_function(vm.names.from, from, 1, attr); define_native_function(vm.names.from, from, 1, attr);
define_native_function(vm.names.isArray, is_array, 1, attr); define_native_function(vm.names.isArray, is_array, 1, attr);
define_native_function(vm.names.of, of, 0, attr); define_native_function(vm.names.of, of, 0, attr);
define_native_property(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
} }
Value ArrayConstructor::call() Value ArrayConstructor::call()
@ -151,4 +153,9 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
return array; return array;
} }
JS_DEFINE_NATIVE_GETTER(ArrayConstructor::symbol_species_getter)
{
return vm.this_value(global_object);
}
} }

View file

@ -27,6 +27,8 @@ private:
JS_DECLARE_NATIVE_FUNCTION(from); JS_DECLARE_NATIVE_FUNCTION(from);
JS_DECLARE_NATIVE_FUNCTION(is_array); JS_DECLARE_NATIVE_FUNCTION(is_array);
JS_DECLARE_NATIVE_FUNCTION(of); JS_DECLARE_NATIVE_FUNCTION(of);
JS_DECLARE_NATIVE_GETTER(symbol_species_getter);
}; };
} }

View file

@ -35,6 +35,8 @@ void PromiseConstructor::initialize(GlobalObject& global_object)
// define_native_function(vm.names.race, race, 1, attr); // define_native_function(vm.names.race, race, 1, attr);
define_native_function(vm.names.reject, reject, 1, attr); define_native_function(vm.names.reject, reject, 1, attr);
define_native_function(vm.names.resolve, resolve, 1, attr); define_native_function(vm.names.resolve, resolve, 1, attr);
define_native_property(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
} }
Value PromiseConstructor::call() Value PromiseConstructor::call()
@ -113,4 +115,9 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::resolve)
return promise_resolve(global_object, *constructor, value); return promise_resolve(global_object, *constructor, value);
} }
JS_DEFINE_NATIVE_GETTER(PromiseConstructor::symbol_species_getter)
{
return vm.this_value(global_object);
}
} }

View file

@ -30,6 +30,8 @@ private:
JS_DECLARE_NATIVE_FUNCTION(race); JS_DECLARE_NATIVE_FUNCTION(race);
JS_DECLARE_NATIVE_FUNCTION(reject); JS_DECLARE_NATIVE_FUNCTION(reject);
JS_DECLARE_NATIVE_FUNCTION(resolve); JS_DECLARE_NATIVE_FUNCTION(resolve);
JS_DECLARE_NATIVE_GETTER(symbol_species_getter);
}; };
} }

View file

@ -22,6 +22,8 @@ void RegExpConstructor::initialize(GlobalObject& global_object)
NativeFunction::initialize(global_object); NativeFunction::initialize(global_object);
define_property(vm.names.prototype, global_object.regexp_prototype(), 0); define_property(vm.names.prototype, global_object.regexp_prototype(), 0);
define_property(vm.names.length, Value(2), Attribute::Configurable); define_property(vm.names.length, Value(2), Attribute::Configurable);
define_native_property(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
} }
RegExpConstructor::~RegExpConstructor() RegExpConstructor::~RegExpConstructor()
@ -51,4 +53,9 @@ Value RegExpConstructor::construct(Function&)
return RegExpObject::create(global_object(), pattern, flags); return RegExpObject::create(global_object(), pattern, flags);
} }
JS_DEFINE_NATIVE_GETTER(RegExpConstructor::symbol_species_getter)
{
return vm.this_value(global_object);
}
} }

View file

@ -23,6 +23,8 @@ public:
private: private:
virtual bool has_constructor() const override { return true; } virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_GETTER(symbol_species_getter);
}; };
} }

View file

@ -25,6 +25,8 @@ void TypedArrayConstructor::initialize(GlobalObject& global_object)
NativeFunction::initialize(global_object); NativeFunction::initialize(global_object);
define_property(vm.names.prototype, global_object.typed_array_prototype(), 0); define_property(vm.names.prototype, global_object.typed_array_prototype(), 0);
define_property(vm.names.length, Value(0), Attribute::Configurable); define_property(vm.names.length, Value(0), Attribute::Configurable);
define_native_property(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
} }
TypedArrayConstructor::~TypedArrayConstructor() TypedArrayConstructor::~TypedArrayConstructor()
@ -42,4 +44,9 @@ Value TypedArrayConstructor::construct(Function&)
return {}; return {};
} }
JS_DEFINE_NATIVE_GETTER(TypedArrayConstructor::symbol_species_getter)
{
return vm.this_value(global_object);
}
} }

View file

@ -24,6 +24,8 @@ public:
private: private:
virtual bool has_constructor() const override { return true; } virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_GETTER(symbol_species_getter);
}; };
} }