Revert of Use shared container to manage imports/exports. (patchset #2 id:20001 of https://codereview.chromium.org/1143993003/)

Reason for revert:
Breaks nosnap bots

Original issue's description:
> Use shared container to manage imports/exports.
>
> Also changed string.js and math.js to adapt this change.
>
> R=jkummerow@chromium.org
>
> Committed: https://crrev.com/e25058b0b7b9831162579564fc8935d568c1ecdd
> Cr-Commit-Position: refs/heads/master@{#28521}

TBR=yangguo@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#28523}
This commit is contained in:
jkummerow 2015-05-20 08:59:51 -07:00 committed by Commit bot
parent aca4735bec
commit 1ec5561685
41 changed files with 307 additions and 436 deletions

View File

@ -204,7 +204,6 @@ action("js2c") {
"src/macros.py",
"src/messages.h",
"src/runtime.js",
"src/prologue.js",
"src/v8natives.js",
"src/symbol.js",
"src/array.js",

View File

@ -5,7 +5,7 @@
var $iteratorCreateResultObject;
var $arrayValues;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -17,7 +17,7 @@ var $innerArrayLastIndexOf;
var $innerArrayReverse;
var $innerArraySort;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -27,14 +27,8 @@ var $innerArraySort;
// Imports
var GlobalArray = global.Array;
var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var MathMin;
utils.Import(function(from) {
MathMin = from.MathMin;
});
var InternalArray = exports.InternalArray;
var InternalPackedArray = exports.InternalPackedArray;
// -------------------------------------------------------------------
@ -268,7 +262,7 @@ function SparseMove(array, start_i, del_count, len, num_additional_args) {
// Move data to new array.
var new_array = new InternalArray(
// Clamp array length to 2^32-1 to avoid early RangeError.
MathMin(len - del_count + num_additional_args, 0xffffffff));
$min(len - del_count + num_additional_args, 0xffffffff));
var big_indices;
var indices = %GetArrayKeys(array, len);
if (IS_NUMBER(indices)) {

View File

@ -2,27 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalArrayBuffer = global.ArrayBuffer;
var GlobalObject = global.Object;
var MathMax;
var MathMin;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
});
// -------------------------------------------------------------------
function ArrayBufferConstructor(length) { // length = 1
@ -56,16 +44,16 @@ function ArrayBufferSlice(start, end) {
var first;
var byte_length = %_ArrayBufferGetByteLength(this);
if (relativeStart < 0) {
first = MathMax(byte_length + relativeStart, 0);
first = $max(byte_length + relativeStart, 0);
} else {
first = MathMin(relativeStart, byte_length);
first = $min(relativeStart, byte_length);
}
var relativeEnd = IS_UNDEFINED(end) ? byte_length : end;
var fin;
if (relativeEnd < 0) {
fin = MathMax(byte_length + relativeEnd, 0);
fin = $max(byte_length + relativeEnd, 0);
} else {
fin = MathMin(relativeEnd, byte_length);
fin = $min(relativeEnd, byte_length);
}
if (fin < first) {

View File

@ -307,15 +307,14 @@ class Genesis BASE_EMBEDDED {
FunctionMode function_mode);
void SetStrongFunctionInstanceDescriptor(Handle<Map> map);
static bool CompileBuiltin(Isolate* isolate, int index);
static bool CompileBuiltin(Isolate* isolate, int index,
Handle<JSObject> shared);
static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
static bool CompileExtraBuiltin(Isolate* isolate, int index);
static bool CompileNative(Isolate* isolate, Vector<const char> name,
Handle<String> source, int argc,
Handle<Object> argv[]);
static bool CallUtilsFunction(Isolate* isolate, const char* name);
static bool CompileExtension(Isolate* isolate, v8::Extension* extension);
Isolate* isolate_;
@ -1443,13 +1442,14 @@ void Genesis::InitializeExperimentalGlobal() {
}
bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
bool Genesis::CompileBuiltin(Isolate* isolate, int index,
Handle<JSObject> shared) {
Vector<const char> name = Natives::GetScriptName(index);
Handle<String> source_code =
isolate->bootstrapper()->SourceLookup<Natives>(index);
Handle<Object> global = isolate->global_object();
Handle<Object> utils = isolate->natives_utils_object();
Handle<Object> args[] = {global, utils};
Handle<Object> exports = isolate->builtin_exports_object();
Handle<Object> args[] = {global, shared, exports};
return CompileNative(isolate, name, source_code, arraysize(args), args);
}
@ -1460,8 +1460,8 @@ bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
Handle<String> source_code =
isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index);
Handle<Object> global = isolate->global_object();
Handle<Object> utils = isolate->natives_utils_object();
Handle<Object> args[] = {global, utils};
Handle<Object> exports = isolate->builtin_exports_object();
Handle<Object> args[] = {global, exports};
return CompileNative(isolate, name, source_code, arraysize(args), args);
}
@ -1517,17 +1517,6 @@ bool Genesis::CompileNative(Isolate* isolate, Vector<const char> name,
}
bool Genesis::CallUtilsFunction(Isolate* isolate, const char* name) {
Handle<JSObject> utils =
Handle<JSObject>::cast(isolate->natives_utils_object());
Handle<String> name_string =
isolate->factory()->NewStringFromAsciiChecked(name);
Handle<Object> fun = JSObject::GetDataProperty(utils, name_string);
Handle<Object> receiver = isolate->factory()->undefined_value();
return !Execution::Call(isolate, fun, receiver, 0, NULL).is_null();
}
bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
Factory* factory = isolate->factory();
HandleScope scope(isolate);
@ -1929,11 +1918,19 @@ bool Genesis::InstallNatives() {
native_context()->set_runtime_context(*context);
// Set up the utils object as shared container between native scripts.
Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
"utils container for native scripts");
native_context()->set_natives_utils_object(*utils);
// Set up shared object to set up cross references between native scripts.
// "shared" is used for cross references between native scripts that are part
// of the snapshot. "builtin_exports" is used for experimental natives.
Handle<JSObject> shared =
factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(shared, CLEAR_INOBJECT_PROPERTIES, 16,
"container to share between native scripts");
Handle<JSObject> builtin_exports =
factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(builtin_exports, CLEAR_INOBJECT_PROPERTIES, 16,
"container to export to experimental natives");
native_context()->set_builtin_exports_object(*builtin_exports);
Handle<JSObject> extras_exports =
factory()->NewJSObject(isolate()->object_function());
@ -1942,8 +1939,8 @@ bool Genesis::InstallNatives() {
native_context()->set_extras_exports_object(*extras_exports);
if (FLAG_expose_natives_as != NULL) {
Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils");
JSObject::AddProperty(builtins, utils_key, utils, NONE);
Handle<String> shared_key = factory()->NewStringFromAsciiChecked("shared");
JSObject::AddProperty(builtins, shared_key, shared, NONE);
}
{ // -- S c r i p t
@ -2119,12 +2116,12 @@ bool Genesis::InstallNatives() {
// transition easy to trap. Moreover, they rarely are smi-only.
{
HandleScope scope(isolate());
Handle<JSObject> utils =
Handle<JSObject>::cast(isolate()->natives_utils_object());
Handle<JSFunction> array_function =
InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS);
Handle<JSObject> builtin_exports =
Handle<JSObject>::cast(isolate()->builtin_exports_object());
Handle<JSFunction> array_function = InstallInternalArray(
builtin_exports, "InternalArray", FAST_HOLEY_ELEMENTS);
native_context()->set_internal_array_function(*array_function);
InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS);
InstallInternalArray(builtin_exports, "InternalPackedArray", FAST_ELEMENTS);
}
{ // -- S e t I t e r a t o r
@ -2224,16 +2221,17 @@ bool Genesis::InstallNatives() {
#undef INSTALL_PUBLIC_SYMBOL
}
// Install natives. Everything exported to experimental natives is also
// shared to regular natives.
TransferNamedProperties(builtin_exports, shared);
int i = Natives::GetDebuggerCount();
if (!CompileBuiltin(isolate(), i)) return false;
if (!CompileBuiltin(isolate(), i, shared)) return false;
if (!InstallJSBuiltins(builtins)) return false;
for (++i; i < Natives::GetBuiltinsCount(); ++i) {
if (!CompileBuiltin(isolate(), i)) return false;
if (!CompileBuiltin(isolate(), i, shared)) return false;
}
if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
InstallNativeFunctions();
auto function_cache =
@ -2546,8 +2544,9 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
JSObject::AddProperty(Error, name, stack_trace_limit, NONE);
// By now the utils object is useless and can be removed.
native_context->set_natives_utils_object(*factory->undefined_value());
Handle<Object> builtin_exports(native_context->builtin_exports_object(),
isolate);
native_context->set_builtin_exports_object(Smi::FromInt(0));
// Expose the natives in global if a name for it is specified.
if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
@ -2557,6 +2556,9 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
if (natives_key->AsArrayIndex(&dummy_index)) return true;
Handle<JSBuiltinsObject> natives(global->builtins());
JSObject::AddProperty(global, natives_key, natives, DONT_ENUM);
Handle<String> builtin_exports_key =
factory->NewStringFromAsciiChecked("builtin_exports");
JSObject::AddProperty(natives, builtin_exports_key, builtin_exports, NONE);
}
// Expose the stack trace symbol to native JS.

View File

@ -7,7 +7,7 @@ var $mapIteratorNext;
var $setIteratorNext;
var $setValues;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -188,7 +188,7 @@ enum BindingFlags {
V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \
V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table) \
V(NATIVES_UTILS_OBJECT_INDEX, Object, natives_utils_object) \
V(BUILTIN_EXPORTS_OBJECT_INDEX, Object, builtin_exports_object) \
V(EXTRAS_EXPORTS_OBJECT_INDEX, JSObject, extras_exports_object)
@ -428,7 +428,7 @@ class Context: public FixedArray {
SCRIPT_CONTEXT_TABLE_INDEX,
MAP_CACHE_INDEX,
TO_LENGTH_FUN_INDEX,
NATIVES_UTILS_OBJECT_INDEX,
BUILTIN_EXPORTS_OBJECT_INDEX,
EXTRAS_EXPORTS_OBJECT_INDEX,
// Properties from here are treated as weak references by the full GC.

View File

@ -10,7 +10,7 @@ var $createDate;
// -------------------------------------------------------------------
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -20,15 +20,7 @@ var $createDate;
// Imports
var GlobalDate = global.Date;
var InternalArray = utils.InternalArray;
var MathAbs;
var MathFloor;
utils.Import(function(from) {
MathAbs = from.MathAbs;
MathFloor = from.MathFloor;
});
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
@ -109,7 +101,7 @@ function MakeDate(day, time) {
// is no way that the time can be within range even after UTC
// conversion we return NaN immediately instead of relying on
// TimeClip to do it.
if (MathAbs(time) > MAX_TIME_BEFORE_UTC) return NAN;
if ($abs(time) > MAX_TIME_BEFORE_UTC) return NAN;
return time;
}
@ -117,7 +109,7 @@ function MakeDate(day, time) {
// ECMA 262 - 15.9.1.14
function TimeClip(time) {
if (!$isFinite(time)) return NAN;
if (MathAbs(time) > MAX_TIME_MS) return NAN;
if ($abs(time) > MAX_TIME_MS) return NAN;
return TO_INTEGER(time);
}
@ -244,8 +236,8 @@ function LocalTimezoneString(date) {
var timezoneOffset = -TIMEZONE_OFFSET(date);
var sign = (timezoneOffset >= 0) ? 1 : -1;
var hours = MathFloor((sign * timezoneOffset)/60);
var min = MathFloor((sign * timezoneOffset)%60);
var hours = $floor((sign * timezoneOffset)/60);
var min = $floor((sign * timezoneOffset)%60);
var gmt = ' GMT' + ((sign == 1) ? '+' : '-') +
TwoDigitString(hours) + TwoDigitString(min);
return gmt + ' (' + timezone + ')';

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, exports) {
'use strict';

View File

@ -8,54 +8,43 @@ var $innerArrayFind;
var $innerArrayFindIndex;
var $arrayFrom;
(function(global, utils) {
(function(global, exports) {
'use strict';
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalArray = global.Array;
var GlobalSymbol = global.Symbol;
var MathMax;
var MathMin;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
});
// -------------------------------------------------------------------
function InnerArrayCopyWithin(target, start, end, array, length) {
target = TO_INTEGER(target);
var to;
if (target < 0) {
to = MathMax(length + target, 0);
to = $max(length + target, 0);
} else {
to = MathMin(target, length);
to = $min(target, length);
}
start = TO_INTEGER(start);
var from;
if (start < 0) {
from = MathMax(length + start, 0);
from = $max(length + start, 0);
} else {
from = MathMin(start, length);
from = $min(start, length);
}
end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
var final;
if (end < 0) {
final = MathMax(length + end, 0);
final = $max(length + end, 0);
} else {
final = MathMin(end, length);
final = $min(end, length);
}
var count = MathMin(final - from, length - to);
var count = $min(final - from, length - to);
var direction = 1;
if (from < to && to < (from + count)) {
direction = -1;

View File

@ -3,7 +3,7 @@
// found in the LICENSE file.
//
(function(global, utils) {
(function(global, exports) {
"use strict";

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, exports) {
'use strict';

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, exports) {
'use strict';

View File

@ -5,13 +5,13 @@
var $spreadArguments;
var $spreadIterable;
(function(global, utils) {
(function(global, exports) {
'use strict';
// -------------------------------------------------------------------
// Imports
var InternalArray = utils.InternalArray;
var InternalArray = exports.InternalArray;
// -------------------------------------------------------------------

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, exports) {
"use strict";

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, exports) {
"use strict";

View File

@ -8,28 +8,19 @@
* Intl object is a single object that has some named properties,
* all of which are constructors.
*/
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalBoolean = global.Boolean;
var GlobalDate = global.Date;
var GlobalNumber = global.Number;
var GlobalRegExp = global.RegExp;
var GlobalString = global.String;
var MathFloor;
utils.Import(function(from) {
MathFloor = from.MathFloor;
});
// -------------------------------------------------------------------
var undefined = global.undefined;
var Intl = {};
@ -39,24 +30,24 @@ var Intl = {};
* Caches available locales for each service.
*/
var AVAILABLE_LOCALES = {
'collator': UNDEFINED,
'numberformat': UNDEFINED,
'dateformat': UNDEFINED,
'breakiterator': UNDEFINED
'collator': undefined,
'numberformat': undefined,
'dateformat': undefined,
'breakiterator': undefined
};
/**
* Caches default ICU locale.
*/
var DEFAULT_ICU_LOCALE = UNDEFINED;
var DEFAULT_ICU_LOCALE = undefined;
/**
* Unicode extension regular expression.
*/
var UNICODE_EXTENSION_RE = UNDEFINED;
var UNICODE_EXTENSION_RE = undefined;
function GetUnicodeExtensionRE() {
if (IS_UNDEFINED(UNDEFINED)) {
if (UNICODE_EXTENSION_RE === undefined) {
UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g');
}
return UNICODE_EXTENSION_RE;
@ -65,10 +56,10 @@ function GetUnicodeExtensionRE() {
/**
* Matches any Unicode extension.
*/
var ANY_EXTENSION_RE = UNDEFINED;
var ANY_EXTENSION_RE = undefined;
function GetAnyExtensionRE() {
if (IS_UNDEFINED(ANY_EXTENSION_RE)) {
if (ANY_EXTENSION_RE === undefined) {
ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g');
}
return ANY_EXTENSION_RE;
@ -77,10 +68,10 @@ function GetAnyExtensionRE() {
/**
* Replace quoted text (single quote, anything but the quote and quote again).
*/
var QUOTED_STRING_RE = UNDEFINED;
var QUOTED_STRING_RE = undefined;
function GetQuotedStringRE() {
if (IS_UNDEFINED(QUOTED_STRING_RE)) {
if (QUOTED_STRING_RE === undefined) {
QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g');
}
return QUOTED_STRING_RE;
@ -89,10 +80,10 @@ function GetQuotedStringRE() {
/**
* Matches valid service name.
*/
var SERVICE_RE = UNDEFINED;
var SERVICE_RE = undefined;
function GetServiceRE() {
if (IS_UNDEFINED(SERVICE_RE)) {
if (SERVICE_RE === undefined) {
SERVICE_RE =
new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$');
}
@ -103,10 +94,10 @@ function GetServiceRE() {
* Validates a language tag against bcp47 spec.
* Actual value is assigned on first run.
*/
var LANGUAGE_TAG_RE = UNDEFINED;
var LANGUAGE_TAG_RE = undefined;
function GetLanguageTagRE() {
if (IS_UNDEFINED(LANGUAGE_TAG_RE)) {
if (LANGUAGE_TAG_RE === undefined) {
BuildLanguageTagREs();
}
return LANGUAGE_TAG_RE;
@ -115,10 +106,10 @@ function GetLanguageTagRE() {
/**
* Helps find duplicate variants in the language tag.
*/
var LANGUAGE_VARIANT_RE = UNDEFINED;
var LANGUAGE_VARIANT_RE = undefined;
function GetLanguageVariantRE() {
if (IS_UNDEFINED(LANGUAGE_VARIANT_RE)) {
if (LANGUAGE_VARIANT_RE === undefined) {
BuildLanguageTagREs();
}
return LANGUAGE_VARIANT_RE;
@ -127,10 +118,10 @@ function GetLanguageVariantRE() {
/**
* Helps find duplicate singletons in the language tag.
*/
var LANGUAGE_SINGLETON_RE = UNDEFINED;
var LANGUAGE_SINGLETON_RE = undefined;
function GetLanguageSingletonRE() {
if (IS_UNDEFINED(LANGUAGE_SINGLETON_RE)) {
if (LANGUAGE_SINGLETON_RE === undefined) {
BuildLanguageTagREs();
}
return LANGUAGE_SINGLETON_RE;
@ -139,10 +130,10 @@ function GetLanguageSingletonRE() {
/**
* Matches valid IANA time zone names.
*/
var TIMEZONE_NAME_CHECK_RE = UNDEFINED;
var TIMEZONE_NAME_CHECK_RE = undefined;
function GetTimezoneNameCheckRE() {
if (IS_UNDEFINED(TIMEZONE_NAME_CHECK_RE)) {
if (TIMEZONE_NAME_CHECK_RE === undefined) {
TIMEZONE_NAME_CHECK_RE =
new GlobalRegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$');
}
@ -158,10 +149,10 @@ function addBoundMethod(obj, methodName, implementation, length) {
throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
}
var internalName = '__bound' + methodName + '__';
if (IS_UNDEFINED(this[internalName])) {
if (this[internalName] === undefined) {
var that = this;
var boundMethod;
if (IS_UNDEFINED(length) || length === 2) {
if (length === undefined || length === 2) {
boundMethod = function(x, y) {
if (%_IsConstructCall()) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
@ -220,14 +211,14 @@ function supportedLocalesOf(service, locales, options) {
}
// Provide defaults if matcher was not specified.
if (IS_UNDEFINED(options)) {
if (options === undefined) {
options = {};
} else {
options = $toObject(options);
}
var matcher = options.localeMatcher;
if (!IS_UNDEFINED(matcher)) {
if (matcher !== undefined) {
matcher = GlobalString(matcher);
if (matcher !== 'lookup' && matcher !== 'best fit') {
throw MakeRangeError(kLocaleMatcher, matcher);
@ -239,7 +230,7 @@ function supportedLocalesOf(service, locales, options) {
var requestedLocales = initializeLocaleList(locales);
// Cache these, they don't ever change per service.
if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) {
if (AVAILABLE_LOCALES[service] === undefined) {
AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
}
@ -265,7 +256,7 @@ function lookupSupportedLocalesOf(requestedLocales, availableLocales) {
// Remove -u- extension.
var locale = requestedLocales[i].replace(GetUnicodeExtensionRE(), '');
do {
if (!IS_UNDEFINED(availableLocales[locale])) {
if (availableLocales[locale] !== undefined) {
// Push requested locale not the resolved one.
matchedLocales.push(requestedLocales[i]);
break;
@ -301,10 +292,10 @@ function bestFitSupportedLocalesOf(requestedLocales, availableLocales) {
* is out of range for that property it throws RangeError.
*/
function getGetOption(options, caller) {
if (IS_UNDEFINED(options)) throw MakeError(kDefaultOptionsMissing, caller);
if (options === undefined) throw MakeError(kDefaultOptionsMissing, caller);
var getOption = function getOption(property, type, values, defaultValue) {
if (!IS_UNDEFINED(options[property])) {
if (options[property] !== undefined) {
var value = options[property];
switch (type) {
case 'boolean':
@ -319,7 +310,7 @@ function getGetOption(options, caller) {
default:
throw MakeError(kWrongValueType);
}
if (!IS_UNDEFINED(values) && values.indexOf(value) === -1) {
if (values !== undefined && values.indexOf(value) === -1) {
throw MakeRangeError(kValueOutOfRange, value, caller, property);
}
@ -373,7 +364,7 @@ function lookupMatcher(service, requestedLocales) {
}
// Cache these, they don't ever change per service.
if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) {
if (AVAILABLE_LOCALES[service] === undefined) {
AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
}
@ -381,7 +372,7 @@ function lookupMatcher(service, requestedLocales) {
// Remove all extensions.
var locale = requestedLocales[i].replace(GetAnyExtensionRE(), '');
do {
if (!IS_UNDEFINED(AVAILABLE_LOCALES[service][locale])) {
if (AVAILABLE_LOCALES[service][locale] !== undefined) {
// Return the resolved locale and extension.
var extensionMatch = requestedLocales[i].match(GetUnicodeExtensionRE());
var extension = IS_NULL(extensionMatch) ? '' : extensionMatch[0];
@ -397,7 +388,7 @@ function lookupMatcher(service, requestedLocales) {
}
// Didn't find a match, return default.
if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) {
if (DEFAULT_ICU_LOCALE === undefined) {
DEFAULT_ICU_LOCALE = %GetDefaultICULocale();
}
@ -432,16 +423,16 @@ function parseExtension(extension) {
// Key is {2}alphanum, value is {3,8}alphanum.
// Some keys may not have explicit values (booleans).
var extensionMap = {};
var previousKey = UNDEFINED;
var previousKey = undefined;
for (var i = 2; i < extensionSplit.length; ++i) {
var length = extensionSplit[i].length;
var element = extensionSplit[i];
if (length === 2) {
extensionMap[element] = UNDEFINED;
extensionMap[element] = undefined;
previousKey = element;
} else if (length >= 3 && length <=8 && !IS_UNDEFINED(previousKey)) {
} else if (length >= 3 && length <=8 && previousKey !== undefined) {
extensionMap[previousKey] = element;
previousKey = UNDEFINED;
previousKey = undefined;
} else {
// There is a value that's too long, or that doesn't have a key.
return {};
@ -474,21 +465,21 @@ function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) {
value = (value === 'true') ? true : false;
}
if (!IS_UNDEFINED(property)) {
if (property !== undefined) {
defineWEProperty(outOptions, property, value);
}
}
for (var key in keyValues) {
if (keyValues.hasOwnProperty(key)) {
var value = UNDEFINED;
var value = undefined;
var map = keyValues[key];
if (!IS_UNDEFINED(map.property)) {
if (map.property !== undefined) {
// This may return true if user specifies numeric: 'false', since
// Boolean('nonempty') === true.
value = getOption(map.property, map.type, map.values);
}
if (!IS_UNDEFINED(value)) {
if (value !== undefined) {
updateProperty(map.property, map.type, value);
extension += updateExtension(key, value);
continue;
@ -498,7 +489,7 @@ function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) {
// values (not a user error).
if (extensionMap.hasOwnProperty(key)) {
value = extensionMap[key];
if (!IS_UNDEFINED(value)) {
if (value !== undefined) {
updateProperty(map.property, map.type, value);
extension += updateExtension(key, value);
} else if (map.type === 'boolean') {
@ -599,7 +590,7 @@ function defineWEProperty(object, property, value) {
* Sets configurable descriptor to false.
*/
function addWEPropertyIfDefined(object, property, value) {
if (!IS_UNDEFINED(value)) {
if (value !== undefined) {
defineWEProperty(object, property, value);
}
}
@ -621,7 +612,7 @@ function defineWECProperty(object, property, value) {
* Sets all descriptors to true.
*/
function addWECPropertyIfDefined(object, property, value) {
if (!IS_UNDEFINED(value)) {
if (value !== undefined) {
defineWECProperty(object, property, value);
}
}
@ -669,7 +660,7 @@ function canonicalizeLanguageTag(localeID) {
*/
function initializeLocaleList(locales) {
var seen = [];
if (IS_UNDEFINED(locales)) {
if (locales === undefined) {
// Constructor is called without arguments.
seen = [];
} else {
@ -802,7 +793,7 @@ function initializeCollator(collator, locales, options) {
throw MakeTypeError(kReinitializeIntl, "Collator");
}
if (IS_UNDEFINED(options)) {
if (options === undefined) {
options = {};
}
@ -815,13 +806,13 @@ function initializeCollator(collator, locales, options) {
var sensitivity = getOption('sensitivity', 'string',
['base', 'accent', 'case', 'variant']);
if (IS_UNDEFINED(sensitivity) && internalOptions.usage === 'sort') {
if (sensitivity === undefined && internalOptions.usage === 'sort') {
sensitivity = 'variant';
}
defineWEProperty(internalOptions, 'sensitivity', sensitivity);
defineWEProperty(internalOptions, 'ignorePunctuation', getOption(
'ignorePunctuation', 'boolean', UNDEFINED, false));
'ignorePunctuation', 'boolean', undefined, false));
var locale = resolveLocale('collator', locales, options);
@ -1007,12 +998,12 @@ function isWellFormedCurrencyCode(currency) {
*/
function getNumberOption(options, property, min, max, fallback) {
var value = options[property];
if (!IS_UNDEFINED(value)) {
if (value !== undefined) {
value = GlobalNumber(value);
if ($isNaN(value) || value < min || value > max) {
throw MakeRangeError(kPropertyValueOutOfRange, property);
}
return MathFloor(value);
return $floor(value);
}
return fallback;
@ -1028,7 +1019,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
throw MakeTypeError(kReinitializeIntl, "NumberFormat");
}
if (IS_UNDEFINED(options)) {
if (options === undefined) {
options = {};
}
@ -1041,11 +1032,11 @@ function initializeNumberFormat(numberFormat, locales, options) {
'style', 'string', ['decimal', 'percent', 'currency'], 'decimal'));
var currency = getOption('currency', 'string');
if (!IS_UNDEFINED(currency) && !isWellFormedCurrencyCode(currency)) {
if (currency !== undefined && !isWellFormedCurrencyCode(currency)) {
throw MakeRangeError(kInvalidCurrencyCode, currency);
}
if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) {
if (internalOptions.style === 'currency' && currency === undefined) {
throw MakeTypeError(kCurrencyCode);
}
@ -1068,7 +1059,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
var mnsd = options['minimumSignificantDigits'];
var mxsd = options['maximumSignificantDigits'];
if (!IS_UNDEFINED(mnsd) || !IS_UNDEFINED(mxsd)) {
if (mnsd !== undefined || mxsd !== undefined) {
mnsd = getNumberOption(options, 'minimumSignificantDigits', 1, 21, 0);
defineWEProperty(internalOptions, 'minimumSignificantDigits', mnsd);
@ -1078,7 +1069,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
// Grouping.
defineWEProperty(internalOptions, 'useGrouping', getOption(
'useGrouping', 'boolean', UNDEFINED, true));
'useGrouping', 'boolean', undefined, true));
// ICU prefers options to be passed using -u- extension key/values for
// number format, so we need to build that.
@ -1089,7 +1080,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
* for a number format.
*/
var NUMBER_FORMAT_KEY_MAP = {
'nu': {'property': UNDEFINED, 'type': 'string'}
'nu': {'property': undefined, 'type': 'string'}
};
var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP,
@ -1109,10 +1100,10 @@ function initializeNumberFormat(numberFormat, locales, options) {
useGrouping: {writable: true}
});
if (internalOptions.hasOwnProperty('minimumSignificantDigits')) {
defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED);
defineWEProperty(resolved, 'minimumSignificantDigits', undefined);
}
if (internalOptions.hasOwnProperty('maximumSignificantDigits')) {
defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
defineWEProperty(resolved, 'maximumSignificantDigits', undefined);
}
var formatter = %CreateNumberFormat(requestedLocale,
internalOptions,
@ -1281,7 +1272,7 @@ function toLDMLString(options) {
var hr12 = getOption('hour12', 'boolean');
option = getOption('hour', 'string', ['2-digit', 'numeric']);
if (IS_UNDEFINED(hr12)) {
if (hr12 === undefined) {
ldmlString += appendToLDMLString(option, {'2-digit': 'jj', 'numeric': 'j'});
} else if (hr12 === true) {
ldmlString += appendToLDMLString(option, {'2-digit': 'hh', 'numeric': 'h'});
@ -1306,7 +1297,7 @@ function toLDMLString(options) {
* Returns either LDML equivalent of the current option or empty string.
*/
function appendToLDMLString(option, pairs) {
if (!IS_UNDEFINED(option)) {
if (option !== undefined) {
return pairs[option];
} else {
return '';
@ -1380,7 +1371,7 @@ function fromLDMLString(ldmlString) {
function appendToDateTimeObject(options, option, match, pairs) {
if (IS_NULL(match)) {
if (!options.hasOwnProperty(option)) {
defineWEProperty(options, option, UNDEFINED);
defineWEProperty(options, option, undefined);
}
return options;
}
@ -1396,7 +1387,7 @@ function appendToDateTimeObject(options, option, match, pairs) {
* Returns options with at least default values in it.
*/
function toDateTimeOptions(options, required, defaults) {
if (IS_UNDEFINED(options)) {
if (options === undefined) {
options = {};
} else {
options = TO_OBJECT_INLINE(options);
@ -1404,14 +1395,14 @@ function toDateTimeOptions(options, required, defaults) {
var needsDefault = true;
if ((required === 'date' || required === 'any') &&
(!IS_UNDEFINED(options.weekday) || !IS_UNDEFINED(options.year) ||
!IS_UNDEFINED(options.month) || !IS_UNDEFINED(options.day))) {
(options.weekday !== undefined || options.year !== undefined ||
options.month !== undefined || options.day !== undefined)) {
needsDefault = false;
}
if ((required === 'time' || required === 'any') &&
(!IS_UNDEFINED(options.hour) || !IS_UNDEFINED(options.minute) ||
!IS_UNDEFINED(options.second))) {
(options.hour !== undefined || options.minute !== undefined ||
options.second !== undefined)) {
needsDefault = false;
}
@ -1459,7 +1450,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
throw MakeTypeError(kReinitializeIntl, "DateTimeFormat");
}
if (IS_UNDEFINED(options)) {
if (options === undefined) {
options = {};
}
@ -1492,8 +1483,8 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
* for a date/time format.
*/
var DATETIME_FORMAT_KEY_MAP = {
'ca': {'property': UNDEFINED, 'type': 'string'},
'nu': {'property': UNDEFINED, 'type': 'string'}
'ca': {'property': undefined, 'type': 'string'},
'nu': {'property': undefined, 'type': 'string'}
};
var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP,
@ -1523,7 +1514,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
var formatter = %CreateDateTimeFormat(
requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
if (!IS_UNDEFINED(tz) && tz !== resolved.timeZone) {
if (tz !== undefined && tz !== resolved.timeZone) {
throw MakeRangeError(kUnsupportedTimeZone, tz);
}
@ -1589,7 +1580,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
var format = this;
var fromPattern = fromLDMLString(format.resolved.pattern);
var userCalendar = ICU_CALENDAR_MAP[format.resolved.calendar];
if (IS_UNDEFINED(userCalendar)) {
if (userCalendar === undefined) {
// Use ICU name if we don't have a match. It shouldn't happen, but
// it would be too strict to throw for this.
userCalendar = format.resolved.calendar;
@ -1653,7 +1644,7 @@ $setFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf');
*/
function formatDate(formatter, dateValue) {
var dateMs;
if (IS_UNDEFINED(dateValue)) {
if (dateValue === undefined) {
dateMs = GlobalDate.now();
} else {
dateMs = $toNumber(dateValue);
@ -1689,7 +1680,7 @@ addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1);
*/
function canonicalizeTimeZoneID(tzID) {
// Skip undefined zones.
if (IS_UNDEFINED(tzID)) {
if (tzID === undefined) {
return tzID;
}
@ -1707,7 +1698,7 @@ function canonicalizeTimeZoneID(tzID) {
var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]);
var i = 3;
while (!IS_UNDEFINED(match[i]) && i < match.length) {
while (match[i] !== undefined && i < match.length) {
result = result + '_' + toTitleCaseWord(match[i]);
i++;
}
@ -1724,7 +1715,7 @@ function initializeBreakIterator(iterator, locales, options) {
throw MakeTypeError(kReinitializeIntl, "v8BreakIterator");
}
if (IS_UNDEFINED(options)) {
if (options === undefined) {
options = {};
}
@ -1887,11 +1878,11 @@ var savedObjects = {
// Default (created with undefined locales and options parameters) collator,
// number and date format instances. They'll be created as needed.
var defaultObjects = {
'collator': UNDEFINED,
'numberformat': UNDEFINED,
'dateformatall': UNDEFINED,
'dateformatdate': UNDEFINED,
'dateformattime': UNDEFINED,
'collator': undefined,
'numberformat': undefined,
'dateformatall': undefined,
'dateformatdate': undefined,
'dateformattime': undefined,
};
@ -1900,9 +1891,9 @@ var defaultObjects = {
* We cache only default instances (where no locales or options are provided).
*/
function cachedOrNewService(service, locales, options, defaults) {
var useOptions = (IS_UNDEFINED(defaults)) ? options : defaults;
if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) {
if (IS_UNDEFINED(defaultObjects[service])) {
var useOptions = (defaults === undefined) ? options : defaults;
if (locales === undefined && options === undefined) {
if (defaultObjects[service] === undefined) {
defaultObjects[service] = new savedObjects[service](locales, useOptions);
}
return defaultObjects[service];

View File

@ -4,7 +4,7 @@
var $iteratorPrototype;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
%CheckIsBootstrapping();

View File

@ -4,7 +4,7 @@
var $jsonSerializeAdapter;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -14,15 +14,7 @@ var $jsonSerializeAdapter;
// Imports
var GlobalJSON = global.JSON;
var InternalArray = utils.InternalArray;
var MathMax;
var MathMin;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
});
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
@ -191,7 +183,7 @@ function JSONStringify(value, replacer, space) {
}
var gap;
if (IS_NUMBER(space)) {
space = MathMax(0, MathMin($toInteger(space), 10));
space = $max(0, $min($toInteger(space), 10));
gap = %_SubString(" ", 0, space);
} else if (IS_STRING(space)) {
if (space.length > 10) {

View File

@ -4,7 +4,13 @@
var rngstate; // Initialized to a Uint32Array during genesis.
(function(global, utils) {
var $abs;
var $exp;
var $floor;
var $max;
var $min;
(function(global, shared, exports) {
"use strict";
@ -14,7 +20,7 @@ var rngstate; // Initialized to a Uint32Array during genesis.
// Imports
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var InternalArray = shared.InternalArray;
//-------------------------------------------------------------------
@ -351,15 +357,11 @@ $installFunctions(Math, DONT_ENUM, [
%SetForceInlineFlag(MathSqrtJS);
%SetForceInlineFlag(MathTrunc);
// -------------------------------------------------------------------
// Exports
utils.Export(function(to) {
to.MathAbs = MathAbs;
to.MathExp = MathExp;
to.MathFloor = MathFloorJS;
to.MathMax = MathMax;
to.MathMin = MathMin;
});
// Expose to the global scope.
$abs = MathAbs;
$exp = MathExp;
$floor = MathFloorJS;
$max = MathMax;
$min = MathMin;
})

View File

@ -31,7 +31,7 @@ var MakeReferenceErrorEmbedded;
var MakeSyntaxErrorEmbedded;
var MakeTypeErrorEmbedded;
(function(global, utils) {
(function(global, shared, exports) {
%CheckIsBootstrapping();
@ -39,17 +39,7 @@ var MakeTypeErrorEmbedded;
// Imports
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var StringCharAt;
var StringIndexOf;
var StringSubstring;
utils.Import(function(from) {
StringCharAt = from.StringCharAt;
StringIndexOf = from.StringIndexOf;
StringSubstring = from.StringSubstring;
});
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
@ -255,7 +245,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;
@ -378,7 +368,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);
}
@ -469,7 +459,7 @@ function SourceLocationSourceText() {
return %_CallFunction(this.script.source,
this.start,
this.end,
StringSubstring);
$stringSubstring);
}
@ -514,7 +504,7 @@ function SourceSliceSourceText() {
return %_CallFunction(this.script.source,
this.from_position,
this.to_position,
StringSubstring);
$stringSubstring);
}
$setUpLockedPrototype(SourceSlice,
@ -689,12 +679,12 @@ function CallSiteToString() {
var methodName = this.getMethodName();
if (functionName) {
if (typeName &&
%_CallFunction(functionName, typeName, StringIndexOf) != 0) {
%_CallFunction(functionName, typeName, $stringIndexOf) != 0) {
line += typeName + ".";
}
line += functionName;
if (methodName &&
(%_CallFunction(functionName, "." + methodName, StringIndexOf) !=
(%_CallFunction(functionName, "." + methodName, $stringIndexOf) !=
functionName.length - methodName.length - 1)) {
line += " [as " + methodName + "]";
}

View File

@ -10,7 +10,7 @@ var $observeNativeObjectObserve;
var $observeNativeObjectGetNotifier;
var $observeNativeObjectNotifierPerformChange;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -21,7 +21,7 @@ var $observeNativeObjectNotifierPerformChange;
var GlobalArray = global.Array;
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------

View File

@ -1,57 +0,0 @@
// Copyright 2015 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();
// -----------------------------------------------------------------------
// Utils
var imports = UNDEFINED;
var exports = UNDEFINED;
utils.Export = function Export(f) {
f.next = exports;
exports = f;
};
utils.Import = function Import(f) {
f.next = imports;
imports = f;
};
// -----------------------------------------------------------------------
// To be called by bootstrapper
utils.PostNatives = function() {
%CheckIsBootstrapping();
var container = {};
for ( ; !IS_UNDEFINED(exports); exports = exports.next) exports(container);
for ( ; !IS_UNDEFINED(imports); imports = imports.next) imports(container);
var expose_to_experimental = [
"MathMax",
"MathMin",
];
var experimental = {};
%OptimizeObjectForAddingMultipleProperties(
experimental, expose_to_experimental.length);
for (var key of expose_to_experimental) experimental[key] = container[key];
%ToFastProperties(experimental);
container = UNDEFINED;
utils.Export = UNDEFINED;
utils.PostNatives = UNDEFINED;
utils.Import = function ImportFromExperimental(f) {
f(experimental);
};
};
})

View File

@ -12,7 +12,7 @@ var $promiseHasUserDefinedRejectHandler;
var $promiseStatus;
var $promiseValue;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -21,7 +21,7 @@ var $promiseValue;
// -------------------------------------------------------------------
// Imports
var InternalArray = utils.InternalArray;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------

View File

@ -10,7 +10,7 @@ var $proxyDerivedKeysTrap;
var $proxyDerivedSetTrap;
var $proxyEnumerate;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -9,7 +9,7 @@ var $regexpLastMatchInfoOverride;
var harmony_regexps = false;
var harmony_unicode_regexps = false;
(function(global, utils) {
(function(global, shared, exports) {
%CheckIsBootstrapping();
@ -17,7 +17,7 @@ var harmony_unicode_regexps = false;
// Imports
var GlobalRegExp = global.RegExp;
var InternalPackedArray = utils.InternalPackedArray;
var InternalPackedArray = shared.InternalPackedArray;
// -------------------------------------------------------------------

View File

@ -85,7 +85,7 @@ var $toPrimitive;
var $toString;
var $toUint32;
(function(global, utils) {
(function(global, shared, exports) {
%CheckIsBootstrapping();

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
var $stringCharAt;
var $stringIndexOf;
var $stringSubstring;
(function(global, shared, exports) {
%CheckIsBootstrapping();
@ -11,16 +15,8 @@
var GlobalRegExp = global.RegExp;
var GlobalString = global.String;
var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var MathMax;
var MathMin;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
});
var InternalArray = shared.InternalArray;
var InternalPackedArray = shared.InternalPackedArray;
//-------------------------------------------------------------------
@ -972,7 +968,7 @@ function StringStartsWith(searchString /* position */) { // length == 1
}
var s_len = s.length;
var start = MathMin(MathMax(pos, 0), s_len);
var start = $min($max(pos, 0), s_len);
var ss_len = ss.length;
if (ss_len + start > s_len) {
return false;
@ -1002,7 +998,7 @@ function StringEndsWith(searchString /* position */) { // length == 1
}
}
var end = MathMin(MathMax(pos, 0), s_len);
var end = $min($max(pos, 0), s_len);
var ss_len = ss.length;
var start = end - ss_len;
if (start < 0) {
@ -1031,7 +1027,7 @@ function StringIncludes(searchString /* position */) { // length == 1
}
var s_len = s.length;
var start = MathMin(MathMax(pos, 0), s_len);
var start = $min($max(pos, 0), s_len);
var ss_len = ss.length;
if (ss_len + start > s_len) {
return false;
@ -1176,13 +1172,8 @@ $installFunctions(GlobalString.prototype, DONT_ENUM, [
"sup", StringSup
]);
// -------------------------------------------------------------------
// Exports
utils.Export(function(to) {
to.StringCharAt = StringCharAtJS;
to.StringIndexOf = StringIndexOfJS;
to.StringSubstring = StringSubstring;
});
$stringCharAt = StringCharAtJS;
$stringIndexOf = StringIndexOfJS;
$stringSubstring = StringSubstring;
})

View File

@ -12,7 +12,7 @@
var $symbolToString;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -6,7 +6,7 @@
var $getTemplateCallSite;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -16,7 +16,7 @@ var $getTemplateCallSite;
// Imports
var GlobalMap = global.Map;
var InternalArray = utils.InternalArray;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------

View File

@ -26,26 +26,15 @@
var kMath;
var rempio2result;
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalMath = global.Math;
var MathAbs;
var MathExp;
utils.Import(function(from) {
MathAbs = from.MathAbs;
MathExp = from.MathExp;
});
// -------------------------------------------------------------------
//-------------------------------------------------------------------
define INVPIO2 = kMath[0];
define PIO2_1 = kMath[1];
@ -98,7 +87,7 @@ macro REMPIO2(X)
}
} else if (ix <= 0x413921fb) {
// |X| ~<= 2^19*(pi/2), medium size
var t = MathAbs(X);
var t = $abs(X);
n = (t * INVPIO2 + 0.5) | 0;
var r = t - n * PIO2_1;
var w = n * PIO2_1T;
@ -280,7 +269,7 @@ function KernelTan(x, y, returnTan) {
if (ix < 0x3e300000) { // |x| < 2^-28
if (((ix | %_DoubleLo(x)) | (returnTan + 1)) == 0) {
// x == 0 && returnTan = -1
return 1 / MathAbs(x);
return 1 / $abs(x);
} else {
if (returnTan == 1) {
return x;
@ -768,7 +757,7 @@ function MathSinh(x) {
x = x * 1; // Convert to number.
var h = (x < 0) ? -0.5 : 0.5;
// |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1))
var ax = MathAbs(x);
var ax = $abs(x);
if (ax < 22) {
// For |x| < 2^-28, sinh(x) = x
if (ax < TWO_M28) return x;
@ -777,11 +766,11 @@ function MathSinh(x) {
return h * (t + t / (t + 1));
}
// |x| in [22, log(maxdouble)], return 0.5 * exp(|x|)
if (ax < LOG_MAXD) return h * MathExp(ax);
if (ax < LOG_MAXD) return h * $exp(ax);
// |x| in [log(maxdouble), overflowthreshold]
// overflowthreshold = 710.4758600739426
if (ax <= KSINH_OVERFLOW) {
var w = MathExp(0.5 * ax);
var w = $exp(0.5 * ax);
var t = h * w;
return t * w;
}
@ -819,7 +808,7 @@ function MathCosh(x) {
var ix = %_DoubleHi(x) & 0x7fffffff;
// |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|))
if (ix < 0x3fd62e43) {
var t = MathExpm1(MathAbs(x));
var t = MathExpm1($abs(x));
var w = 1 + t;
// For |x| < 2^-55, cosh(x) = 1
if (ix < 0x3c800000) return w;
@ -827,14 +816,14 @@ function MathCosh(x) {
}
// |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2
if (ix < 0x40360000) {
var t = MathExp(MathAbs(x));
var t = $exp($abs(x));
return 0.5 * t + 0.5 / t;
}
// |x| in [22, log(maxdouble)], return half*exp(|x|)
if (ix < 0x40862e42) return 0.5 * MathExp(MathAbs(x));
if (ix < 0x40862e42) return 0.5 * $exp($abs(x));
// |x| in [log(maxdouble), overflowthreshold]
if (MathAbs(x) <= KCOSH_OVERFLOW) {
var w = MathExp(0.5 * MathAbs(x));
if ($abs(x) <= KCOSH_OVERFLOW) {
var w = $exp(0.5 * $abs(x));
var t = 0.5 * w;
return t * w;
}
@ -937,7 +926,7 @@ define TWO53 = 9007199254740992;
function MathLog2(x) {
x = x * 1; // Convert to number.
var ax = MathAbs(x);
var ax = $abs(x);
var hx = %_DoubleHi(x);
var lx = %_DoubleLo(x);
var ix = hx & 0x7fffffff;

View File

@ -2,31 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalArray = global.Array;
var GlobalArrayBuffer = global.ArrayBuffer;
var GlobalDataView = global.DataView;
var GlobalObject = global.Object;
var MathMax;
var MathMin;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
});
// -------------------------------------------------------------------
macro TYPED_ARRAYS(FUNCTION)
// arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
FUNCTION(1, Uint8Array, 1)
@ -179,16 +165,16 @@ function NAMESubArray(begin, end) {
var srcLength = %_TypedArrayGetLength(this);
if (beginInt < 0) {
beginInt = MathMax(0, srcLength + beginInt);
beginInt = $max(0, srcLength + beginInt);
} else {
beginInt = MathMin(srcLength, beginInt);
beginInt = $min(srcLength, beginInt);
}
var endInt = IS_UNDEFINED(end) ? srcLength : end;
if (endInt < 0) {
endInt = MathMax(0, srcLength + endInt);
endInt = $max(0, srcLength + endInt);
} else {
endInt = MathMin(endInt, srcLength);
endInt = $min(endInt, srcLength);
}
if (endInt < beginInt) {
endInt = beginInt;

View File

@ -5,7 +5,7 @@
// This file contains support for URI manipulations written in
// JavaScript.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";
@ -16,7 +16,7 @@
var GlobalObject = global.Object;
var GlobalArray = global.Array;
var InternalArray = utils.InternalArray;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
// Define internal helper functions.

View File

@ -32,7 +32,7 @@ var $setUpLockedPrototype;
var $toCompletePropertyDescriptor;
var $toNameArray;
(function(global, utils) {
(function(global, shared, exports) {
%CheckIsBootstrapping();
@ -44,15 +44,7 @@ var GlobalBoolean = global.Boolean;
var GlobalFunction = global.Function;
var GlobalNumber = global.Number;
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var MathAbs;
var StringIndexOf;
utils.Import(function(from) {
MathAbs = from.MathAbs;
StringIndexOf = from.StringIndexOf;
});
var InternalArray = shared.InternalArray;
// ----------------------------------------------------------------------------
@ -1705,7 +1697,7 @@ function NumberIsSafeInteger(number) {
if (NumberIsFinite(number)) {
var integral = TO_INTEGER(number);
if (integral == number) {
return MathAbs(integral) <= GlobalNumber.MAX_SAFE_INTEGER;
return $abs(integral) <= GlobalNumber.MAX_SAFE_INTEGER;
}
}
return false;
@ -1890,7 +1882,7 @@ function NewFunctionString(args, 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, ')', StringIndexOf) != -1) {
if (%_CallFunction(p, ')', $stringIndexOf) != -1) {
throw MakeSyntaxError(kParenthesisInArgString);
}
// If the formal parameters include an unbalanced block comment, the

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
(function(global, shared, exports) {
"use strict";

View File

@ -5410,11 +5410,19 @@ TEST(PreprocessStackTrace) {
}
static bool utils_has_been_collected = false;
static bool shared_has_been_collected = false;
static bool builtin_exports_has_been_collected = false;
static void UtilsHasBeenCollected(
static void SharedHasBeenCollected(
const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
utils_has_been_collected = true;
shared_has_been_collected = true;
data.GetParameter()->Reset();
}
static void BuiltinExportsHasBeenCollected(
const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
builtin_exports_has_been_collected = true;
data.GetParameter()->Reset();
}
@ -5426,50 +5434,30 @@ TEST(BootstrappingExports) {
if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return;
utils_has_been_collected = false;
shared_has_been_collected = false;
builtin_exports_has_been_collected = false;
v8::Persistent<v8::Object> utils;
v8::Persistent<v8::Object> shared;
v8::Persistent<v8::Object> builtin_exports;
{
v8::HandleScope scope(isolate);
v8::Handle<v8::Object> natives =
CcTest::global()->Get(v8_str("natives"))->ToObject(isolate);
utils.Reset(isolate, natives->Get(v8_str("utils"))->ToObject(isolate));
natives->Delete(v8_str("utils"));
shared.Reset(isolate, natives->Get(v8_str("shared"))->ToObject(isolate));
natives->Delete(v8_str("shared"));
builtin_exports.Reset(
isolate, natives->Get(v8_str("builtin_exports"))->ToObject(isolate));
natives->Delete(v8_str("builtin_exports"));
}
utils.SetWeak(&utils, UtilsHasBeenCollected,
shared.SetWeak(&shared, SharedHasBeenCollected,
v8::WeakCallbackType::kParameter);
builtin_exports.SetWeak(&builtin_exports, BuiltinExportsHasBeenCollected,
v8::WeakCallbackType::kParameter);
CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks");
CHECK(utils_has_been_collected);
}
TEST(Regress1878) {
FLAG_allow_natives_syntax = true;
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Function> constructor =
v8::Utils::ToLocal(CcTest::i_isolate()->internal_array_function());
CcTest::global()->Set(v8_str("InternalArray"), constructor);
v8::TryCatch try_catch;
CompileRun(
"var a = Array();"
"for (var i = 0; i < 1000; i++) {"
" var ai = new InternalArray(10000);"
" if (%HaveSameMap(ai, a)) throw Error();"
" if (!%HasFastObjectElements(ai)) throw Error();"
"}"
"for (var i = 0; i < 1000; i++) {"
" var ai = new InternalArray(10000);"
" if (%HaveSameMap(ai, a)) throw Error();"
" if (!%HasFastObjectElements(ai)) throw Error();"
"}");
CHECK(!try_catch.HasCaught());
CHECK(shared_has_been_collected);
CHECK(builtin_exports_has_been_collected);
}

View File

@ -0,0 +1,44 @@
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// See: http://code.google.com/p/v8/issues/detail?id=1878
// Flags: --allow-natives-syntax --expose-natives-as=natives
var a = Array();
for (var i = 0; i < 1000; i++) {
var ai = natives.builtin_exports.InternalArray(10000);
assertFalse(%HaveSameMap(ai, a));
assertTrue(%HasFastObjectElements(ai));
}
for (var i = 0; i < 1000; i++) {
var ai = new natives.builtin_exports.InternalArray(10000);
assertFalse(%HaveSameMap(ai, a));
assertTrue(%HasFastObjectElements(ai));
}

View File

@ -1709,7 +1709,6 @@
'../../src/macros.py',
'../../src/messages.h',
'../../src/runtime.js',
'../../src/prologue.js',
'../../src/v8natives.js',
'../../src/symbol.js',
'../../src/array.js',