Commit ca489d39 authored by Joyee Cheung's avatar Joyee Cheung Committed by Commit Bot

[esnext] Implement Symbol.prototype.description

Proposal repo: https://github.com/tc39/proposal-symbol-description

Add new Builtin SymbolPrototypeDescriptionGetter.

Bug: v8:7807
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I7353bd00b172e91d8624e3373d2a4b55aced8b5c
Reviewed-on: https://chromium-review.googlesource.com/1088871
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53592}
parent 81e75305
......@@ -4380,6 +4380,18 @@ void Genesis::InitializeGlobal_harmony_array_flat() {
Builtins::kArrayPrototypeFlatMap, 1, false, DONT_ENUM);
}
void Genesis::InitializeGlobal_harmony_symbol_description() {
if (!FLAG_harmony_symbol_description) return;
// Symbol.prototype.description
Handle<JSFunction> symbol_fun(native_context()->symbol_function());
Handle<JSObject> symbol_prototype(
JSObject::cast(symbol_fun->instance_prototype()));
SimpleInstallGetter(isolate(), symbol_prototype,
factory()->InternalizeUtf8String("description"),
Builtins::kSymbolPrototypeDescriptionGetter, true);
}
void Genesis::InitializeGlobal_harmony_string_matchall() {
if (!FLAG_harmony_string_matchall) return;
......
......@@ -1103,6 +1103,8 @@ namespace internal {
CPP(SymbolFor) \
/* ES6 #sec-symbol.keyfor */ \
CPP(SymbolKeyFor) \
/* ES #sec-symbol.prototype.description */ \
TFJ(SymbolPrototypeDescriptionGetter, 0) \
/* ES6 #sec-symbol.prototype-@@toprimitive */ \
TFJ(SymbolPrototypeToPrimitive, 1, kHint) \
/* ES6 #sec-symbol.prototype.tostring */ \
......
......@@ -11,6 +11,16 @@ namespace internal {
// -----------------------------------------------------------------------------
// ES6 #sec-symbol-objects
// ES ##sec-symbol.prototype.description
TF_BUILTIN(SymbolPrototypeDescriptionGetter, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* receiver = Parameter(Descriptor::kReceiver);
Node* value = ToThisValue(context, receiver, PrimitiveType::kSymbol,
"Symbol.prototype.description");
Node* result = LoadObjectField(value, Symbol::kNameOffset);
Return(result);
}
// ES6 #sec-symbol.prototype-@@toprimitive
TF_BUILTIN(SymbolPrototypeToPrimitive, CodeStubAssembler) {
......
......@@ -208,10 +208,11 @@ DEFINE_IMPLICATION(harmony_class_fields, harmony_private_fields)
// Update bootstrapper.cc whenever adding a new feature flag.
// Features that are still work in progress (behind individual flags).
#define HARMONY_INPROGRESS_BASE(V) \
V(harmony_do_expressions, "harmony do-expressions") \
V(harmony_class_fields, "harmony fields in class literals") \
V(harmony_static_fields, "harmony static fields in class literals")
#define HARMONY_INPROGRESS_BASE(V) \
V(harmony_do_expressions, "harmony do-expressions") \
V(harmony_class_fields, "harmony fields in class literals") \
V(harmony_static_fields, "harmony static fields in class literals") \
V(harmony_symbol_description, "harmony Symbol.prototype.description")
#ifdef V8_INTL_SUPPORT
#define HARMONY_INPROGRESS(V) \
......
// Copyright 2018 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.
// Flags: --harmony-symbol-description
{
let desc = Object.getOwnPropertyDescriptor(Symbol.prototype, 'description');
assertEquals(desc.set, undefined);
assertEquals(desc.writable, undefined);
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
}
{
const empty = Symbol();
assertEquals(empty.description, undefined);
const symbol = Symbol('test');
assertEquals(symbol.description, 'test');
assertFalse(symbol.hasOwnProperty('description'));
}
{
const empty = Object(Symbol());
assertEquals(empty.description, undefined);
const symbol = Object(Symbol('test'));
assertEquals(symbol.description, 'test');
assertFalse(symbol.hasOwnProperty('description'));
}
{
assertThrows(function() {
const proxy = new Proxy({}, {});
Symbol.prototype.description.call(proxy);
}, TypeError);
assertThrows(function() {
const smi = 123;
Symbol.prototype.description.call(smi);
}, TypeError);
assertThrows(function() {
const str = 'string';
Symbol.prototype.description.call(string);
}, TypeError);
assertThrows(function() {
const obj = { prop: 'test' };
Symbol.prototype.description.call(obj);
}, TypeError);
}
......@@ -266,33 +266,33 @@ KNOWN_MAPS = {
("RO_SPACE", 0x05019): (172, "Tuple2Map"),
("RO_SPACE", 0x05211): (170, "ScriptMap"),
("RO_SPACE", 0x053d9): (162, "InterceptorInfoMap"),
("RO_SPACE", 0x09d21): (154, "AccessorInfoMap"),
("RO_SPACE", 0x09f31): (153, "AccessCheckInfoMap"),
("RO_SPACE", 0x09f99): (155, "AccessorPairMap"),
("RO_SPACE", 0x0a001): (156, "AliasedArgumentsEntryMap"),
("RO_SPACE", 0x0a069): (157, "AllocationMementoMap"),
("RO_SPACE", 0x0a0d1): (158, "AllocationSiteMap"),
("RO_SPACE", 0x0a139): (159, "AsyncGeneratorRequestMap"),
("RO_SPACE", 0x0a1a1): (160, "DebugInfoMap"),
("RO_SPACE", 0x0a209): (161, "FunctionTemplateInfoMap"),
("RO_SPACE", 0x0a271): (163, "InterpreterDataMap"),
("RO_SPACE", 0x0a2d9): (164, "ModuleInfoEntryMap"),
("RO_SPACE", 0x0a341): (165, "ModuleMap"),
("RO_SPACE", 0x0a3a9): (166, "ObjectTemplateInfoMap"),
("RO_SPACE", 0x0a411): (167, "PromiseCapabilityMap"),
("RO_SPACE", 0x0a479): (168, "PromiseReactionMap"),
("RO_SPACE", 0x0a4e1): (169, "PrototypeInfoMap"),
("RO_SPACE", 0x0a549): (171, "StackFrameInfoMap"),
("RO_SPACE", 0x0a5b1): (173, "Tuple3Map"),
("RO_SPACE", 0x0a619): (174, "WasmCompiledModuleMap"),
("RO_SPACE", 0x0a681): (175, "WasmDebugInfoMap"),
("RO_SPACE", 0x0a6e9): (176, "WasmExportedFunctionDataMap"),
("RO_SPACE", 0x0a751): (177, "WasmSharedModuleDataMap"),
("RO_SPACE", 0x0a7b9): (178, "CallableTaskMap"),
("RO_SPACE", 0x0a821): (179, "CallbackTaskMap"),
("RO_SPACE", 0x0a889): (180, "PromiseFulfillReactionJobTaskMap"),
("RO_SPACE", 0x0a8f1): (181, "PromiseRejectReactionJobTaskMap"),
("RO_SPACE", 0x0a959): (182, "PromiseResolveThenableJobTaskMap"),
("RO_SPACE", 0x09d59): (154, "AccessorInfoMap"),
("RO_SPACE", 0x09f69): (153, "AccessCheckInfoMap"),
("RO_SPACE", 0x09fd1): (155, "AccessorPairMap"),
("RO_SPACE", 0x0a039): (156, "AliasedArgumentsEntryMap"),
("RO_SPACE", 0x0a0a1): (157, "AllocationMementoMap"),
("RO_SPACE", 0x0a109): (158, "AllocationSiteMap"),
("RO_SPACE", 0x0a171): (159, "AsyncGeneratorRequestMap"),
("RO_SPACE", 0x0a1d9): (160, "DebugInfoMap"),
("RO_SPACE", 0x0a241): (161, "FunctionTemplateInfoMap"),
("RO_SPACE", 0x0a2a9): (163, "InterpreterDataMap"),
("RO_SPACE", 0x0a311): (164, "ModuleInfoEntryMap"),
("RO_SPACE", 0x0a379): (165, "ModuleMap"),
("RO_SPACE", 0x0a3e1): (166, "ObjectTemplateInfoMap"),
("RO_SPACE", 0x0a449): (167, "PromiseCapabilityMap"),
("RO_SPACE", 0x0a4b1): (168, "PromiseReactionMap"),
("RO_SPACE", 0x0a519): (169, "PrototypeInfoMap"),
("RO_SPACE", 0x0a581): (171, "StackFrameInfoMap"),
("RO_SPACE", 0x0a5e9): (173, "Tuple3Map"),
("RO_SPACE", 0x0a651): (174, "WasmCompiledModuleMap"),
("RO_SPACE", 0x0a6b9): (175, "WasmDebugInfoMap"),
("RO_SPACE", 0x0a721): (176, "WasmExportedFunctionDataMap"),
("RO_SPACE", 0x0a789): (177, "WasmSharedModuleDataMap"),
("RO_SPACE", 0x0a7f1): (178, "CallableTaskMap"),
("RO_SPACE", 0x0a859): (179, "CallbackTaskMap"),
("RO_SPACE", 0x0a8c1): (180, "PromiseFulfillReactionJobTaskMap"),
("RO_SPACE", 0x0a929): (181, "PromiseRejectReactionJobTaskMap"),
("RO_SPACE", 0x0a991): (182, "PromiseResolveThenableJobTaskMap"),
("MAP_SPACE", 0x02201): (1057, "ExternalMap"),
("MAP_SPACE", 0x02259): (1072, "JSMessageObjectMap"),
}
......
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