1// Copyright 2019 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5namespace symbol { 6extern runtime SymbolDescriptiveString(implicit context: Context)(Symbol): 7 String; 8 9transitioning macro ThisSymbolValue(implicit context: Context)( 10 receiver: JSAny, method: constexpr string): Symbol { 11 return UnsafeCast<Symbol>( 12 ToThisValue(receiver, PrimitiveType::kSymbol, method)); 13} 14 15// ES #sec-symbol.prototype.description 16transitioning javascript builtin SymbolPrototypeDescriptionGetter( 17 js-implicit context: NativeContext, receiver: JSAny)(): String|Undefined { 18 // 1. Let s be the this value. 19 // 2. Let sym be ? thisSymbolValue(s). 20 const sym: Symbol = ThisSymbolValue(receiver, 'Symbol.prototype.description'); 21 // 3. Return sym.[[Description]]. 22 return sym.description; 23} 24 25// ES6 #sec-symbol.prototype-@@toprimitive 26transitioning javascript builtin SymbolPrototypeToPrimitive( 27 js-implicit context: NativeContext, receiver: JSAny)(_hint: JSAny): JSAny { 28 // 1. Return ? thisSymbolValue(this value). 29 return ThisSymbolValue(receiver, 'Symbol.prototype [ @@toPrimitive ]'); 30} 31 32// ES6 #sec-symbol.prototype.tostring 33transitioning javascript builtin SymbolPrototypeToString( 34 js-implicit context: NativeContext, receiver: JSAny)(): JSAny { 35 // 1. Let sym be ? thisSymbolValue(this value). 36 const sym: Symbol = ThisSymbolValue(receiver, 'Symbol.prototype.toString'); 37 // 2. Return SymbolDescriptiveString(sym). 38 return SymbolDescriptiveString(sym); 39} 40 41// ES6 #sec-symbol.prototype.valueof 42transitioning javascript builtin SymbolPrototypeValueOf( 43 js-implicit context: NativeContext, receiver: JSAny)(): JSAny { 44 // 1. Return ? thisSymbolValue(this value). 45 return ThisSymbolValue(receiver, 'Symbol.prototype.valueOf'); 46} 47} 48