[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 <peter.wm.wong@gmail.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Cr-Commit-Position: refs/heads/master@{#50120}
This commit is contained in:
peterwmwong 2017-12-14 23:38:02 -06:00 committed by Commit Bot
parent d6e68f4334
commit ab38b03d1b
9 changed files with 61 additions and 71 deletions

View File

@ -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",

View File

@ -1697,11 +1697,10 @@ class CallNew final : public Expression {
ZoneList<Expression*>* 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<Expression*>* arguments() const { return arguments_; }

View File

@ -1493,6 +1493,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> 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);

View File

@ -762,6 +762,8 @@ namespace internal {
CPP(ObjectPrototypePropertyIsEnumerable) \
CPP(ObjectPrototypeGetProto) \
CPP(ObjectPrototypeSetProto) \
/* ES #sec-object.prototype.tolocalestring */ \
TFJ(ObjectPrototypeToLocaleString, 0) \
CPP(ObjectSeal) \
CPP(ObjectValues) \
\

View File

@ -97,6 +97,22 @@ Node* ObjectBuiltinsAssembler::ConstructDataDescriptor(Node* context,
return js_desc;
}
TF_BUILTIN(ObjectPrototypeToLocaleString, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
Label if_null_or_undefined(this, Label::kDeferred);
GotoIf(IsNullOrUndefined(receiver), &if_null_or_undefined);
TNode<Object> 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);

View File

@ -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);

View File

@ -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;
});
})

View File

@ -2354,7 +2354,6 @@
'js/macros.py',
'messages.h',
'js/prologue.js',
'js/v8natives.js',
'js/array.js',
'js/typedarray.js',
'js/messages.js',

View File

@ -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);