Commit 4e9daf4e authored by yangguo's avatar yangguo Committed by Commit bot

Hide RegExp and String initialization in a closure.

R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/1000063002

Cr-Commit-Position: refs/heads/master@{#27161}
parent 99f8d57f
......@@ -328,6 +328,8 @@ void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
bool RunExtraCode(Isolate* isolate, const char* utf8_source) {
// Run custom script if provided.
base::ElapsedTimer timer;
timer.Start();
TryCatch try_catch;
Local<String> source_string = String::NewFromUtf8(isolate, utf8_source);
if (try_catch.HasCaught()) return false;
......@@ -336,6 +338,11 @@ bool RunExtraCode(Isolate* isolate, const char* utf8_source) {
Local<Script> script = ScriptCompiler::Compile(isolate, &source);
if (try_catch.HasCaught()) return false;
script->Run();
if (i::FLAG_profile_deserialization) {
i::PrintF("Executing custom snapshot script took %0.3f ms\n",
timer.Elapsed().InMillisecondsF());
}
timer.Stop();
return !try_catch.HasCaught();
}
......@@ -345,6 +352,8 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
StartupData result = {NULL, 0};
{
base::ElapsedTimer timer;
timer.Start();
Isolate::Scope isolate_scope(isolate);
internal_isolate->Init(NULL);
Persistent<Context> context;
......@@ -384,6 +393,11 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
result = i::Snapshot::CreateSnapshotBlob(ser, context_ser, metadata);
}
if (i::FLAG_profile_deserialization) {
i::PrintF("Creating snapshot took %0.3f ms\n",
timer.Elapsed().InMillisecondsF());
}
timer.Stop();
}
isolate->Dispose();
return result;
......
......@@ -15,6 +15,8 @@
%CheckIsBootstrapping();
var GlobalDate = global.Date;
var GlobalRegExp = global.RegExp;
var GlobalString = global.String;
var undefined = global.undefined;
......@@ -54,7 +56,7 @@ var UNICODE_EXTENSION_RE = undefined;
function GetUnicodeExtensionRE() {
if (UNICODE_EXTENSION_RE === undefined) {
UNICODE_EXTENSION_RE = new $RegExp('-u(-[a-z0-9]{2,8})+', 'g');
UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g');
}
return UNICODE_EXTENSION_RE;
}
......@@ -66,7 +68,7 @@ var ANY_EXTENSION_RE = undefined;
function GetAnyExtensionRE() {
if (ANY_EXTENSION_RE === undefined) {
ANY_EXTENSION_RE = new $RegExp('-[a-z0-9]{1}-.*', 'g');
ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g');
}
return ANY_EXTENSION_RE;
}
......@@ -78,7 +80,7 @@ var QUOTED_STRING_RE = undefined;
function GetQuotedStringRE() {
if (QUOTED_STRING_RE === undefined) {
QUOTED_STRING_RE = new $RegExp("'[^']+'", 'g');
QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g');
}
return QUOTED_STRING_RE;
}
......@@ -91,7 +93,7 @@ var SERVICE_RE = undefined;
function GetServiceRE() {
if (SERVICE_RE === undefined) {
SERVICE_RE =
new $RegExp('^(collator|numberformat|dateformat|breakiterator)$');
new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$');
}
return SERVICE_RE;
}
......@@ -141,7 +143,7 @@ var TIMEZONE_NAME_CHECK_RE = undefined;
function GetTimezoneNameCheckRE() {
if (TIMEZONE_NAME_CHECK_RE === undefined) {
TIMEZONE_NAME_CHECK_RE =
new $RegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$');
new GlobalRegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$');
}
return TIMEZONE_NAME_CHECK_RE;
}
......@@ -289,7 +291,7 @@ function supportedLocalesOf(service, locales, options) {
var matcher = options.localeMatcher;
if (matcher !== undefined) {
matcher = $String(matcher);
matcher = GlobalString(matcher);
if (matcher !== 'lookup' && matcher !== 'best fit') {
throw new $RangeError('Illegal value for localeMatcher:' + matcher);
}
......@@ -375,7 +377,7 @@ function getGetOption(options, caller) {
value = $Boolean(value);
break;
case 'string':
value = $String(value);
value = GlobalString(value);
break;
case 'number':
value = $Number(value);
......@@ -531,7 +533,7 @@ function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) {
var extension = '';
var updateExtension = function updateExtension(key, value) {
return '-' + key + '-' + $String(value);
return '-' + key + '-' + GlobalString(value);
}
var updateProperty = function updateProperty(property, type, value) {
......@@ -620,7 +622,7 @@ function getOptimalLanguageTag(original, resolved) {
}
// Preserve extensions of resolved locale, but swap base tags with original.
var resolvedBase = new $RegExp('^' + locales[1].base);
var resolvedBase = new GlobalRegExp('^' + locales[1].base);
return resolved.replace(resolvedBase, locales[0].base);
}
......@@ -710,7 +712,7 @@ function canonicalizeLanguageTag(localeID) {
throw new $TypeError('Language ID should be string or object.');
}
var localeString = $String(localeID);
var localeString = GlobalString(localeID);
if (isValidLanguageTag(localeString) === false) {
throw new $RangeError('Invalid language tag: ' + localeString);
......@@ -839,12 +841,12 @@ function BuildLanguageTagREs() {
var privateUse = '(x(-' + alphanum + '{1,8})+)';
var singleton = '(' + digit + '|[A-WY-Za-wy-z])';
LANGUAGE_SINGLETON_RE = new $RegExp('^' + singleton + '$', 'i');
LANGUAGE_SINGLETON_RE = new GlobalRegExp('^' + singleton + '$', 'i');
var extension = '(' + singleton + '(-' + alphanum + '{2,8})+)';
var variant = '(' + alphanum + '{5,8}|(' + digit + alphanum + '{3}))';
LANGUAGE_VARIANT_RE = new $RegExp('^' + variant + '$', 'i');
LANGUAGE_VARIANT_RE = new GlobalRegExp('^' + variant + '$', 'i');
var region = '(' + alpha + '{2}|' + digit + '{3})';
var script = '(' + alpha + '{4})';
......@@ -856,7 +858,7 @@ function BuildLanguageTagREs() {
var languageTag =
'^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$';
LANGUAGE_TAG_RE = new $RegExp(languageTag, 'i');
LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i');
}
/**
......@@ -1029,7 +1031,7 @@ function initializeCollator(collator, locales, options) {
*/
function compare(collator, x, y) {
return %InternalCompare(%GetImplFromInitializedIntlObject(collator),
$String(x), $String(y));
GlobalString(x), GlobalString(y));
};
......@@ -1282,7 +1284,7 @@ function formatNumber(formatter, value) {
*/
function parseNumber(formatter, value) {
return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter),
$String(value));
GlobalString(value));
}
......@@ -1686,7 +1688,7 @@ function formatDate(formatter, dateValue) {
*/
function parseDate(formatter, value) {
return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter),
$String(value));
GlobalString(value));
}
......@@ -1847,7 +1849,7 @@ function initializeBreakIterator(iterator, locales, options) {
*/
function adoptText(iterator, text) {
%BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator),
$String(text));
GlobalString(text));
}
......@@ -1930,7 +1932,7 @@ function cachedOrNewService(service, locales, options, defaults) {
* Compares this and that, and returns less than 0, 0 or greater than 0 value.
* Overrides the built-in method.
*/
OverrideFunction($String.prototype, 'localeCompare', function(that) {
OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
if (%_IsConstructCall()) {
throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
}
......@@ -1954,14 +1956,14 @@ OverrideFunction($String.prototype, 'localeCompare', function(that) {
* If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
* a RangeError Exception.
*/
OverrideFunction($String.prototype, 'normalize', function(that) {
OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
if (%_IsConstructCall()) {
throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
}
CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
var form = $String(%_Arguments(0) || 'NFC');
var form = GlobalString(%_Arguments(0) || 'NFC');
var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
if (normalizationForm === -1) {
......
......@@ -2,13 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file relies on the fact that the following declarations have been made
// in runtime.js:
// var $Object = global.Object;
// Instance class name can only be set on functions. That is the only
// purpose for MathConstructor.
var rngstate; // Initialized to a Uint32Array during genesis.
var $abs;
......@@ -17,12 +10,17 @@ var $floor;
var $max;
var $min;
// -------------------------------------------------------------------
(function() {
"use strict";
%CheckIsBootstrapping();
var GlobalObject = global.Object;
var GlobalArray = global.Array;
//-------------------------------------------------------------------
// ECMA 262 - 15.8.2.1
function MathAbs(x) {
if (%_IsSmi(x)) return x >= 0 ? x : -x;
......@@ -293,20 +291,20 @@ function CubeRoot(x) {
// -------------------------------------------------------------------
%CheckIsBootstrapping();
// Instance class name can only be set on functions. That is the only
// purpose for MathConstructor.
function MathConstructor() {}
var Math = new MathConstructor();
%InternalSetPrototype(Math, $Object.prototype);
%InternalSetPrototype(Math, GlobalObject.prototype);
%AddNamedProperty(global, "Math", Math, DONT_ENUM);
%FunctionSetInstanceClassName(MathConstructor, 'Math');
%AddNamedProperty(Math, symbolToStringTag, "Math", READ_ONLY | DONT_ENUM);
// Set up math constants.
InstallConstants(Math, $Array(
InstallConstants(Math, GlobalArray(
// ECMA-262, section 15.8.1.1.
"E", 2.7182818284590452354,
// ECMA-262, section 15.8.1.2.
......@@ -323,7 +321,7 @@ InstallConstants(Math, $Array(
// Set up non-enumerable functions of the Math object and
// set their names.
InstallFunctions(Math, DONT_ENUM, $Array(
InstallFunctions(Math, DONT_ENUM, GlobalArray(
"random", MathRandom,
"abs", MathAbs,
"acos", MathAcosJS,
......
......@@ -442,7 +442,7 @@ function ScriptLocationFromPosition(position,
var line_ends = this.line_ends;
var start = line == 0 ? 0 : line_ends[line - 1] + 1;
var end = line_ends[line];
if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') {
if (end > 0 && %_CallFunction(this.source, end - 1, $stringCharAt) == '\r') {
end--;
}
var column = position - start;
......@@ -565,7 +565,7 @@ function ScriptSourceLine(opt_line) {
var line_ends = this.line_ends;
var start = line == 0 ? 0 : line_ends[line - 1] + 1;
var end = line_ends[line];
return %_CallFunction(this.source, start, end, StringSubstring);
return %_CallFunction(this.source, start, end, $stringSubstring);
}
......@@ -707,7 +707,7 @@ function SourceLocationSourceText() {
return %_CallFunction(this.script.source,
this.start,
this.end,
StringSubstring);
$stringSubstring);
}
......@@ -755,7 +755,7 @@ function SourceSliceSourceText() {
return %_CallFunction(this.script.source,
this.from_position,
this.to_position,
StringSubstring);
$stringSubstring);
}
SetUpLockedPrototype(SourceSlice,
......@@ -969,12 +969,12 @@ function CallSiteToString() {
var methodName = this.getMethodName();
if (functionName) {
if (typeName &&
%_CallFunction(functionName, typeName, StringIndexOfJS) != 0) {
%_CallFunction(functionName, typeName, $stringIndexOf) != 0) {
line += typeName + ".";
}
line += functionName;
if (methodName &&
(%_CallFunction(functionName, "." + methodName, StringIndexOfJS) !=
(%_CallFunction(functionName, "." + methodName, $stringIndexOf) !=
functionName.length - methodName.length - 1)) {
line += " [as " + methodName + "]";
}
......
This diff is collapsed.
......@@ -110,9 +110,9 @@ void CalculateFirstPageSizes(bool is_default_snapshot,
}
PrintF(
"Deserialization will reserve:\n"
"%*d bytes for startup\n"
"%*d bytes per context\n",
10, startup_total, 10, context_total);
"%10d bytes for startup\n"
"%10d bytes per context\n",
startup_total, context_total);
}
for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) {
......@@ -187,9 +187,9 @@ v8::StartupData Snapshot::CreateSnapshotBlob(
if (FLAG_profile_deserialization) {
PrintF(
"Snapshot blob consists of:\n"
"%*d bytes for startup\n"
"%*d bytes for context\n",
10, startup_length, 10, context_length);
"%10d bytes for startup\n"
"%10d bytes for context\n",
startup_length, context_length);
}
return result;
}
......
......@@ -2,13 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function() {
"use strict";
%CheckIsBootstrapping();
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $String = global.String;
var GlobalArray = global.Array;
var GlobalObject = global.Object;
var GlobalString = global.String;
//-------------------------------------------------------------------
var stringIteratorIteratedStringSymbol =
GLOBAL_PRIVATE("StringIterator#iteratedString");
......@@ -75,35 +79,27 @@ function StringIteratorNext() {
}
function SetUpStringIterator() {
%CheckIsBootstrapping();
%FunctionSetPrototype(StringIterator, new $Object());
%FunctionSetInstanceClassName(StringIterator, 'String Iterator');
InstallFunctions(StringIterator.prototype, DONT_ENUM, $Array(
'next', StringIteratorNext
));
%FunctionSetName(StringIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(StringIterator.prototype, symbolIterator,
StringIteratorIterator, DONT_ENUM);
%AddNamedProperty(StringIterator.prototype, symbolToStringTag,
"String Iterator", READ_ONLY | DONT_ENUM);
}
SetUpStringIterator();
// 21.1.3.27 String.prototype [ @@iterator ]( )
function StringPrototypeIterator() {
return CreateStringIterator(this);
}
//-------------------------------------------------------------------
function ExtendStringPrototypeWithIterator() {
%CheckIsBootstrapping();
%FunctionSetPrototype(StringIterator, new GlobalObject());
%FunctionSetInstanceClassName(StringIterator, 'String Iterator');
%FunctionSetName(StringPrototypeIterator, '[Symbol.iterator]');
%AddNamedProperty($String.prototype, symbolIterator,
StringPrototypeIterator, DONT_ENUM);
}
ExtendStringPrototypeWithIterator();
InstallFunctions(StringIterator.prototype, DONT_ENUM, GlobalArray(
'next', StringIteratorNext
));
%FunctionSetName(StringIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(StringIterator.prototype, symbolIterator,
StringIteratorIterator, DONT_ENUM);
%AddNamedProperty(StringIterator.prototype, symbolToStringTag,
"String Iterator", READ_ONLY | DONT_ENUM);
%FunctionSetName(StringPrototypeIterator, '[Symbol.iterator]');
%AddNamedProperty(GlobalString.prototype, symbolIterator,
StringPrototypeIterator, DONT_ENUM);
})();
This diff is collapsed.
......@@ -30,6 +30,13 @@ var rempio2result;
"use strict";
%CheckIsBootstrapping();
var GlobalMath = global.Math;
var GlobalArray = global.Array;
//-------------------------------------------------------------------
const INVPIO2 = kMath[0];
const PIO2_1 = kMath[1];
const PIO2_1T = kMath[2];
......@@ -1006,9 +1013,7 @@ function MathLog2(x) {
//-------------------------------------------------------------------
%CheckIsBootstrapping();
InstallFunctions(global.Math, DONT_ENUM, $Array(
InstallFunctions(GlobalMath, DONT_ENUM, GlobalArray(
"cos", MathCos,
"sin", MathSin,
"tan", MathTan,
......@@ -1023,4 +1028,4 @@ InstallFunctions(global.Math, DONT_ENUM, $Array(
%SetInlineBuiltinFlag(MathSin);
%SetInlineBuiltinFlag(MathCos);
})();
\ No newline at end of file
})();
......@@ -1843,7 +1843,7 @@ function NewFunctionFromString(arguments, function_token) {
// If the formal parameters string include ) - an illegal
// character - it may make the combined function expression
// compile. We avoid this problem by checking for this early on.
if (%_CallFunction(p, ')', StringIndexOfJS) != -1) {
if (%_CallFunction(p, ')', $stringIndexOf) != -1) {
throw MakeSyntaxError('paren_in_arg_string', []);
}
// If the formal parameters include an unbalanced block comment, the
......
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