|
|
@ -99,6 +99,12 @@ impl BuiltIn for Symbol { |
|
|
|
|
|
|
|
|
|
|
|
let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT; |
|
|
|
let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let to_primitive = FunctionBuilder::native(context, Self::to_primitive) |
|
|
|
|
|
|
|
.name("[Symbol.toPrimitive]") |
|
|
|
|
|
|
|
.length(1) |
|
|
|
|
|
|
|
.constructable(false) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
let get_description = FunctionBuilder::native(context, Self::get_description) |
|
|
|
let get_description = FunctionBuilder::native(context, Self::get_description) |
|
|
|
.name("get description") |
|
|
|
.name("get description") |
|
|
|
.constructable(false) |
|
|
|
.constructable(false) |
|
|
@ -123,7 +129,7 @@ impl BuiltIn for Symbol { |
|
|
|
.static_property("search", symbol_search, attribute) |
|
|
|
.static_property("search", symbol_search, attribute) |
|
|
|
.static_property("species", symbol_species, attribute) |
|
|
|
.static_property("species", symbol_species, attribute) |
|
|
|
.static_property("split", symbol_split, attribute) |
|
|
|
.static_property("split", symbol_split, attribute) |
|
|
|
.static_property("toPrimitive", symbol_to_primitive, attribute) |
|
|
|
.static_property("toPrimitive", symbol_to_primitive.clone(), attribute) |
|
|
|
.static_property("toStringTag", symbol_to_string_tag.clone(), attribute) |
|
|
|
.static_property("toStringTag", symbol_to_string_tag.clone(), attribute) |
|
|
|
.static_property("unscopables", symbol_unscopables, attribute) |
|
|
|
.static_property("unscopables", symbol_unscopables, attribute) |
|
|
|
.method(Self::to_string, "toString", 0) |
|
|
|
.method(Self::to_string, "toString", 0) |
|
|
@ -141,6 +147,11 @@ impl BuiltIn for Symbol { |
|
|
|
Self::NAME, |
|
|
|
Self::NAME, |
|
|
|
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, |
|
|
|
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
.property( |
|
|
|
|
|
|
|
symbol_to_primitive, |
|
|
|
|
|
|
|
to_primitive, |
|
|
|
|
|
|
|
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, |
|
|
|
|
|
|
|
) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
symbol_object.into() |
|
|
|
symbol_object.into() |
|
|
@ -316,4 +327,25 @@ impl Symbol { |
|
|
|
context.throw_type_error("Symbol.keyFor: sym is not a symbol") |
|
|
|
context.throw_type_error("Symbol.keyFor: sym is not a symbol") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// `Symbol.prototype [ @@toPrimitive ]`
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// This function is called by ECMAScript language operators to convert a Symbol object to a primitive value.
|
|
|
|
|
|
|
|
/// NOTE: The argument is ignored
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// More information:
|
|
|
|
|
|
|
|
/// - [MDN documentation][mdn]
|
|
|
|
|
|
|
|
/// - [ECMAScript reference][spec]
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/multipage/#sec-symbol.prototype-@@toprimitive
|
|
|
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/@@toPrimitive
|
|
|
|
|
|
|
|
pub(crate) fn to_primitive( |
|
|
|
|
|
|
|
this: &JsValue, |
|
|
|
|
|
|
|
_: &[JsValue], |
|
|
|
|
|
|
|
context: &mut Context, |
|
|
|
|
|
|
|
) -> JsResult<JsValue> { |
|
|
|
|
|
|
|
let sym = Self::this_symbol_value(this, context)?; |
|
|
|
|
|
|
|
// 1. Return ? thisSymbolValue(this value).
|
|
|
|
|
|
|
|
Ok(sym.into()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|