mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 18:37:58 +03:00
LibJS: Implement String.prototype[@@toPrimitive]()
This commit is contained in:
parent
e9a0759b16
commit
b661363dfe
Notes:
sideshowbarker
2024-07-18 12:45:12 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b661363dfe1 Pull-request: https://github.com/SerenityOS/serenity/pull/7846
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@ -30,8 +31,8 @@ void SymbolPrototype::initialize(GlobalObject& global_object)
|
||||
define_native_property(vm.names.description, description_getter, {}, Attribute::Configurable);
|
||||
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_property(global_object.vm().well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Symbol"), Attribute::Configurable);
|
||||
define_native_function(vm.well_known_symbol_to_primitive(), symbol_to_primitive, Attribute::Configurable);
|
||||
define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Symbol"), Attribute::Configurable);
|
||||
}
|
||||
|
||||
SymbolPrototype::~SymbolPrototype()
|
||||
@ -70,4 +71,11 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of)
|
||||
{
|
||||
return this_symbol_value(global_object, vm.this_value(global_object));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::symbol_to_primitive)
|
||||
{
|
||||
// The hint argument is ignored.
|
||||
return this_symbol_value(global_object, vm.this_value(global_object));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ private:
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
JS_DECLARE_NATIVE_FUNCTION(symbol_to_primitive);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
test("basic functionality", () => {
|
||||
const s = Symbol();
|
||||
expect(s[Symbol.toPrimitive]("string")).toBe(s);
|
||||
expect(s[Symbol.toPrimitive]("number")).toBe(s);
|
||||
});
|
Loading…
Reference in New Issue
Block a user