2015-05-21 06:15:33 +00:00
|
|
|
// 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.
|
|
|
|
|
2015-09-16 21:00:45 +00:00
|
|
|
(function(global, utils, extrasUtils) {
|
2015-05-21 06:15:33 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
%CheckIsBootstrapping();
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// Utils
|
|
|
|
|
|
|
|
var imports = UNDEFINED;
|
2015-05-26 07:24:13 +00:00
|
|
|
var imports_from_experimental = UNDEFINED;
|
2015-08-28 10:22:31 +00:00
|
|
|
var exports_container = %ExportFromRuntime({});
|
2015-10-22 14:40:43 +00:00
|
|
|
var typed_array_setup = UNDEFINED;
|
|
|
|
|
|
|
|
// Register context value to be initialized with a typed array in
|
|
|
|
// Genesis::InitializeBuiltinTypedArrays.
|
|
|
|
function SetupTypedArray(f) {
|
|
|
|
f.next = typed_array_setup;
|
|
|
|
typed_array_setup = f;
|
|
|
|
}
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2015-05-26 07:24:13 +00:00
|
|
|
// Export to other scripts.
|
|
|
|
// In normal natives, this exports functions to other normal natives.
|
|
|
|
// In experimental natives, this exports to other experimental natives and
|
|
|
|
// to normal natives that import using utils.ImportFromExperimental.
|
|
|
|
function Export(f) {
|
2015-08-19 08:34:21 +00:00
|
|
|
f(exports_container);
|
2015-08-18 13:08:05 +00:00
|
|
|
}
|
2015-05-21 06:15:33 +00:00
|
|
|
|
|
|
|
|
2015-08-19 08:34:21 +00:00
|
|
|
// Import from other scripts. The actual importing happens in PostNatives and
|
|
|
|
// PostExperimental so that we can import from scripts executed later. However,
|
|
|
|
// that means that the import is not available until the very end. If the
|
|
|
|
// import needs to be available immediate, use ImportNow.
|
2015-05-26 07:24:13 +00:00
|
|
|
// In normal natives, this imports from other normal natives.
|
|
|
|
// In experimental natives, this imports from other experimental natives and
|
|
|
|
// whitelisted exports from normal natives.
|
|
|
|
function Import(f) {
|
2015-05-21 06:15:33 +00:00
|
|
|
f.next = imports;
|
|
|
|
imports = f;
|
2015-08-18 13:08:05 +00:00
|
|
|
}
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2015-08-28 10:22:31 +00:00
|
|
|
|
2015-08-19 08:34:21 +00:00
|
|
|
// Import immediately from exports of previous scripts. We need this for
|
|
|
|
// functions called during bootstrapping. Hooking up imports in PostNatives
|
|
|
|
// would be too late.
|
2015-08-28 10:22:31 +00:00
|
|
|
function ImportNow(name) {
|
|
|
|
return exports_container[name];
|
2015-08-19 08:34:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 07:24:13 +00:00
|
|
|
|
|
|
|
// In normal natives, import from experimental natives.
|
|
|
|
// Not callable from experimental natives.
|
|
|
|
function ImportFromExperimental(f) {
|
|
|
|
f.next = imports_from_experimental;
|
|
|
|
imports_from_experimental = f;
|
2015-08-18 13:08:05 +00:00
|
|
|
}
|
2015-05-26 07:24:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
function SetFunctionName(f, name, prefix) {
|
|
|
|
if (IS_SYMBOL(name)) {
|
|
|
|
name = "[" + %SymbolDescription(name) + "]";
|
|
|
|
}
|
|
|
|
if (IS_UNDEFINED(prefix)) {
|
|
|
|
%FunctionSetName(f, name);
|
|
|
|
} else {
|
|
|
|
%FunctionSetName(f, prefix + " " + name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function InstallConstants(object, constants) {
|
|
|
|
%CheckIsBootstrapping();
|
|
|
|
%OptimizeObjectForAddingMultipleProperties(object, constants.length >> 1);
|
|
|
|
var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
|
|
|
|
for (var i = 0; i < constants.length; i += 2) {
|
|
|
|
var name = constants[i];
|
|
|
|
var k = constants[i + 1];
|
|
|
|
%AddNamedProperty(object, name, k, attributes);
|
|
|
|
}
|
|
|
|
%ToFastProperties(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function InstallFunctions(object, attributes, functions) {
|
2015-08-18 13:08:05 +00:00
|
|
|
%CheckIsBootstrapping();
|
|
|
|
%OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1);
|
|
|
|
for (var i = 0; i < functions.length; i += 2) {
|
|
|
|
var key = functions[i];
|
|
|
|
var f = functions[i + 1];
|
|
|
|
SetFunctionName(f, key);
|
|
|
|
%FunctionRemovePrototype(f);
|
|
|
|
%AddNamedProperty(object, key, f, attributes);
|
|
|
|
%SetNativeFlag(f);
|
|
|
|
}
|
|
|
|
%ToFastProperties(object);
|
2015-05-26 07:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Helper function to install a getter-only accessor property.
|
2015-11-10 06:58:04 +00:00
|
|
|
function InstallGetter(object, name, getter, attributes, prefix) {
|
2015-05-26 07:24:13 +00:00
|
|
|
%CheckIsBootstrapping();
|
2015-11-10 06:58:04 +00:00
|
|
|
if (IS_UNDEFINED(attributes)) attributes = DONT_ENUM;
|
|
|
|
SetFunctionName(getter, name, IS_UNDEFINED(prefix) ? "get" : prefix);
|
2015-05-26 07:24:13 +00:00
|
|
|
%FunctionRemovePrototype(getter);
|
2015-11-10 06:58:04 +00:00
|
|
|
%DefineGetterPropertyUnchecked(object, name, getter, attributes);
|
2015-05-26 07:24:13 +00:00
|
|
|
%SetNativeFlag(getter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Helper function to install a getter/setter accessor property.
|
2015-11-10 06:58:04 +00:00
|
|
|
function InstallGetterSetter(object, name, getter, setter, attributes) {
|
2015-05-26 07:24:13 +00:00
|
|
|
%CheckIsBootstrapping();
|
2015-11-10 06:58:04 +00:00
|
|
|
if (IS_UNDEFINED(attributes)) attributes = DONT_ENUM;
|
2015-05-26 07:24:13 +00:00
|
|
|
SetFunctionName(getter, name, "get");
|
|
|
|
SetFunctionName(setter, name, "set");
|
|
|
|
%FunctionRemovePrototype(getter);
|
|
|
|
%FunctionRemovePrototype(setter);
|
|
|
|
%DefineAccessorPropertyUnchecked(object, name, getter, setter, DONT_ENUM);
|
|
|
|
%SetNativeFlag(getter);
|
|
|
|
%SetNativeFlag(setter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-24 22:26:15 +00:00
|
|
|
function OverrideFunction(object, name, f, afterInitialBootstrap) {
|
|
|
|
%CheckIsBootstrapping();
|
2016-04-25 12:24:02 +00:00
|
|
|
%object_define_property(object, name, { value: f,
|
|
|
|
writeable: true,
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false });
|
2016-03-24 22:26:15 +00:00
|
|
|
SetFunctionName(f, name);
|
|
|
|
if (!afterInitialBootstrap) %FunctionRemovePrototype(f);
|
|
|
|
%SetNativeFlag(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-26 07:24:13 +00:00
|
|
|
// Prevents changes to the prototype of a built-in function.
|
|
|
|
// The "prototype" property of the function object is made non-configurable,
|
|
|
|
// and the prototype object is made non-extensible. The latter prevents
|
|
|
|
// changing the __proto__ property.
|
|
|
|
function SetUpLockedPrototype(
|
|
|
|
constructor, fields, methods) {
|
|
|
|
%CheckIsBootstrapping();
|
|
|
|
var prototype = constructor.prototype;
|
|
|
|
// Install functions first, because this function is used to initialize
|
|
|
|
// PropertyDescriptor itself.
|
|
|
|
var property_count = (methods.length >> 1) + (fields ? fields.length : 0);
|
|
|
|
if (property_count >= 4) {
|
|
|
|
%OptimizeObjectForAddingMultipleProperties(prototype, property_count);
|
|
|
|
}
|
|
|
|
if (fields) {
|
|
|
|
for (var i = 0; i < fields.length; i++) {
|
|
|
|
%AddNamedProperty(prototype, fields[i],
|
|
|
|
UNDEFINED, DONT_ENUM | DONT_DELETE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i = 0; i < methods.length; i += 2) {
|
|
|
|
var key = methods[i];
|
|
|
|
var f = methods[i + 1];
|
|
|
|
%AddNamedProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
%SetNativeFlag(f);
|
|
|
|
}
|
|
|
|
%InternalSetPrototype(prototype, null);
|
|
|
|
%ToFastProperties(prototype);
|
|
|
|
}
|
|
|
|
|
2015-08-21 06:44:17 +00:00
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// To be called by bootstrapper
|
|
|
|
|
2015-05-26 07:24:13 +00:00
|
|
|
function PostNatives(utils) {
|
2015-05-21 06:15:33 +00:00
|
|
|
%CheckIsBootstrapping();
|
|
|
|
|
2015-08-19 08:34:21 +00:00
|
|
|
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
|
|
|
|
imports(exports_container);
|
|
|
|
}
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2015-08-19 08:34:21 +00:00
|
|
|
// Whitelist of exports from normal natives to experimental natives and debug.
|
|
|
|
var expose_list = [
|
2016-05-12 00:32:42 +00:00
|
|
|
"AddBoundMethod",
|
2015-06-02 18:58:12 +00:00
|
|
|
"ArrayToString",
|
2016-05-17 00:26:53 +00:00
|
|
|
"AsyncFunctionNext",
|
|
|
|
"AsyncFunctionThrow",
|
2015-10-15 10:22:48 +00:00
|
|
|
"ErrorToString",
|
2015-05-26 07:24:13 +00:00
|
|
|
"GetIterator",
|
|
|
|
"GetMethod",
|
2016-05-12 00:32:42 +00:00
|
|
|
"IntlParseDate",
|
|
|
|
"IntlParseNumber",
|
2015-05-26 07:24:13 +00:00
|
|
|
"IsNaN",
|
2015-10-22 11:29:40 +00:00
|
|
|
"MakeError",
|
2016-03-25 21:52:15 +00:00
|
|
|
"MakeRangeError",
|
2015-10-22 11:29:40 +00:00
|
|
|
"MakeTypeError",
|
2015-10-15 10:22:48 +00:00
|
|
|
"MapEntries",
|
2015-10-16 11:27:14 +00:00
|
|
|
"MapIterator",
|
2015-10-15 10:22:48 +00:00
|
|
|
"MapIteratorNext",
|
2015-10-20 13:43:44 +00:00
|
|
|
"MaxSimple",
|
|
|
|
"MinSimple",
|
2016-03-25 21:52:15 +00:00
|
|
|
"NumberIsInteger",
|
2015-12-10 23:57:39 +00:00
|
|
|
"PromiseChain",
|
2016-05-03 07:19:14 +00:00
|
|
|
"PromiseDefer",
|
|
|
|
"PromiseAccept",
|
2016-05-17 00:26:53 +00:00
|
|
|
"PromiseCreateRejected",
|
|
|
|
"PromiseCreateResolved",
|
|
|
|
"PromiseThen",
|
2016-03-24 22:26:15 +00:00
|
|
|
"RegExpSubclassExecJS",
|
|
|
|
"RegExpSubclassMatch",
|
|
|
|
"RegExpSubclassReplace",
|
|
|
|
"RegExpSubclassSearch",
|
|
|
|
"RegExpSubclassSplit",
|
|
|
|
"RegExpSubclassTest",
|
2015-10-16 11:27:14 +00:00
|
|
|
"SetIterator",
|
2015-10-15 10:22:48 +00:00
|
|
|
"SetIteratorNext",
|
|
|
|
"SetValues",
|
2015-08-28 10:22:31 +00:00
|
|
|
"SymbolToString",
|
Use ICU case conversion/transliterator for case conversion
When I18N is enabled, use ICU's case conversion API and transliteration
API [1] to implement String.prototype.to{Upper,Lower}Case and
String.prototype.toLocale{Upper,Lower}Case.
* ICU-based case conversion was implemented in runtime-i18n.cc/i18n.js
* The above 4 functions are overridden with those in i18n.js when
--icu_case_mapping flag is turned on. To control the override by the flag,
they're overriden in icu-case-mapping.js
Previously, toLocale{U,L}Case just called to{U,L}Case so that they didn't
support locale-sensitive case conversion for Turkic languages (az, tr),
Greek (el) and Lithuanian (lt).
Before ICU APIs for the most general case are called, a fast-path for Latin-1
is tried. It's taken from Blink and adopted as necessary. This fast path
is always tried for to{U,L}Case. For toLocale{U,L}Case, it's only taken
when a locale (explicitly specified or default) is not in {az, el, lt, tr}.
With these changes, a build with --icu_case_mapping=true passes a bunch
of tests in test262/intl402/Strings/* and intl/* that failed before.
Handling of pure ASCII strings (aligned at word boundary) are not as fast
as Unibrow's implementation that uses word-by-word case conversion. OTOH,
Latin-1 input handling is faster than Unibrow. General Unicode input
handling is slower but more accurate.
See https://docs.google.com/spreadsheets/d/1KJCJxKc1FxFXjwmYqABS0_2cNdPetvnd8gY8_HGSbrg/edit?usp=sharing for the benchmark.
This CL started with http://crrev.com/1544023002#ps200001 by littledan@,
but has changed significantly since.
[1] See why transliteration API is needed for uppercasing in Greek.
http://bugs.icu-project.org/trac/ticket/10582
R=yangguo
BUG=v8:4476,v8:4477
LOG=Y
TEST=test262/{built-ins,intl402}/Strings/*, webkit/fast/js/*, mjsunit/string-case,
intl/general/case*
Review-Url: https://codereview.chromium.org/1812673005
Cr-Commit-Position: refs/heads/master@{#36187}
2016-05-11 19:01:41 +00:00
|
|
|
"ToLocaleLowerCaseI18N",
|
|
|
|
"ToLocaleUpperCaseI18N",
|
|
|
|
"ToLowerCaseI18N",
|
2015-10-15 10:22:48 +00:00
|
|
|
"ToPositiveInteger",
|
Use ICU case conversion/transliterator for case conversion
When I18N is enabled, use ICU's case conversion API and transliteration
API [1] to implement String.prototype.to{Upper,Lower}Case and
String.prototype.toLocale{Upper,Lower}Case.
* ICU-based case conversion was implemented in runtime-i18n.cc/i18n.js
* The above 4 functions are overridden with those in i18n.js when
--icu_case_mapping flag is turned on. To control the override by the flag,
they're overriden in icu-case-mapping.js
Previously, toLocale{U,L}Case just called to{U,L}Case so that they didn't
support locale-sensitive case conversion for Turkic languages (az, tr),
Greek (el) and Lithuanian (lt).
Before ICU APIs for the most general case are called, a fast-path for Latin-1
is tried. It's taken from Blink and adopted as necessary. This fast path
is always tried for to{U,L}Case. For toLocale{U,L}Case, it's only taken
when a locale (explicitly specified or default) is not in {az, el, lt, tr}.
With these changes, a build with --icu_case_mapping=true passes a bunch
of tests in test262/intl402/Strings/* and intl/* that failed before.
Handling of pure ASCII strings (aligned at word boundary) are not as fast
as Unibrow's implementation that uses word-by-word case conversion. OTOH,
Latin-1 input handling is faster than Unibrow. General Unicode input
handling is slower but more accurate.
See https://docs.google.com/spreadsheets/d/1KJCJxKc1FxFXjwmYqABS0_2cNdPetvnd8gY8_HGSbrg/edit?usp=sharing for the benchmark.
This CL started with http://crrev.com/1544023002#ps200001 by littledan@,
but has changed significantly since.
[1] See why transliteration API is needed for uppercasing in Greek.
http://bugs.icu-project.org/trac/ticket/10582
R=yangguo
BUG=v8:4476,v8:4477
LOG=Y
TEST=test262/{built-ins,intl402}/Strings/*, webkit/fast/js/*, mjsunit/string-case,
intl/general/case*
Review-Url: https://codereview.chromium.org/1812673005
Cr-Commit-Position: refs/heads/master@{#36187}
2016-05-11 19:01:41 +00:00
|
|
|
"ToUpperCaseI18N",
|
2015-08-28 10:22:31 +00:00
|
|
|
// From runtime:
|
|
|
|
"is_concat_spreadable_symbol",
|
|
|
|
"iterator_symbol",
|
2016-05-03 07:19:14 +00:00
|
|
|
"promise_result_symbol",
|
|
|
|
"promise_state_symbol",
|
2016-01-04 08:10:13 +00:00
|
|
|
"object_freeze",
|
|
|
|
"object_is_frozen",
|
|
|
|
"object_is_sealed",
|
2015-08-28 10:22:31 +00:00
|
|
|
"reflect_apply",
|
|
|
|
"reflect_construct",
|
2015-11-05 13:08:39 +00:00
|
|
|
"regexp_flags_symbol",
|
2015-08-28 10:22:31 +00:00
|
|
|
"to_string_tag_symbol",
|
2015-12-11 04:26:34 +00:00
|
|
|
"object_to_string",
|
2016-01-04 19:39:52 +00:00
|
|
|
"species_symbol",
|
2016-03-24 22:26:15 +00:00
|
|
|
"match_symbol",
|
|
|
|
"replace_symbol",
|
|
|
|
"search_symbol",
|
|
|
|
"split_symbol",
|
2015-05-21 06:15:33 +00:00
|
|
|
];
|
2015-08-19 08:34:21 +00:00
|
|
|
|
|
|
|
var filtered_exports = {};
|
2015-05-21 06:15:33 +00:00
|
|
|
%OptimizeObjectForAddingMultipleProperties(
|
2015-08-19 08:34:21 +00:00
|
|
|
filtered_exports, expose_list.length);
|
|
|
|
for (var key of expose_list) {
|
|
|
|
filtered_exports[key] = exports_container[key];
|
2015-05-26 07:24:13 +00:00
|
|
|
}
|
2015-08-19 08:34:21 +00:00
|
|
|
%ToFastProperties(filtered_exports);
|
|
|
|
exports_container = filtered_exports;
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2015-05-22 11:21:32 +00:00
|
|
|
utils.PostNatives = UNDEFINED;
|
2015-05-26 07:24:13 +00:00
|
|
|
utils.ImportFromExperimental = UNDEFINED;
|
2015-08-18 13:08:05 +00:00
|
|
|
}
|
2015-05-26 07:24:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
function PostExperimentals(utils) {
|
|
|
|
%CheckIsBootstrapping();
|
2015-08-28 10:22:31 +00:00
|
|
|
%ExportExperimentalFromRuntime(exports_container);
|
2015-05-26 07:24:13 +00:00
|
|
|
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
|
2015-08-19 08:34:21 +00:00
|
|
|
imports(exports_container);
|
2015-05-26 07:24:13 +00:00
|
|
|
}
|
|
|
|
for ( ; !IS_UNDEFINED(imports_from_experimental);
|
|
|
|
imports_from_experimental = imports_from_experimental.next) {
|
2015-08-19 08:34:21 +00:00
|
|
|
imports_from_experimental(exports_container);
|
2015-05-26 07:24:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 08:24:27 +00:00
|
|
|
utils.CreateDoubleResultArray();
|
|
|
|
utils.CreateDoubleResultArray = UNDEFINED;
|
2015-11-02 13:44:52 +00:00
|
|
|
|
2015-08-12 14:22:07 +00:00
|
|
|
utils.Export = UNDEFINED;
|
2015-10-16 11:27:14 +00:00
|
|
|
utils.PostDebug = UNDEFINED;
|
|
|
|
utils.PostExperimentals = UNDEFINED;
|
2015-10-22 14:40:43 +00:00
|
|
|
typed_array_setup = UNDEFINED;
|
2015-08-18 13:08:05 +00:00
|
|
|
}
|
2015-08-12 14:22:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
function PostDebug(utils) {
|
|
|
|
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
|
2015-08-19 08:34:21 +00:00
|
|
|
imports(exports_container);
|
2015-08-12 14:22:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 08:24:27 +00:00
|
|
|
utils.CreateDoubleResultArray();
|
|
|
|
utils.CreateDoubleResultArray = UNDEFINED;
|
2015-11-02 13:44:52 +00:00
|
|
|
|
2015-08-19 08:34:21 +00:00
|
|
|
exports_container = UNDEFINED;
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
utils.Export = UNDEFINED;
|
|
|
|
utils.Import = UNDEFINED;
|
|
|
|
utils.ImportNow = UNDEFINED;
|
2015-08-12 14:22:07 +00:00
|
|
|
utils.PostDebug = UNDEFINED;
|
2015-05-26 07:24:13 +00:00
|
|
|
utils.PostExperimentals = UNDEFINED;
|
2015-10-22 14:40:43 +00:00
|
|
|
typed_array_setup = UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-02 12:21:13 +00:00
|
|
|
function InitializeBuiltinTypedArrays(utils, rng_state, rempio2result) {
|
2015-10-22 14:40:43 +00:00
|
|
|
var setup_list = typed_array_setup;
|
|
|
|
|
|
|
|
for ( ; !IS_UNDEFINED(setup_list); setup_list = setup_list.next) {
|
2015-11-02 12:21:13 +00:00
|
|
|
setup_list(rng_state, rempio2result);
|
2015-10-22 14:40:43 +00:00
|
|
|
}
|
2015-08-18 13:08:05 +00:00
|
|
|
}
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2015-05-26 07:24:13 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2015-11-24 13:18:12 +00:00
|
|
|
%OptimizeObjectForAddingMultipleProperties(utils, 14);
|
2015-08-18 13:08:05 +00:00
|
|
|
|
|
|
|
utils.Import = Import;
|
2015-08-19 08:34:21 +00:00
|
|
|
utils.ImportNow = ImportNow;
|
2015-08-18 13:08:05 +00:00
|
|
|
utils.Export = Export;
|
|
|
|
utils.ImportFromExperimental = ImportFromExperimental;
|
|
|
|
utils.SetFunctionName = SetFunctionName;
|
|
|
|
utils.InstallConstants = InstallConstants;
|
|
|
|
utils.InstallFunctions = InstallFunctions;
|
|
|
|
utils.InstallGetter = InstallGetter;
|
|
|
|
utils.InstallGetterSetter = InstallGetterSetter;
|
2016-03-24 22:26:15 +00:00
|
|
|
utils.OverrideFunction = OverrideFunction;
|
2015-08-18 13:08:05 +00:00
|
|
|
utils.SetUpLockedPrototype = SetUpLockedPrototype;
|
|
|
|
utils.PostNatives = PostNatives;
|
|
|
|
utils.PostExperimentals = PostExperimentals;
|
|
|
|
utils.PostDebug = PostDebug;
|
|
|
|
|
|
|
|
%ToFastProperties(utils);
|
2015-05-26 07:24:13 +00:00
|
|
|
|
2015-09-16 21:00:45 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
%OptimizeObjectForAddingMultipleProperties(extrasUtils, 5);
|
|
|
|
|
|
|
|
extrasUtils.logStackTrace = function logStackTrace() {
|
|
|
|
%DebugTrace();
|
|
|
|
};
|
|
|
|
|
|
|
|
extrasUtils.log = function log() {
|
|
|
|
let message = '';
|
|
|
|
for (const arg of arguments) {
|
|
|
|
message += arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
%GlobalPrint(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Extras need the ability to store private state on their objects without
|
|
|
|
// exposing it to the outside world.
|
|
|
|
|
|
|
|
extrasUtils.createPrivateSymbol = function createPrivateSymbol(name) {
|
|
|
|
return %CreatePrivateSymbol(name);
|
|
|
|
};
|
|
|
|
|
|
|
|
// These functions are key for safe meta-programming:
|
|
|
|
// http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming
|
|
|
|
//
|
|
|
|
// Technically they could all be derived from combinations of
|
|
|
|
// Function.prototype.{bind,call,apply} but that introduces lots of layers of
|
|
|
|
// indirection and slowness given how un-optimized bind is.
|
|
|
|
|
|
|
|
extrasUtils.simpleBind = function simpleBind(func, thisArg) {
|
2016-02-26 08:09:41 +00:00
|
|
|
return function(...args) {
|
|
|
|
return %reflect_apply(func, thisArg, args);
|
2015-09-16 21:00:45 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extrasUtils.uncurryThis = function uncurryThis(func) {
|
2016-02-26 08:09:41 +00:00
|
|
|
return function(thisArg, ...args) {
|
|
|
|
return %reflect_apply(func, thisArg, args);
|
2015-09-16 21:00:45 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
%ToFastProperties(extrasUtils);
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
})
|