From ab38b03d1b330678577f9d6abbc14726db34c7f3 Mon Sep 17 00:00:00 2001 From: peterwmwong Date: Thu, 14 Dec 2017 23:38:02 -0600 Subject: [PATCH] [builtins] Port Object.p.toLocaleString to CSA from JS - Added ObjectPrototypeToLocaleString TFJ - Remove v8natives.js - Move GetMethod and GetIterator into prologue.js TBR=adamk@chromium.org Bug: v8:6005 Change-Id: I2b5b65892304e62bf64375458f8ffb9473b2c9b7 Reviewed-on: https://chromium-review.googlesource.com/826479 Reviewed-by: Peter Wong Reviewed-by: Jakob Gruber Commit-Queue: Peter Wong Cr-Commit-Position: refs/heads/master@{#50120} --- BUILD.gn | 1 - src/ast/ast.h | 3 +- src/bootstrapper.cc | 2 + src/builtins/builtins-definitions.h | 2 + src/builtins/builtins-object-gen.cc | 16 ++++++++ src/js/prologue.js | 36 ++++++++++++++++ src/js/v8natives.js | 64 ----------------------------- src/v8.gyp | 1 - test/cctest/test-serialize.cc | 7 ++-- 9 files changed, 61 insertions(+), 71 deletions(-) delete mode 100644 src/js/v8natives.js diff --git a/BUILD.gn b/BUILD.gn index 9e2c0291e5..9d95b048b6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -583,7 +583,6 @@ action("js2c") { "src/js/macros.py", "src/messages.h", "src/js/prologue.js", - "src/js/v8natives.js", "src/js/array.js", "src/js/typedarray.js", "src/js/messages.js", diff --git a/src/ast/ast.h b/src/ast/ast.h index 1ca192a462..21db2032da 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -1697,11 +1697,10 @@ class CallNew final : public Expression { ZoneList* arguments_; }; - // The CallRuntime class does not represent any official JavaScript // language construct. Instead it is used to call a C or JS function // with a set of arguments. This is used from the builtins that are -// implemented in JavaScript (see "v8natives.js"). +// implemented in JavaScript. class CallRuntime final : public Expression { public: ZoneList* arguments() const { return arguments_; } diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 1b55d6f02e..5ce692cdb7 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1493,6 +1493,8 @@ void Genesis::InitializeGlobal(Handle global_object, true); SimpleInstallFunction(isolate->initial_object_prototype(), "hasOwnProperty", Builtins::kObjectPrototypeHasOwnProperty, 1, true); + SimpleInstallFunction(isolate->initial_object_prototype(), "toLocaleString", + Builtins::kObjectPrototypeToLocaleString, 0, true); SimpleInstallFunction(isolate->initial_object_prototype(), "__lookupGetter__", Builtins::kObjectLookupGetter, 1, true); diff --git a/src/builtins/builtins-definitions.h b/src/builtins/builtins-definitions.h index 63f5947080..61f1371ef1 100644 --- a/src/builtins/builtins-definitions.h +++ b/src/builtins/builtins-definitions.h @@ -762,6 +762,8 @@ namespace internal { CPP(ObjectPrototypePropertyIsEnumerable) \ CPP(ObjectPrototypeGetProto) \ CPP(ObjectPrototypeSetProto) \ + /* ES #sec-object.prototype.tolocalestring */ \ + TFJ(ObjectPrototypeToLocaleString, 0) \ CPP(ObjectSeal) \ CPP(ObjectValues) \ \ diff --git a/src/builtins/builtins-object-gen.cc b/src/builtins/builtins-object-gen.cc index 830eda9221..4cd012e6f0 100644 --- a/src/builtins/builtins-object-gen.cc +++ b/src/builtins/builtins-object-gen.cc @@ -97,6 +97,22 @@ Node* ObjectBuiltinsAssembler::ConstructDataDescriptor(Node* context, return js_desc; } +TF_BUILTIN(ObjectPrototypeToLocaleString, CodeStubAssembler) { + TNode context = CAST(Parameter(Descriptor::kContext)); + TNode receiver = CAST(Parameter(Descriptor::kReceiver)); + + Label if_null_or_undefined(this, Label::kDeferred); + GotoIf(IsNullOrUndefined(receiver), &if_null_or_undefined); + + TNode method = + CAST(GetProperty(context, receiver, factory()->toString_string())); + Return(CallJS(CodeFactory::Call(isolate()), context, method, receiver)); + + BIND(&if_null_or_undefined); + ThrowTypeError(context, MessageTemplate::kCalledOnNullOrUndefined, + "Object.prototype.toLocaleString"); +} + TF_BUILTIN(ObjectPrototypeHasOwnProperty, ObjectBuiltinsAssembler) { Node* object = Parameter(Descriptor::kReceiver); Node* key = Parameter(Descriptor::kKey); diff --git a/src/js/prologue.js b/src/js/prologue.js index 08ef3ba520..32f826691d 100644 --- a/src/js/prologue.js +++ b/src/js/prologue.js @@ -99,6 +99,42 @@ function PostNatives(utils) { utils.PostNatives = UNDEFINED; } +// ---------------------------------------------------------------------------- +// Object + +var iteratorSymbol = ImportNow("iterator_symbol"); + +// ES6 7.3.9 +function GetMethod(obj, p) { + var func = obj[p]; + if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; + if (IS_CALLABLE(func)) return func; + throw %make_type_error(kCalledNonCallable, typeof func); +} + +// ---------------------------------------------------------------------------- +// Iterator related spec functions. + +// ES6 7.4.1 GetIterator(obj, method) +function GetIterator(obj, method) { + if (IS_UNDEFINED(method)) { + method = obj[iteratorSymbol]; + } + if (!IS_CALLABLE(method)) { + throw %make_type_error(kNotIterable, obj); + } + var iterator = %_Call(method, obj); + if (!IS_RECEIVER(iterator)) { + throw %make_type_error(kNotAnIterator, iterator); + } + return iterator; +} + + +exports_container.GetIterator = GetIterator; +exports_container.GetMethod = GetMethod; + + // ----------------------------------------------------------------------- %OptimizeObjectForAddingMultipleProperties(utils, 14); diff --git a/src/js/v8natives.js b/src/js/v8natives.js deleted file mode 100644 index 26dada3759..0000000000 --- a/src/js/v8natives.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2012 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. - -(function(global, utils) { - -"use strict"; - -%CheckIsBootstrapping(); - -// ---------------------------------------------------------------------------- -// Imports - -var GlobalObject = global.Object; -var iteratorSymbol = utils.ImportNow("iterator_symbol"); - -// ---------------------------------------------------------------------------- -// Object - -// Set up non-enumerable functions on the Object.prototype object. -DEFINE_METHOD( - GlobalObject.prototype, - // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]]) - toLocaleString() { - REQUIRE_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); - return this.toString(); - } -); - -// ES6 7.3.9 -function GetMethod(obj, p) { - var func = obj[p]; - if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; - if (IS_CALLABLE(func)) return func; - throw %make_type_error(kCalledNonCallable, typeof func); -} - -// ---------------------------------------------------------------------------- -// Iterator related spec functions. - -// ES6 7.4.1 GetIterator(obj, method) -function GetIterator(obj, method) { - if (IS_UNDEFINED(method)) { - method = obj[iteratorSymbol]; - } - if (!IS_CALLABLE(method)) { - throw %make_type_error(kNotIterable, obj); - } - var iterator = %_Call(method, obj); - if (!IS_RECEIVER(iterator)) { - throw %make_type_error(kNotAnIterator, iterator); - } - return iterator; -} - -// ---------------------------------------------------------------------------- -// Exports - -utils.Export(function(to) { - to.GetIterator = GetIterator; - to.GetMethod = GetMethod; -}); - -}) diff --git a/src/v8.gyp b/src/v8.gyp index 5520fbe7e1..c00ed95abf 100644 --- a/src/v8.gyp +++ b/src/v8.gyp @@ -2354,7 +2354,6 @@ 'js/macros.py', 'messages.h', 'js/prologue.js', - 'js/v8natives.js', 'js/array.js', 'js/typedarray.js', 'js/messages.js', diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc index bb3f5faf40..4138c0f763 100644 --- a/test/cctest/test-serialize.cc +++ b/test/cctest/test-serialize.cc @@ -122,9 +122,10 @@ struct StartupBlobs { static StartupBlobs Serialize(v8::Isolate* isolate) { // We have to create one context. One reason for this is so that the builtins - // can be loaded from v8natives.js and their addresses can be processed. This - // will clear the pending fixups array, which would otherwise contain GC roots - // that would confuse the serialization/deserialization process. + // can be loaded from self hosted JS builtins and their addresses can be + // processed. This will clear the pending fixups array, which would otherwise + // contain GC roots that would confuse the serialization/deserialization + // process. v8::Isolate::Scope isolate_scope(isolate); { v8::HandleScope scope(isolate);