[cleanup] Remove runtime.js, move the remainder to more logical places

This patch retires runtime.js:
  - Removes some dead code from runtime.js (ToPositiveInteger, ToIndex),
  - Moves Array.prototype initialization to prologue.js
  - Moves SpeciesConstructor to the only file that calls it (typedarray.js)
  - Renames the remainder to reflect its only inhabitants ({Max,Min}Simple)

Change-Id: If9048a30c4f6b86396bfd647bb637b4175880fc3
Reviewed-on: https://chromium-review.googlesource.com/478579
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44730}
This commit is contained in:
Adam Klein 2017-04-14 17:25:59 -07:00 committed by Commit Bot
parent 486cd04f3d
commit 468ddfa6bb
9 changed files with 59 additions and 117 deletions

View File

@ -502,7 +502,7 @@ action("js2c") {
"src/js/macros.py",
"src/messages.h",
"src/js/prologue.js",
"src/js/runtime.js",
"src/js/max-min.js",
"src/js/v8natives.js",
"src/js/array.js",
"src/js/string.js",

View File

@ -4211,11 +4211,9 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
factory()->NewStringFromAsciiChecked("isPromise"));
int builtin_index = Natives::GetDebuggerCount();
// Only run prologue.js and runtime.js at this point.
// Only run prologue.js at this point.
DCHECK_EQ(builtin_index, Natives::GetIndex("prologue"));
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
DCHECK_EQ(builtin_index, Natives::GetIndex("runtime"));
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
{
// Builtin function for OpaqueReference -- a JSValue-based object,

View File

@ -13,7 +13,7 @@ namespace internal {
// A SourceCodeCache uses a FixedArray to store pairs of
// (OneByteString*, JSFunction*), mapping names of native code files
// (runtime.js, etc.) to precompiled functions. Instead of mapping
// (array.js, etc.) to precompiled functions. Instead of mapping
// names to functions it might make sense to let the JS2C tool
// generate an index for each native JS file.
class SourceCodeCache final BASE_EMBEDDED {

View File

@ -1534,7 +1534,6 @@ class JavaScriptFrameIterator BASE_EMBEDDED {
// NOTE: The stack trace frame iterator is an iterator that only traverse proper
// JavaScript frames that have proper JavaScript functions and WASM frames.
// This excludes the problematic functions in runtime.js.
class StackTraceFrameIterator BASE_EMBEDDED {
public:
explicit StackTraceFrameIterator(Isolate* isolate);

28
src/js/max-min.js vendored Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2006-2008 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) {
%CheckIsBootstrapping();
function MaxSimple(a, b) {
return a > b ? a : b;
}
function MinSimple(a, b) {
return a > b ? b : a;
}
%SetForceInlineFlag(MaxSimple);
%SetForceInlineFlag(MinSimple);
// ----------------------------------------------------------------------------
// Exports
utils.Export(function(to) {
to.MaxSimple = MaxSimple;
to.MinSimple = MinSimple;
});
})

View File

@ -8,6 +8,13 @@
%CheckIsBootstrapping();
// NOTE: Setting the prototype for Array must take place as early as
// possible due to code generation for array literals. When
// generating code for a array literal a boilerplate array is created
// that is cloned when running the code. It is essential that the
// boilerplate gets the right prototype.
%FunctionSetPrototype(global.Array, new global.Array(0));
// -----------------------------------------------------------------------
// Utils

View File

@ -1,104 +0,0 @@
// Copyright 2006-2008 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.
// This files contains runtime support implemented in JavaScript.
// CAUTION: Some of the functions specified in this file are called
// directly from compiled code. These are the functions with names in
// ALL CAPS. The compiled code passes the first argument in 'this'.
// The following declarations are shared with other native JS files.
// They are all declared at this one spot to avoid redeclaration errors.
(function(global, utils) {
%CheckIsBootstrapping();
var GlobalArray = global.Array;
var GlobalBoolean = global.Boolean;
var GlobalString = global.String;
var speciesSymbol;
utils.Import(function(from) {
speciesSymbol = from.species_symbol;
});
// ----------------------------------------------------------------------------
/* ---------------------------------
- - - U t i l i t i e s - - -
---------------------------------
*/
function ToPositiveInteger(x, rangeErrorIndex) {
var i = TO_INTEGER(x) + 0;
if (i < 0) throw %make_range_error(rangeErrorIndex);
return i;
}
function ToIndex(x, rangeErrorIndex) {
var i = TO_INTEGER(x) + 0;
if (i < 0 || i > kMaxSafeInteger) throw %make_range_error(rangeErrorIndex);
return i;
}
function MaxSimple(a, b) {
return a > b ? a : b;
}
function MinSimple(a, b) {
return a > b ? b : a;
}
%SetForceInlineFlag(MaxSimple);
%SetForceInlineFlag(MinSimple);
// ES2015 7.3.20
function SpeciesConstructor(object, defaultConstructor) {
var constructor = object.constructor;
if (IS_UNDEFINED(constructor)) {
return defaultConstructor;
}
if (!IS_RECEIVER(constructor)) {
throw %make_type_error(kConstructorNotReceiver);
}
var species = constructor[speciesSymbol];
if (IS_NULL_OR_UNDEFINED(species)) {
return defaultConstructor;
}
if (%IsConstructor(species)) {
return species;
}
throw %make_type_error(kSpeciesNotConstructor);
}
//----------------------------------------------------------------------------
// NOTE: Setting the prototype for Array must take place as early as
// possible due to code generation for array literals. When
// generating code for a array literal a boilerplate array is created
// that is cloned when running the code. It is essential that the
// boilerplate gets the right prototype.
%FunctionSetPrototype(GlobalArray, new GlobalArray(0));
// ----------------------------------------------------------------------------
// Exports
utils.Export(function(to) {
to.MaxSimple = MaxSimple;
to.MinSimple = MinSimple;
to.ToPositiveInteger = ToPositiveInteger;
to.ToIndex = ToIndex;
to.SpeciesConstructor = SpeciesConstructor;
});
})

View File

@ -29,10 +29,8 @@ var InnerArrayToLocaleString;
var InternalArray = utils.InternalArray;
var MaxSimple;
var MinSimple;
var SpeciesConstructor;
var ToPositiveInteger;
var ToIndex;
var iteratorSymbol = utils.ImportNow("iterator_symbol");
var speciesSymbol = utils.ImportNow("species_symbol");
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
macro TYPED_ARRAYS(FUNCTION)
@ -67,11 +65,27 @@ utils.Import(function(from) {
InnerArrayToLocaleString = from.InnerArrayToLocaleString;
MaxSimple = from.MaxSimple;
MinSimple = from.MinSimple;
SpeciesConstructor = from.SpeciesConstructor;
ToPositiveInteger = from.ToPositiveInteger;
ToIndex = from.ToIndex;
});
// ES2015 7.3.20
function SpeciesConstructor(object, defaultConstructor) {
var constructor = object.constructor;
if (IS_UNDEFINED(constructor)) {
return defaultConstructor;
}
if (!IS_RECEIVER(constructor)) {
throw %make_type_error(kConstructorNotReceiver);
}
var species = constructor[speciesSymbol];
if (IS_NULL_OR_UNDEFINED(species)) {
return defaultConstructor;
}
if (%IsConstructor(species)) {
return species;
}
throw %make_type_error(kSpeciesNotConstructor);
}
// --------------- Typed Arrays ---------------------
function TypedArrayDefaultConstructor(typedArray) {

View File

@ -2298,7 +2298,7 @@
'js/macros.py',
'messages.h',
'js/prologue.js',
'js/runtime.js',
'js/max-min.js',
'js/v8natives.js',
'js/array.js',
'js/string.js',