Commit bdc0a0ec authored by Gus Caplan's avatar Gus Caplan Committed by Commit Bot

[Torque] port Symbol prototype methods to Torque

Change-Id: I97ccbb29f9d4d92bb2ac20402ff8240632533989
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1864572
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64480}
parent 10b5e806
......@@ -986,6 +986,7 @@ torque_files = [
"src/builtins/string-startswith.tq",
"src/builtins/string-substring.tq",
"src/builtins/string-substr.tq",
"src/builtins/symbol.tq",
"src/builtins/torque-internal.tq",
"src/builtins/typed-array-createtypedarray.tq",
"src/builtins/typed-array-every.tq",
......@@ -1497,7 +1498,6 @@ v8_source_set("v8_initializers") {
"src/builtins/builtins-sharedarraybuffer-gen.cc",
"src/builtins/builtins-string-gen.cc",
"src/builtins/builtins-string-gen.h",
"src/builtins/builtins-symbol-gen.cc",
"src/builtins/builtins-typed-array-gen.cc",
"src/builtins/builtins-typed-array-gen.h",
"src/builtins/builtins-utils-gen.h",
......
......@@ -1451,6 +1451,8 @@ const kString: constexpr PrimitiveType
generates 'PrimitiveType::kString';
const kBoolean: constexpr PrimitiveType
generates 'PrimitiveType::kBoolean';
const kSymbol: constexpr PrimitiveType
generates 'PrimitiveType::kSymbol';
const kNameDictionaryInitialCapacity:
constexpr int32 generates 'NameDictionary::kInitialCapacity';
......
......@@ -908,14 +908,6 @@ namespace internal {
CPP(SymbolFor) \
/* ES6 #sec-symbol.keyfor */ \
CPP(SymbolKeyFor) \
/* ES #sec-symbol.prototype.description */ \
TFJ(SymbolPrototypeDescriptionGetter, 0, kReceiver) \
/* ES6 #sec-symbol.prototype-@@toprimitive */ \
TFJ(SymbolPrototypeToPrimitive, 1, kReceiver, kHint) \
/* ES6 #sec-symbol.prototype.tostring */ \
TFJ(SymbolPrototypeToString, 0, kReceiver) \
/* ES6 #sec-symbol.prototype.valueof */ \
TFJ(SymbolPrototypeValueOf, 0, kReceiver) \
\
/* TypedArray */ \
/* ES #sec-typedarray-constructors */ \
......
// Copyright 2017 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.
#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
#include "src/codegen/code-stub-assembler.h"
namespace v8 {
namespace internal {
// -----------------------------------------------------------------------------
// ES #sec-symbol-objects
// ES #sec-symbol.prototype.description
TF_BUILTIN(SymbolPrototypeDescriptionGetter, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
TNode<Symbol> value =
CAST(ToThisValue(context, receiver, PrimitiveType::kSymbol,
"Symbol.prototype.description"));
TNode<Object> result = LoadObjectField(value, Symbol::kNameOffset);
Return(result);
}
// ES6 #sec-symbol.prototype-@@toprimitive
TF_BUILTIN(SymbolPrototypeToPrimitive, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
TNode<Object> result = ToThisValue(context, receiver, PrimitiveType::kSymbol,
"Symbol.prototype [ @@toPrimitive ]");
Return(result);
}
// ES6 #sec-symbol.prototype.tostring
TF_BUILTIN(SymbolPrototypeToString, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
TNode<Object> value = ToThisValue(context, receiver, PrimitiveType::kSymbol,
"Symbol.prototype.toString");
TNode<Object> result =
CallRuntime(Runtime::kSymbolDescriptiveString, context, value);
Return(result);
}
// ES6 #sec-symbol.prototype.valueof
TF_BUILTIN(SymbolPrototypeValueOf, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
TNode<Object> result = ToThisValue(context, receiver, PrimitiveType::kSymbol,
"Symbol.prototype.valueOf");
Return(result);
}
} // namespace internal
} // namespace v8
// 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 {
extern runtime SymbolDescriptiveString(implicit context: Context)(Symbol):
String;
transitioning macro ThisSymbolValue(implicit context: Context)(
receiver: JSAny, method: constexpr string): Symbol {
return UnsafeCast<Symbol>(ToThisValue(receiver, kSymbol, method));
}
// ES #sec-symbol.prototype.description
transitioning javascript builtin SymbolPrototypeDescriptionGetter(
js-implicit context: Context, receiver: JSAny)(): JSAny {
// 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 Cast<JSAny>(sym.name) otherwise unreachable;
}
// ES6 #sec-symbol.prototype-@@toprimitive
transitioning javascript builtin SymbolPrototypeToPrimitive(
js-implicit context: Context, receiver: JSAny)(_hint: JSAny): JSAny {
// 1. Return ? thisSymbolValue(this value).
return ThisSymbolValue(receiver, 'Symbol.prototype [ @@toPrimitive ]');
}
// ES6 #sec-symbol.prototype.tostring
transitioning javascript builtin SymbolPrototypeToString(
js-implicit context: Context, 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);
}
// ES6 #sec-symbol.prototype.valueof
transitioning javascript builtin SymbolPrototypeValueOf(
js-implicit context: Context, receiver: JSAny)(): JSAny {
// 1. Return ? thisSymbolValue(this value).
return ThisSymbolValue(receiver, 'Symbol.prototype.valueOf');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment