diff options
Diffstat (limited to 'deps/v8/src/builtins/string.tq')
-rw-r--r-- | deps/v8/src/builtins/string.tq | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/deps/v8/src/builtins/string.tq b/deps/v8/src/builtins/string.tq index dbcc5799e1..7f007680e9 100644 --- a/deps/v8/src/builtins/string.tq +++ b/deps/v8/src/builtins/string.tq @@ -7,15 +7,15 @@ namespace string { // ES6 #sec-string.prototype.tostring transitioning javascript builtin - StringPrototypeToString(js-implicit context: Context)(receiver: Object): - Object { + StringPrototypeToString(js-implicit context: Context, receiver: JSAny)(): + JSAny { return ToThisValue(receiver, kString, 'String.prototype.toString'); } // ES6 #sec-string.prototype.valueof transitioning javascript builtin - StringPrototypeValueOf(js-implicit context: Context)(receiver: Object): - Object { + StringPrototypeValueOf(js-implicit context: Context, receiver: JSAny)(): + JSAny { return ToThisValue(receiver, kString, 'String.prototype.valueOf'); } @@ -29,7 +29,8 @@ namespace string { const kind = PACKED_ELEMENTS; const stringLength: intptr = string.length_intptr; - const map: Map = LoadJSArrayElementsMap(kind, LoadNativeContext(context)); + const nativeContext = LoadNativeContext(context); + const map: Map = LoadJSArrayElementsMap(kind, nativeContext); const array: JSArray = AllocateJSArray( kind, map, stringLength, SmiTag(stringLength), kAllowLargeObjectAllocation); @@ -53,7 +54,7 @@ namespace string { } transitioning macro GenerateStringAt(implicit context: Context)( - receiver: Object, position: Object, + receiver: JSAny, position: JSAny, methodName: constexpr string): never labels IfInBounds(String, intptr, intptr), IfOutOfBounds { // Check that {receiver} is coercible to Object and convert it to a String. @@ -71,8 +72,7 @@ namespace string { // ES6 #sec-string.prototype.charat transitioning javascript builtin StringPrototypeCharAt( - js-implicit context: Context, - receiver: Object)(position: Object): Object { + js-implicit context: Context, receiver: JSAny)(position: JSAny): JSAny { try { GenerateStringAt(receiver, position, 'String.prototype.charAt') otherwise IfInBounds, IfOutOfBounds; @@ -88,8 +88,7 @@ namespace string { // ES6 #sec-string.prototype.charcodeat transitioning javascript builtin StringPrototypeCharCodeAt( - js-implicit context: Context, - receiver: Object)(position: Object): Object { + js-implicit context: Context, receiver: JSAny)(position: JSAny): JSAny { try { GenerateStringAt(receiver, position, 'String.prototype.charCodeAt') otherwise IfInBounds, IfOutOfBounds; @@ -105,8 +104,7 @@ namespace string { // ES6 #sec-string.prototype.codepointat transitioning javascript builtin StringPrototypeCodePointAt( - js-implicit context: Context, - receiver: Object)(position: Object): Object { + js-implicit context: Context, receiver: JSAny)(position: JSAny): JSAny { try { GenerateStringAt(receiver, position, 'String.prototype.codePointAt') otherwise IfInBounds, IfOutOfBounds; @@ -125,7 +123,7 @@ namespace string { // ES6 String.prototype.concat(...args) // ES6 #sec-string.prototype.concat transitioning javascript builtin StringPrototypeConcat( - js-implicit context: Context, receiver: Object)(...arguments): Object { + js-implicit context: Context, receiver: JSAny)(...arguments): JSAny { // Check that {receiver} is coercible to Object and convert it to a String. let string: String = ToThisString(receiver, 'String.prototype.concat'); @@ -137,4 +135,56 @@ namespace string { } return string; } + + extern transitioning runtime + SymbolDescriptiveString(implicit context: Context)(Symbol): String; + + // ES #sec-string-constructor + // https://tc39.github.io/ecma262/#sec-string-constructor + transitioning javascript builtin StringConstructor( + js-implicit context: Context, receiver: JSAny, newTarget: JSAny, + target: JSFunction)(...arguments): JSAny { + const length: intptr = Convert<intptr>(arguments.length); + let s: String; + // 1. If no arguments were passed to this function invocation, let s be "". + if (length == 0) { + s = EmptyStringConstant(); + } else { + // 2. Else, + // 2. a. If NewTarget is undefined and Type(value) is Symbol, return + // SymbolDescriptiveString(value). + if (newTarget == Undefined) { + typeswitch (arguments[0]) { + case (value: Symbol): { + return SymbolDescriptiveString(value); + } + case (JSAny): { + } + } + } + // 2. b. Let s be ? ToString(value). + s = ToString_Inline(context, arguments[0]); + } + // 3. If NewTarget is undefined, return s. + if (newTarget == Undefined) { + return s; + } + // 4. Return ! StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, + // "%String.prototype%")). + const map = GetDerivedMap(target, UnsafeCast<JSReceiver>(newTarget)); + const obj = + UnsafeCast<JSPrimitiveWrapper>(AllocateFastOrSlowJSObjectFromMap(map)); + obj.value = s; + return obj; + } + + transitioning builtin StringAddConvertLeft(implicit context: Context)( + left: JSAny, right: String): String { + return ToStringImpl(context, ToPrimitiveDefault(left)) + right; + } + + transitioning builtin StringAddConvertRight(implicit context: Context)( + left: String, right: JSAny): String { + return left + ToStringImpl(context, ToPrimitiveDefault(right)); + } } |