symbol.tq 1.81 KB
Newer Older
1 2 3 4 5
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

namespace symbol {
6 7
extern runtime SymbolDescriptiveString(implicit context: Context)(Symbol):
    String;
8

9 10 11 12 13
transitioning macro ThisSymbolValue(implicit context: Context)(
    receiver: JSAny, method: constexpr string): Symbol {
  return UnsafeCast<Symbol>(
      ToThisValue(receiver, PrimitiveType::kSymbol, method));
}
14

15 16 17 18 19 20 21 22 23
// ES #sec-symbol.prototype.description
transitioning javascript builtin SymbolPrototypeDescriptionGetter(
    js-implicit context: NativeContext, receiver: JSAny)(): String|Undefined {
  // 1. Let s be the this value.
  // 2. Let sym be ? thisSymbolValue(s).
  const sym: Symbol = ThisSymbolValue(receiver, 'Symbol.prototype.description');
  // 3. Return sym.[[Description]].
  return sym.description;
}
24

25 26 27 28 29 30
// ES6 #sec-symbol.prototype-@@toprimitive
transitioning javascript builtin SymbolPrototypeToPrimitive(
    js-implicit context: NativeContext, receiver: JSAny)(_hint: JSAny): JSAny {
  // 1. Return ? thisSymbolValue(this value).
  return ThisSymbolValue(receiver, 'Symbol.prototype [ @@toPrimitive ]');
}
31

32 33 34 35 36 37 38 39
// ES6 #sec-symbol.prototype.tostring
transitioning javascript builtin SymbolPrototypeToString(
    js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
  // 1. Let sym be ? thisSymbolValue(this value).
  const sym: Symbol = ThisSymbolValue(receiver, 'Symbol.prototype.toString');
  // 2. Return SymbolDescriptiveString(sym).
  return SymbolDescriptiveString(sym);
}
40

41 42 43 44 45 46
// ES6 #sec-symbol.prototype.valueof
transitioning javascript builtin SymbolPrototypeValueOf(
    js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
  // 1. Return ? thisSymbolValue(this value).
  return ThisSymbolValue(receiver, 'Symbol.prototype.valueOf');
}
47
}