Commit bce199bb authored by peterwmwong's avatar peterwmwong Committed by Commit Bot

Reland "[builtins] Port Object.p.toLocaleString to CSA from JS"

This is a reland of ab38b03d
Original change's description:
> [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}

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng

TBR=adamk@chromium.org

Bug: v8:6005
Change-Id: Ie8c8810c5231e933e61ea8babe963e58bb6dcaed
Reviewed-on: https://chromium-review.googlesource.com/831156Reviewed-by: 's avatarPeter Wong <peter.wm.wong@gmail.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Cr-Commit-Position: refs/heads/master@{#50218}
parent f9eb31bb
......@@ -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",
......
......@@ -1698,11 +1698,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_; }
......
......@@ -1517,6 +1517,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory->proto_string(),
Builtins::kObjectPrototypeGetProto,
Builtins::kObjectPrototypeSetProto, DONT_ENUM);
SimpleInstallFunction(isolate->initial_object_prototype(), "toLocaleString",
Builtins::kObjectPrototypeToLocaleString, 0, true);
}
Handle<JSObject> global(native_context()->global_object());
......
......@@ -763,6 +763,8 @@ namespace internal {
CPP(ObjectPrototypePropertyIsEnumerable) \
CPP(ObjectPrototypeGetProto) \
CPP(ObjectPrototypeSetProto) \
/* ES #sec-object.prototype.tolocalestring */ \
TFJ(ObjectPrototypeToLocaleString, 0) \
CPP(ObjectSeal) \
CPP(ObjectValues) \
\
......
......@@ -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);
......
......@@ -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);
......
// 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;
});
})
......@@ -2354,7 +2354,6 @@
'js/macros.py',
'messages.h',
'js/prologue.js',
'js/v8natives.js',
'js/array.js',
'js/typedarray.js',
'js/messages.js',
......
......@@ -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);
......
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