diff options
Diffstat (limited to 'deps/v8/src/runtime')
31 files changed, 537 insertions, 728 deletions
diff --git a/deps/v8/src/runtime/runtime-array.cc b/deps/v8/src/runtime/runtime-array.cc index ae23c99910..31b03f6bb7 100644 --- a/deps/v8/src/runtime/runtime-array.cc +++ b/deps/v8/src/runtime/runtime-array.cc @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/code-stubs.h" #include "src/conversions-inl.h" #include "src/debug/debug.h" @@ -15,7 +13,9 @@ #include "src/messages.h" #include "src/objects/arguments-inl.h" #include "src/objects/hash-table-inl.h" +#include "src/objects/js-array-inl.h" #include "src/prototype.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { @@ -61,20 +61,14 @@ Object* RemoveArrayHolesGeneric(Isolate* isolate, Handle<JSReceiver> receiver, // For proxies, we do not collect the keys, instead we use all indices in // the full range of [0, limit). Handle<FixedArray> keys; - if (receiver->IsJSProxy()) { - CHECK(Smi::IsValid(limit)); - keys = isolate->factory()->NewFixedArray(limit); - for (uint32_t i = 0; i < limit; ++i) { - keys->set(i, Smi::FromInt(i)); - } - } else { + if (!receiver->IsJSProxy()) { keys = JSReceiver::GetOwnElementIndices(isolate, receiver, Handle<JSObject>::cast(receiver)); } uint32_t num_undefined = 0; uint32_t current_pos = 0; - int num_indices = keys->length(); + int num_indices = keys.is_null() ? limit : keys->length(); // Compact keys with undefined values and moves non-undefined // values to the front. @@ -86,7 +80,7 @@ Object* RemoveArrayHolesGeneric(Isolate* isolate, Handle<JSReceiver> receiver, // Holes and 'undefined' are considered free spots. // A hole is when HasElement(receiver, key) is false. for (int i = 0; i < num_indices; ++i) { - uint32_t key = NumberToUint32(keys->get(i)); + uint32_t key = keys.is_null() ? i : NumberToUint32(keys->get(i)); // We only care about array indices that are smaller than the limit. // The keys are sorted, so we can break as soon as we encounter the first. @@ -143,7 +137,7 @@ Object* RemoveArrayHolesGeneric(Isolate* isolate, Handle<JSReceiver> receiver, // Deleting everything after the undefineds up unto the limit. for (int i = num_indices - 1; i >= 0; --i) { - uint32_t key = NumberToUint32(keys->get(i)); + uint32_t key = keys.is_null() ? i : NumberToUint32(keys->get(i)); if (key < current_pos) break; if (key >= limit) continue; @@ -605,9 +599,7 @@ RUNTIME_FUNCTION(Runtime_NewArray) { // We should allocate with an initial map that reflects the allocation site // advice. Therefore we use AllocateJSObjectFromMap instead of passing // the constructor. - if (to_kind != initial_map->elements_kind()) { - initial_map = Map::AsElementsKind(isolate, initial_map, to_kind); - } + initial_map = Map::AsElementsKind(isolate, initial_map, to_kind); // If we don't care to track arrays of to_kind ElementsKind, then // don't emit a memento for them. @@ -628,7 +620,7 @@ RUNTIME_FUNCTION(Runtime_NewArray) { if ((old_kind != array->GetElementsKind() || !can_use_type_feedback || !can_inline_array_constructor)) { // The arguments passed in caused a transition. This kind of complexity - // can't be dealt with in the inlined hydrogen array constructor case. + // can't be dealt with in the inlined optimized array constructor case. // We must mark the allocationsite as un-inlinable. site->SetDoNotInlineCall(); } diff --git a/deps/v8/src/runtime/runtime-atomics.cc b/deps/v8/src/runtime/runtime-atomics.cc index aa2e260a09..972e48bae6 100644 --- a/deps/v8/src/runtime/runtime-atomics.cc +++ b/deps/v8/src/runtime/runtime-atomics.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/base/macros.h" #include "src/base/platform/mutex.h" #include "src/conversions-inl.h" #include "src/heap/factory.h" +#include "src/objects/js-array-buffer-inl.h" +#include "src/runtime/runtime-utils.h" // Implement Atomic accesses to SharedArrayBuffers as defined in the // SharedArrayBuffer draft spec, found here @@ -108,7 +108,6 @@ ATOMIC_OPS(uint16_t, 16, short) /* NOLINT(runtime/int) */ ATOMIC_OPS(int32_t, 32, long) /* NOLINT(runtime/int) */ ATOMIC_OPS(uint32_t, 32, long) /* NOLINT(runtime/int) */ -#undef ATOMIC_OPS_INTEGER #undef ATOMIC_OPS #undef InterlockedExchange32 @@ -240,14 +239,14 @@ inline Object* DoXor(Isolate* isolate, void* buffer, size_t index, } // anonymous namespace // Duplicated from objects.h -// V has parameters (Type, type, TYPE, C type, element_size) -#define INTEGER_TYPED_ARRAYS(V) \ - V(Uint8, uint8, UINT8, uint8_t, 1) \ - V(Int8, int8, INT8, int8_t, 1) \ - V(Uint16, uint16, UINT16, uint16_t, 2) \ - V(Int16, int16, INT16, int16_t, 2) \ - V(Uint32, uint32, UINT32, uint32_t, 4) \ - V(Int32, int32, INT32, int32_t, 4) +// V has parameters (Type, type, TYPE, C type) +#define INTEGER_TYPED_ARRAYS(V) \ + V(Uint8, uint8, UINT8, uint8_t) \ + V(Int8, int8, INT8, int8_t) \ + V(Uint16, uint16, UINT16, uint16_t) \ + V(Int16, int16, INT16, int16_t) \ + V(Uint32, uint32, UINT32, uint32_t) \ + V(Int32, int32, INT32, int32_t) RUNTIME_FUNCTION(Runtime_AtomicsExchange) { HandleScope scope(isolate); @@ -262,8 +261,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsExchange) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoExchange<ctype>(isolate, source, index, value); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -290,8 +289,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsCompareExchange) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoCompareExchange<ctype>(isolate, source, index, oldobj, newobj); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -319,8 +318,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsAdd) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoAdd<ctype>(isolate, source, index, value); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -348,8 +347,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsSub) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoSub<ctype>(isolate, source, index, value); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -377,8 +376,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsAnd) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoAnd<ctype>(isolate, source, index, value); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -406,8 +405,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsOr) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoOr<ctype>(isolate, source, index, value); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -435,8 +434,8 @@ RUNTIME_FUNCTION(Runtime_AtomicsXor) { NumberToSize(sta->byte_offset()); switch (sta->type()) { -#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ - case kExternal##Type##Array: \ +#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype) \ + case kExternal##Type##Array: \ return DoXor<ctype>(isolate, source, index, value); INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) @@ -449,5 +448,7 @@ RUNTIME_FUNCTION(Runtime_AtomicsXor) { UNREACHABLE(); } +#undef INTEGER_TYPED_ARRAYS + } // namespace internal } // namespace v8 diff --git a/deps/v8/src/runtime/runtime-bigint.cc b/deps/v8/src/runtime/runtime-bigint.cc index 280106751c..f718ab7eb4 100644 --- a/deps/v8/src/runtime/runtime-bigint.cc +++ b/deps/v8/src/runtime/runtime-bigint.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/counters.h" #include "src/objects-inl.h" #include "src/objects/bigint.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/runtime/runtime-classes.cc b/deps/v8/src/runtime/runtime-classes.cc index 6a83087a53..d4fb0df3c3 100644 --- a/deps/v8/src/runtime/runtime-classes.cc +++ b/deps/v8/src/runtime/runtime-classes.cc @@ -8,7 +8,7 @@ #include <limits> #include "src/accessors.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/debug/debug.h" #include "src/elements.h" #include "src/isolate-inl.h" @@ -833,19 +833,5 @@ RUNTIME_FUNCTION(Runtime_StoreKeyedToSuper_Sloppy) { LanguageMode::kSloppy)); } - -RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { - SealHandleScope shs(isolate); - DCHECK_EQ(1, args.length()); - CONVERT_ARG_CHECKED(JSFunction, active_function, 0); - Object* prototype = active_function->map()->prototype(); - if (!prototype->IsConstructor()) { - HandleScope scope(isolate); - return ThrowNotSuperConstructor(isolate, handle(prototype, isolate), - handle(active_function, isolate)); - } - return prototype; -} - } // namespace internal } // namespace v8 diff --git a/deps/v8/src/runtime/runtime-collections.cc b/deps/v8/src/runtime/runtime-collections.cc index 30e4341be3..6c64802963 100644 --- a/deps/v8/src/runtime/runtime-collections.cc +++ b/deps/v8/src/runtime/runtime-collections.cc @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/conversions-inl.h" #include "src/heap/factory.h" #include "src/objects/hash-table-inl.h" #include "src/objects/js-collection-inl.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { @@ -143,19 +142,5 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { return *weak_collection; } -RUNTIME_FUNCTION(Runtime_IsJSWeakMap) { - SealHandleScope shs(isolate); - DCHECK_EQ(1, args.length()); - CONVERT_ARG_CHECKED(Object, obj, 0); - return isolate->heap()->ToBoolean(obj->IsJSWeakMap()); -} - -RUNTIME_FUNCTION(Runtime_IsJSWeakSet) { - SealHandleScope shs(isolate); - DCHECK_EQ(1, args.length()); - CONVERT_ARG_CHECKED(Object, obj, 0); - return isolate->heap()->ToBoolean(obj->IsJSWeakSet()); -} - } // namespace internal } // namespace v8 diff --git a/deps/v8/src/runtime/runtime-compiler.cc b/deps/v8/src/runtime/runtime-compiler.cc index 2502fba30d..bebd489d70 100644 --- a/deps/v8/src/runtime/runtime-compiler.cc +++ b/deps/v8/src/runtime/runtime-compiler.cc @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/asmjs/asm-js.h" #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" #include "src/compiler.h" @@ -12,6 +10,9 @@ #include "src/frames-inl.h" #include "src/isolate-inl.h" #include "src/messages.h" +#include "src/objects/js-array-buffer-inl.h" +#include "src/objects/js-array-inl.h" +#include "src/runtime/runtime-utils.h" #include "src/v8threads.h" #include "src/vm-state-inl.h" diff --git a/deps/v8/src/runtime/runtime-debug.cc b/deps/v8/src/runtime/runtime-debug.cc index 9711ffad54..c1dc4ec9df 100644 --- a/deps/v8/src/runtime/runtime-debug.cc +++ b/deps/v8/src/runtime/runtime-debug.cc @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include <vector> -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/compiler.h" #include "src/debug/debug-coverage.h" #include "src/debug/debug-evaluate.h" @@ -22,7 +20,9 @@ #include "src/isolate-inl.h" #include "src/objects/debug-objects-inl.h" #include "src/objects/js-collection-inl.h" +#include "src/objects/js-generator-inl.h" #include "src/objects/js-promise-inl.h" +#include "src/runtime/runtime-utils.h" #include "src/runtime/runtime.h" #include "src/snapshot/snapshot.h" #include "src/wasm/wasm-objects-inl.h" diff --git a/deps/v8/src/runtime/runtime-forin.cc b/deps/v8/src/runtime/runtime-forin.cc index ed1e226060..b43d91540e 100644 --- a/deps/v8/src/runtime/runtime-forin.cc +++ b/deps/v8/src/runtime/runtime-forin.cc @@ -4,7 +4,7 @@ #include "src/runtime/runtime-utils.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/elements.h" #include "src/heap/factory.h" #include "src/isolate-inl.h" diff --git a/deps/v8/src/runtime/runtime-function.cc b/deps/v8/src/runtime/runtime-function.cc index 1057dfa177..22f4a4fb48 100644 --- a/deps/v8/src/runtime/runtime-function.cc +++ b/deps/v8/src/runtime/runtime-function.cc @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include "src/accessors.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/compiler.h" #include "src/isolate-inl.h" #include "src/messages.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/runtime/runtime-futex.cc b/deps/v8/src/runtime/runtime-futex.cc index 96f538e4f3..3c9a90fbbd 100644 --- a/deps/v8/src/runtime/runtime-futex.cc +++ b/deps/v8/src/runtime/runtime-futex.cc @@ -4,11 +4,12 @@ #include "src/runtime/runtime-utils.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/base/platform/time.h" #include "src/conversions-inl.h" #include "src/futex-emulation.h" #include "src/globals.h" +#include "src/objects/js-array-buffer-inl.h" // Implement Futex API for SharedArrayBuffers as defined in the // SharedArrayBuffer draft spec, found here: @@ -17,7 +18,6 @@ namespace v8 { namespace internal { - RUNTIME_FUNCTION(Runtime_AtomicsNumWaitersForTesting) { HandleScope scope(isolate); DCHECK_EQ(2, args.length()); @@ -30,7 +30,7 @@ RUNTIME_FUNCTION(Runtime_AtomicsNumWaitersForTesting) { Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); size_t addr = (index << 2) + NumberToSize(sta->byte_offset()); - return FutexEmulation::NumWaitersForTesting(isolate, array_buffer, addr); + return FutexEmulation::NumWaitersForTesting(array_buffer, addr); } RUNTIME_FUNCTION(Runtime_SetAllowAtomicsWait) { @@ -41,5 +41,6 @@ RUNTIME_FUNCTION(Runtime_SetAllowAtomicsWait) { isolate->set_allow_atomics_wait(set); return ReadOnlyRoots(isolate).undefined_value(); } + } // namespace internal } // namespace v8 diff --git a/deps/v8/src/runtime/runtime-generator.cc b/deps/v8/src/runtime/runtime-generator.cc index 02068ec7a9..636aa63879 100644 --- a/deps/v8/src/runtime/runtime-generator.cc +++ b/deps/v8/src/runtime/runtime-generator.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/heap/factory.h" +#include "src/heap/heap-inl.h" #include "src/objects-inl.h" +#include "src/objects/js-generator-inl.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/runtime/runtime-internal.cc b/deps/v8/src/runtime/runtime-internal.cc index 310c20b102..c98b27da27 100644 --- a/deps/v8/src/runtime/runtime-internal.cc +++ b/deps/v8/src/runtime/runtime-internal.cc @@ -2,12 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include <memory> #include "src/api.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/ast/prettyprinter.h" #include "src/bootstrapper.h" #include "src/builtins/builtins.h" @@ -16,8 +14,10 @@ #include "src/frames-inl.h" #include "src/isolate-inl.h" #include "src/messages.h" +#include "src/objects/js-array-inl.h" #include "src/parsing/parse-info.h" #include "src/parsing/parsing.h" +#include "src/runtime/runtime-utils.h" #include "src/snapshot/snapshot.h" namespace v8 { @@ -120,8 +120,8 @@ namespace { const char* ElementsKindToType(ElementsKind fixed_elements_kind) { switch (fixed_elements_kind) { -#define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype, size) \ - case TYPE##_ELEMENTS: \ +#define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype) \ + case TYPE##_ELEMENTS: \ return #Type "Array"; TYPED_ARRAYS(ELEMENTS_KIND_CASE) diff --git a/deps/v8/src/runtime/runtime-interpreter.cc b/deps/v8/src/runtime/runtime-interpreter.cc index bc48bb4ab7..7f07d084a1 100644 --- a/deps/v8/src/runtime/runtime-interpreter.cc +++ b/deps/v8/src/runtime/runtime-interpreter.cc @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include <iomanip> -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/frames-inl.h" #include "src/interpreter/bytecode-array-iterator.h" #include "src/interpreter/bytecode-decoder.h" @@ -16,6 +14,7 @@ #include "src/interpreter/interpreter.h" #include "src/isolate-inl.h" #include "src/ostreams.h" +#include "src/runtime/runtime-utils.h" #include "src/snapshot/snapshot.h" namespace v8 { diff --git a/deps/v8/src/runtime/runtime-intl.cc b/deps/v8/src/runtime/runtime-intl.cc index 5d39074984..ad75952824 100644 --- a/deps/v8/src/runtime/runtime-intl.cc +++ b/deps/v8/src/runtime/runtime-intl.cc @@ -6,14 +6,12 @@ #error Internationalization is expected to be enabled. #endif // V8_INTL_SUPPORT -#include "src/runtime/runtime-utils.h" - #include <cmath> #include <memory> +#include "src/api-inl.h" #include "src/api-natives.h" -#include "src/api.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/date.h" #include "src/global-handles.h" #include "src/heap/factory.h" @@ -22,6 +20,13 @@ #include "src/messages.h" #include "src/objects/intl-objects-inl.h" #include "src/objects/intl-objects.h" +#include "src/objects/js-array-inl.h" +#include "src/objects/js-collator-inl.h" +#include "src/objects/js-list-format-inl.h" +#include "src/objects/js-list-format.h" +#include "src/objects/js-plural-rules-inl.h" +#include "src/objects/managed.h" +#include "src/runtime/runtime-utils.h" #include "src/utils.h" #include "unicode/brkiter.h" @@ -52,130 +57,109 @@ namespace v8 { namespace internal { -// ECMA 402 6.2.3 -RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { +// ecma402 #sec-formatlist +RUNTIME_FUNCTION(Runtime_FormatList) { HandleScope scope(isolate); - v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0); + CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1); + RETURN_RESULT_OR_FAILURE( + isolate, JSListFormat::FormatList(isolate, list_format, list)); +} - Factory* factory = isolate->factory(); +// ecma402 #sec-formatlisttoparts +RUNTIME_FUNCTION(Runtime_FormatListToParts) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0); + CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1); + RETURN_RESULT_OR_FAILURE( + isolate, JSListFormat::FormatListToParts(isolate, list_format, list)); +} - DCHECK_EQ(1, args.length()); - CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0); - - v8::String::Utf8Value locale_id(v8_isolate, - v8::Utils::ToLocal(locale_id_str)); - - // TODO(jshin): uloc_{for,to}TanguageTag can fail even for a structually valid - // language tag if it's too long (much longer than 100 chars). Even if we - // allocate a longer buffer, ICU will still fail if it's too long. Either - // propose to Ecma 402 to put a limit on the locale length or change ICU to - // handle long locale names better. See - // https://ssl.icu-project.org/trac/ticket/13417 . - - // Return value which denotes invalid language tag. - const char* const kInvalidTag = "invalid-tag"; - - UErrorCode error = U_ZERO_ERROR; - char icu_result[ULOC_FULLNAME_CAPACITY]; - uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, nullptr, - &error); - if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) { - return *factory->NewStringFromAsciiChecked(kInvalidTag); +RUNTIME_FUNCTION(Runtime_GetNumberOption) { + HandleScope scope(isolate); + DCHECK_EQ(5, args.length()); + CONVERT_ARG_HANDLE_CHECKED(JSReceiver, options, 0); + CONVERT_ARG_HANDLE_CHECKED(String, property, 1); + CONVERT_SMI_ARG_CHECKED(min, 2); + CONVERT_SMI_ARG_CHECKED(max, 3); + CONVERT_SMI_ARG_CHECKED(fallback, 4); + + Maybe<int> num = + Intl::GetNumberOption(isolate, options, property, min, max, fallback); + if (num.IsNothing()) { + return ReadOnlyRoots(isolate).exception(); } + return Smi::FromInt(num.FromJust()); +} - char result[ULOC_FULLNAME_CAPACITY]; - - // Force strict BCP47 rules. - uloc_toLanguageTag(icu_result, result, ULOC_FULLNAME_CAPACITY, TRUE, &error); - - if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) { - return *factory->NewStringFromAsciiChecked(kInvalidTag); +RUNTIME_FUNCTION(Runtime_DefaultNumberOption) { + HandleScope scope(isolate); + DCHECK_EQ(5, args.length()); + CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); + CONVERT_SMI_ARG_CHECKED(min, 1); + CONVERT_SMI_ARG_CHECKED(max, 2); + CONVERT_SMI_ARG_CHECKED(fallback, 3); + CONVERT_ARG_HANDLE_CHECKED(String, property, 4); + + Maybe<int> num = + Intl::DefaultNumberOption(isolate, value, min, max, fallback, property); + if (num.IsNothing()) { + return ReadOnlyRoots(isolate).exception(); } - - return *factory->NewStringFromAsciiChecked(result); + return Smi::FromInt(num.FromJust()); } -RUNTIME_FUNCTION(Runtime_AvailableLocalesOf) { +// ECMA 402 6.2.3 +RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { HandleScope scope(isolate); - Factory* factory = isolate->factory(); DCHECK_EQ(1, args.length()); - CONVERT_ARG_HANDLE_CHECKED(String, service, 0); - - const icu::Locale* available_locales = nullptr; - int32_t count = 0; - - if (service->IsUtf8EqualTo(CStrVector("collator"))) { - available_locales = icu::Collator::getAvailableLocales(count); - } else if (service->IsUtf8EqualTo(CStrVector("numberformat"))) { - available_locales = icu::NumberFormat::getAvailableLocales(count); - } else if (service->IsUtf8EqualTo(CStrVector("dateformat"))) { - available_locales = icu::DateFormat::getAvailableLocales(count); - } else if (service->IsUtf8EqualTo(CStrVector("breakiterator"))) { - available_locales = icu::BreakIterator::getAvailableLocales(count); - } else if (service->IsUtf8EqualTo(CStrVector("pluralrules"))) { - // TODO(littledan): For PluralRules, filter out locales that - // don't support PluralRules. - // PluralRules is missing an appropriate getAvailableLocales method, - // so we should filter from all locales, but it's not clear how; see - // https://ssl.icu-project.org/trac/ticket/12756 - available_locales = icu::Locale::getAvailableLocales(count); - } else if (service->IsUtf8EqualTo(CStrVector("relativetimeformat"))) { - // TODO(ftang): for now just use - // icu::NumberFormat::getAvailableLocales(count) until we migrate to - // Intl::GetAvailableLocales() - available_locales = icu::NumberFormat::getAvailableLocales(count); - } else { - UNREACHABLE(); - } + CONVERT_ARG_HANDLE_CHECKED(Object, locale, 0); - UErrorCode error = U_ZERO_ERROR; - char result[ULOC_FULLNAME_CAPACITY]; - Handle<JSObject> locales = factory->NewJSObject(isolate->object_function()); - - for (int32_t i = 0; i < count; ++i) { - const char* icu_name = available_locales[i].getName(); - - error = U_ZERO_ERROR; - // No need to force strict BCP47 rules. - uloc_toLanguageTag(icu_name, result, ULOC_FULLNAME_CAPACITY, FALSE, &error); - if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) { - // This shouldn't happen, but lets not break the user. - continue; - } - - RETURN_FAILURE_ON_EXCEPTION( - isolate, JSObject::SetOwnPropertyIgnoreAttributes( - locales, factory->NewStringFromAsciiChecked(result), - factory->NewNumber(i), NONE)); + std::string canonicalized; + if (!Intl::CanonicalizeLanguageTag(isolate, locale).To(&canonicalized)) { + return ReadOnlyRoots(isolate).exception(); } + return *isolate->factory()->NewStringFromAsciiChecked(canonicalized.c_str()); +} +RUNTIME_FUNCTION(Runtime_AvailableLocalesOf) { + HandleScope scope(isolate); + DCHECK_EQ(1, args.length()); + CONVERT_ARG_HANDLE_CHECKED(String, service, 0); + Handle<JSObject> locales; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, locales, Intl::AvailableLocalesOf(isolate, service)); return *locales; } RUNTIME_FUNCTION(Runtime_GetDefaultICULocale) { HandleScope scope(isolate); - Factory* factory = isolate->factory(); DCHECK_EQ(0, args.length()); + return *isolate->factory()->NewStringFromAsciiChecked( + Intl::DefaultLocale(isolate).c_str()); +} - icu::Locale default_locale; - - // Translate ICU's fallback locale to a well-known locale. - if (strcmp(default_locale.getName(), "en_US_POSIX") == 0) { - return *factory->NewStringFromStaticChars("en-US"); - } +RUNTIME_FUNCTION(Runtime_IsWellFormedCurrencyCode) { + HandleScope scope(isolate); + DCHECK_EQ(1, args.length()); + CONVERT_ARG_HANDLE_CHECKED(String, currency, 0); + return *(isolate->factory()->ToBoolean( + Intl::IsWellFormedCurrencyCode(isolate, currency))); +} - // Set the locale - char result[ULOC_FULLNAME_CAPACITY]; - UErrorCode status = U_ZERO_ERROR; - uloc_toLanguageTag(default_locale.getName(), result, ULOC_FULLNAME_CAPACITY, - FALSE, &status); - if (U_SUCCESS(status)) { - return *factory->NewStringFromAsciiChecked(result); - } +RUNTIME_FUNCTION(Runtime_DefineWEProperty) { + HandleScope scope(isolate); - return *factory->NewStringFromStaticChars("und"); + DCHECK_EQ(3, args.length()); + CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); + CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); + CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); + Intl::DefineWEProperty(isolate, target, key, value); + return ReadOnlyRoots(isolate).undefined_value(); } RUNTIME_FUNCTION(Runtime_IsInitializedIntlObjectOfType) { @@ -232,10 +216,10 @@ RUNTIME_FUNCTION(Runtime_CreateDateTimeFormat) { // Set date time formatter as embedder field of the resulting JS object. icu::SimpleDateFormat* date_format = DateFormat::InitializeDateTimeFormat(isolate, locale, options, resolved); + CHECK_NOT_NULL(date_format); - if (!date_format) return isolate->ThrowIllegalOperation(); - - local_object->SetEmbedderField(0, reinterpret_cast<Smi*>(date_format)); + local_object->SetEmbedderField(DateFormat::kSimpleDateFormatIndex, + reinterpret_cast<Smi*>(date_format)); // Make object handle weak so we can delete the data format once GC kicks in. Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); @@ -245,33 +229,6 @@ RUNTIME_FUNCTION(Runtime_CreateDateTimeFormat) { return *local_object; } -RUNTIME_FUNCTION(Runtime_InternalDateFormat) { - HandleScope scope(isolate); - - DCHECK_EQ(2, args.length()); - - CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0); - CONVERT_NUMBER_ARG_HANDLE_CHECKED(date, 1); - - double date_value = DateCache::TimeClip(date->Number()); - if (std::isnan(date_value)) { - THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewRangeError(MessageTemplate::kInvalidTimeValue)); - } - - icu::SimpleDateFormat* date_format = - DateFormat::UnpackDateFormat(isolate, date_format_holder); - CHECK_NOT_NULL(date_format); - - icu::UnicodeString result; - date_format->format(date_value, result); - - RETURN_RESULT_OR_FAILURE( - isolate, isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( - reinterpret_cast<const uint16_t*>(result.getBuffer()), - result.length()))); -} - RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { HandleScope scope(isolate); @@ -280,198 +237,103 @@ RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); - - Handle<JSFunction> constructor( - isolate->native_context()->intl_number_format_function(), isolate); - - Handle<JSObject> local_object; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object, - JSObject::New(constructor, constructor)); - - // Set number formatter as embedder field of the resulting JS object. - icu::DecimalFormat* number_format = - NumberFormat::InitializeNumberFormat(isolate, locale, options, resolved); - - if (!number_format) return isolate->ThrowIllegalOperation(); - - local_object->SetEmbedderField(NumberFormat::kDecimalFormatIndex, - reinterpret_cast<Smi*>(number_format)); - - Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); - GlobalHandles::MakeWeak(wrapper.location(), wrapper.location(), - NumberFormat::DeleteNumberFormat, - WeakCallbackType::kInternalFields); - return *local_object; -} - -RUNTIME_FUNCTION(Runtime_InternalNumberFormat) { - HandleScope scope(isolate); - - DCHECK_EQ(2, args.length()); - - CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0); - CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); - - Handle<Object> number_obj; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_obj, - Object::ToNumber(isolate, value)); - - double number = number_obj->Number(); - RETURN_RESULT_OR_FAILURE(isolate, NumberFormat::FormatNumber( - isolate, number_format_holder, number)); + RETURN_RESULT_OR_FAILURE( + isolate, Intl::CreateNumberFormat(isolate, locale, options, resolved)); } RUNTIME_FUNCTION(Runtime_CurrencyDigits) { + HandleScope scope(isolate); DCHECK_EQ(1, args.length()); - v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); - CONVERT_ARG_HANDLE_CHECKED(String, currency, 0); - - v8::String::Value currency_string(v8_isolate, v8::Utils::ToLocal(currency)); - - DisallowHeapAllocation no_gc; - UErrorCode status = U_ZERO_ERROR; - uint32_t fraction_digits = ucurr_getDefaultFractionDigits( - reinterpret_cast<const UChar*>(*currency_string), &status); - // For missing currency codes, default to the most common, 2 - if (!U_SUCCESS(status)) fraction_digits = 2; - return Smi::FromInt(fraction_digits); + return *Intl::CurrencyDigits(isolate, currency); } -RUNTIME_FUNCTION(Runtime_CreateCollator) { +RUNTIME_FUNCTION(Runtime_CollatorResolvedOptions) { HandleScope scope(isolate); - DCHECK_EQ(3, args.length()); - - CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); - CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); - CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); - - Handle<JSFunction> constructor( - isolate->native_context()->intl_collator_function(), isolate); - - Handle<JSObject> collator_holder; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, collator_holder, - JSObject::New(constructor, constructor)); + DCHECK_EQ(1, args.length()); + CONVERT_ARG_HANDLE_CHECKED(Object, collator_obj, 0); - if (!Collator::InitializeCollator(isolate, collator_holder, locale, options, - resolved)) { - return isolate->ThrowIllegalOperation(); + // 3. If pr does not have an [[InitializedCollator]] internal + // slot, throw a TypeError exception. + if (!collator_obj->IsJSCollator()) { + Handle<String> method_str = isolate->factory()->NewStringFromStaticChars( + "Intl.Collator.prototype.resolvedOptions"); + THROW_NEW_ERROR_RETURN_FAILURE( + isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, + method_str, collator_obj)); } - return *collator_holder; + Handle<JSCollator> collator = Handle<JSCollator>::cast(collator_obj); + + return *JSCollator::ResolvedOptions(isolate, collator); } -RUNTIME_FUNCTION(Runtime_InternalCompare) { +RUNTIME_FUNCTION(Runtime_PluralRulesResolvedOptions) { HandleScope scope(isolate); - DCHECK_EQ(3, args.length()); + DCHECK_EQ(1, args.length()); + CONVERT_ARG_HANDLE_CHECKED(Object, plural_rules_obj, 0); - CONVERT_ARG_HANDLE_CHECKED(JSObject, collator_holder, 0); - CONVERT_ARG_HANDLE_CHECKED(String, string1, 1); - CONVERT_ARG_HANDLE_CHECKED(String, string2, 2); - - icu::Collator* collator = Collator::UnpackCollator(isolate, collator_holder); - CHECK_NOT_NULL(collator); - - string1 = String::Flatten(isolate, string1); - string2 = String::Flatten(isolate, string2); - - UCollationResult result; - UErrorCode status = U_ZERO_ERROR; - { - DisallowHeapAllocation no_gc; - int32_t length1 = string1->length(); - int32_t length2 = string2->length(); - String::FlatContent flat1 = string1->GetFlatContent(); - String::FlatContent flat2 = string2->GetFlatContent(); - std::unique_ptr<uc16[]> sap1; - std::unique_ptr<uc16[]> sap2; - icu::UnicodeString string_val1( - FALSE, GetUCharBufferFromFlat(flat1, &sap1, length1), length1); - icu::UnicodeString string_val2( - FALSE, GetUCharBufferFromFlat(flat2, &sap2, length2), length2); - result = collator->compare(string_val1, string_val2, status); + // 3. If pr does not have an [[InitializedPluralRules]] internal + // slot, throw a TypeError exception. + if (!plural_rules_obj->IsJSPluralRules()) { + Handle<String> method_str = isolate->factory()->NewStringFromStaticChars( + "Intl.PluralRules.prototype.resolvedOptions"); + THROW_NEW_ERROR_RETURN_FAILURE( + isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, + method_str, plural_rules_obj)); } - if (U_FAILURE(status)) return isolate->ThrowIllegalOperation(); - return *isolate->factory()->NewNumberFromInt(result); + Handle<JSPluralRules> plural_rules = + Handle<JSPluralRules>::cast(plural_rules_obj); + + return *JSPluralRules::ResolvedOptions(isolate, plural_rules); } -RUNTIME_FUNCTION(Runtime_CreatePluralRules) { +RUNTIME_FUNCTION(Runtime_ParseExtension) { + Factory* factory = isolate->factory(); HandleScope scope(isolate); - - DCHECK_EQ(3, args.length()); - - CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); - CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); - CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); - - Handle<JSFunction> constructor( - isolate->native_context()->intl_plural_rules_function(), isolate); - - Handle<JSObject> local_object; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object, - JSObject::New(constructor, constructor)); - - // Set pluralRules as internal field of the resulting JS object. - icu::PluralRules* plural_rules; - icu::DecimalFormat* decimal_format; - bool success = PluralRules::InitializePluralRules( - isolate, locale, options, resolved, &plural_rules, &decimal_format); - - if (!success) return isolate->ThrowIllegalOperation(); - - local_object->SetEmbedderField(0, reinterpret_cast<Smi*>(plural_rules)); - local_object->SetEmbedderField(1, reinterpret_cast<Smi*>(decimal_format)); - - Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); - GlobalHandles::MakeWeak(wrapper.location(), wrapper.location(), - PluralRules::DeletePluralRules, - WeakCallbackType::kInternalFields); - return *local_object; + DCHECK_EQ(1, args.length()); + CONVERT_ARG_HANDLE_CHECKED(String, extension, 0); + std::map<std::string, std::string> map; + Intl::ParseExtension(isolate, std::string(extension->ToCString().get()), map); + Handle<JSObject> extension_map = + isolate->factory()->NewJSObjectWithNullProto(); + for (std::map<std::string, std::string>::iterator it = map.begin(); + it != map.end(); it++) { + JSObject::AddProperty( + isolate, extension_map, + factory->NewStringFromAsciiChecked(it->first.c_str()), + factory->NewStringFromAsciiChecked(it->second.c_str()), NONE); + } + return *extension_map; } RUNTIME_FUNCTION(Runtime_PluralRulesSelect) { HandleScope scope(isolate); DCHECK_EQ(2, args.length()); - - CONVERT_ARG_HANDLE_CHECKED(JSObject, plural_rules_holder, 0); + CONVERT_ARG_HANDLE_CHECKED(Object, plural_rules_obj, 0); CONVERT_ARG_HANDLE_CHECKED(Object, number, 1); - icu::PluralRules* plural_rules = - PluralRules::UnpackPluralRules(isolate, plural_rules_holder); - CHECK_NOT_NULL(plural_rules); - - icu::DecimalFormat* number_format = - PluralRules::UnpackNumberFormat(isolate, plural_rules_holder); - CHECK_NOT_NULL(number_format); - - // Currently, PluralRules doesn't implement all the options for rounding that - // the Intl spec provides; format and parse the number to round to the - // appropriate amount, then apply PluralRules. - // - // TODO(littledan): If a future ICU version supports an extended API to avoid - // this step, then switch to that API. Bug thread: - // http://bugs.icu-project.org/trac/ticket/12763 - icu::UnicodeString rounded_string; - number_format->format(number->Number(), rounded_string); - - icu::Formattable formattable; - UErrorCode status = U_ZERO_ERROR; - number_format->parse(rounded_string, formattable, status); - if (!U_SUCCESS(status)) return isolate->ThrowIllegalOperation(); - - double rounded = formattable.getDouble(status); - if (!U_SUCCESS(status)) return isolate->ThrowIllegalOperation(); - - icu::UnicodeString result = plural_rules->select(rounded); - return *isolate->factory() - ->NewStringFromTwoByte(Vector<const uint16_t>( - reinterpret_cast<const uint16_t*>(result.getBuffer()), - result.length())) - .ToHandleChecked(); + // 3. If pr does not have an [[InitializedPluralRules]] internal + // slot, throw a TypeError exception. + if (!plural_rules_obj->IsJSPluralRules()) { + Handle<String> method_str = isolate->factory()->NewStringFromStaticChars( + "Intl.PluralRules.prototype.select"); + THROW_NEW_ERROR_RETURN_FAILURE( + isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, + method_str, plural_rules_obj)); + } + + Handle<JSPluralRules> plural_rules = + Handle<JSPluralRules>::cast(plural_rules_obj); + + // 4. Return ? ResolvePlural(pr, n). + + RETURN_RESULT_OR_FAILURE( + isolate, JSPluralRules::ResolvePlural(isolate, plural_rules, number)); } RUNTIME_FUNCTION(Runtime_CreateBreakIterator) { @@ -493,12 +355,15 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) { // Set break iterator as embedder field of the resulting JS object. icu::BreakIterator* break_iterator = V8BreakIterator::InitializeBreakIterator( isolate, locale, options, resolved); + CHECK_NOT_NULL(break_iterator); if (!break_iterator) return isolate->ThrowIllegalOperation(); - local_object->SetEmbedderField(0, reinterpret_cast<Smi*>(break_iterator)); + local_object->SetEmbedderField(V8BreakIterator::kBreakIteratorIndex, + reinterpret_cast<Smi*>(break_iterator)); // Make sure that the pointer to adopted text is nullptr. - local_object->SetEmbedderField(1, static_cast<Smi*>(nullptr)); + local_object->SetEmbedderField(V8BreakIterator::kUnicodeStringIndex, + static_cast<Smi*>(nullptr)); // Make object handle weak so we can delete the break iterator once GC kicks // in. @@ -509,36 +374,6 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) { return *local_object; } -RUNTIME_FUNCTION(Runtime_BreakIteratorAdoptText) { - HandleScope scope(isolate); - - DCHECK_EQ(2, args.length()); - - CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); - CONVERT_ARG_HANDLE_CHECKED(String, text, 1); - - icu::BreakIterator* break_iterator = - V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); - CHECK_NOT_NULL(break_iterator); - - icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>( - break_iterator_holder->GetEmbedderField(1)); - delete u_text; - - int length = text->length(); - text = String::Flatten(isolate, text); - DisallowHeapAllocation no_gc; - String::FlatContent flat = text->GetFlatContent(); - std::unique_ptr<uc16[]> sap; - const UChar* text_value = GetUCharBufferFromFlat(flat, &sap, length); - u_text = new icu::UnicodeString(text_value, length); - break_iterator_holder->SetEmbedderField(1, reinterpret_cast<Smi*>(u_text)); - - break_iterator->setText(*u_text); - - return ReadOnlyRoots(isolate).undefined_value(); -} - RUNTIME_FUNCTION(Runtime_BreakIteratorFirst) { HandleScope scope(isolate); @@ -547,7 +382,7 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorFirst) { CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); icu::BreakIterator* break_iterator = - V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); + V8BreakIterator::UnpackBreakIterator(break_iterator_holder); CHECK_NOT_NULL(break_iterator); return *isolate->factory()->NewNumberFromInt(break_iterator->first()); @@ -561,7 +396,7 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorNext) { CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); icu::BreakIterator* break_iterator = - V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); + V8BreakIterator::UnpackBreakIterator(break_iterator_holder); CHECK_NOT_NULL(break_iterator); return *isolate->factory()->NewNumberFromInt(break_iterator->next()); @@ -575,7 +410,7 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorCurrent) { CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); icu::BreakIterator* break_iterator = - V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); + V8BreakIterator::UnpackBreakIterator(break_iterator_holder); CHECK_NOT_NULL(break_iterator); return *isolate->factory()->NewNumberFromInt(break_iterator->current()); @@ -589,7 +424,7 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) { CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); icu::BreakIterator* break_iterator = - V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); + V8BreakIterator::UnpackBreakIterator(break_iterator_holder); CHECK_NOT_NULL(break_iterator); // TODO(cira): Remove cast once ICU fixes base BreakIterator class. @@ -612,63 +447,50 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) { } } -RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) { +RUNTIME_FUNCTION(Runtime_ToLocaleDateTime) { HandleScope scope(isolate); - DCHECK_EQ(args.length(), 1); - CONVERT_ARG_HANDLE_CHECKED(String, s, 0); - s = String::Flatten(isolate, s); - return ConvertToLower(s, isolate); + + DCHECK_EQ(6, args.length()); + + CONVERT_ARG_HANDLE_CHECKED(Object, date, 0); + CONVERT_ARG_HANDLE_CHECKED(Object, locales, 1); + CONVERT_ARG_HANDLE_CHECKED(Object, options, 2); + CONVERT_ARG_HANDLE_CHECKED(String, required, 3); + CONVERT_ARG_HANDLE_CHECKED(String, defaults, 4); + CONVERT_ARG_HANDLE_CHECKED(String, service, 5); + + RETURN_RESULT_OR_FAILURE( + isolate, DateFormat::ToLocaleDateTime( + isolate, date, locales, options, required->ToCString().get(), + defaults->ToCString().get(), service->ToCString().get())); } -RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) { +RUNTIME_FUNCTION(Runtime_ToDateTimeOptions) { + HandleScope scope(isolate); + DCHECK_EQ(args.length(), 3); + CONVERT_ARG_HANDLE_CHECKED(Object, options, 0); + CONVERT_ARG_HANDLE_CHECKED(String, required, 1); + CONVERT_ARG_HANDLE_CHECKED(String, defaults, 2); + RETURN_RESULT_OR_FAILURE( + isolate, DateFormat::ToDateTimeOptions(isolate, options, + required->ToCString().get(), + defaults->ToCString().get())); +} + +RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) { HandleScope scope(isolate); DCHECK_EQ(args.length(), 1); CONVERT_ARG_HANDLE_CHECKED(String, s, 0); s = String::Flatten(isolate, s); - return ConvertToUpper(s, isolate); + RETURN_RESULT_OR_FAILURE(isolate, ConvertToLower(s, isolate)); } -RUNTIME_FUNCTION(Runtime_StringLocaleConvertCase) { +RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) { HandleScope scope(isolate); - DCHECK_EQ(args.length(), 3); + DCHECK_EQ(args.length(), 1); CONVERT_ARG_HANDLE_CHECKED(String, s, 0); - CONVERT_BOOLEAN_ARG_CHECKED(is_upper, 1); - CONVERT_ARG_HANDLE_CHECKED(String, lang_arg, 2); - - // Primary language tag can be up to 8 characters long in theory. - // https://tools.ietf.org/html/bcp47#section-2.2.1 - DCHECK_LE(lang_arg->length(), 8); - lang_arg = String::Flatten(isolate, lang_arg); s = String::Flatten(isolate, s); - - // All the languages requiring special-handling have two-letter codes. - // Note that we have to check for '!= 2' here because private-use language - // tags (x-foo) or grandfathered irregular tags (e.g. i-enochian) would have - // only 'x' or 'i' when they get here. - if (V8_UNLIKELY(lang_arg->length() != 2)) - return ConvertCase(s, is_upper, isolate); - - char c1, c2; - { - DisallowHeapAllocation no_gc; - String::FlatContent lang = lang_arg->GetFlatContent(); - c1 = lang.Get(0); - c2 = lang.Get(1); - } - // TODO(jshin): Consider adding a fast path for ASCII or Latin-1. The fastpath - // in the root locale needs to be adjusted for az, lt and tr because even case - // mapping of ASCII range characters are different in those locales. - // Greek (el) does not require any adjustment. - if (V8_UNLIKELY(c1 == 't' && c2 == 'r')) - return LocaleConvertCase(s, isolate, is_upper, "tr"); - if (V8_UNLIKELY(c1 == 'e' && c2 == 'l')) - return LocaleConvertCase(s, isolate, is_upper, "el"); - if (V8_UNLIKELY(c1 == 'l' && c2 == 't')) - return LocaleConvertCase(s, isolate, is_upper, "lt"); - if (V8_UNLIKELY(c1 == 'a' && c2 == 'z')) - return LocaleConvertCase(s, isolate, is_upper, "az"); - - return ConvertCase(s, is_upper, isolate); + RETURN_RESULT_OR_FAILURE(isolate, ConvertToUpper(s, isolate)); } RUNTIME_FUNCTION(Runtime_DateCacheVersion) { @@ -704,5 +526,18 @@ RUNTIME_FUNCTION(Runtime_IntlUnwrapReceiver) { check_legacy_constructor)); } +RUNTIME_FUNCTION(Runtime_SupportedLocalesOf) { + HandleScope scope(isolate); + + DCHECK_EQ(args.length(), 3); + + CONVERT_ARG_HANDLE_CHECKED(String, service, 0); + CONVERT_ARG_HANDLE_CHECKED(Object, locales, 1); + CONVERT_ARG_HANDLE_CHECKED(Object, options, 2); + + RETURN_RESULT_OR_FAILURE( + isolate, Intl::SupportedLocalesOf(isolate, service, locales, options)); +} + } // namespace internal } // namespace v8 diff --git a/deps/v8/src/runtime/runtime-literals.cc b/deps/v8/src/runtime/runtime-literals.cc index 6e17ba85d4..d5111f7efa 100644 --- a/deps/v8/src/runtime/runtime-literals.cc +++ b/deps/v8/src/runtime/runtime-literals.cc @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include "src/allocation-site-scopes.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/ast/ast.h" #include "src/isolate-inl.h" #include "src/objects/hash-table-inl.h" #include "src/objects/js-regexp-inl.h" #include "src/objects/literal-objects-inl.h" +#include "src/runtime/runtime-utils.h" #include "src/runtime/runtime.h" namespace v8 { @@ -22,7 +21,7 @@ bool IsUninitializedLiteralSite(Object* literal_site) { return literal_site == Smi::kZero; } -bool HasBoilerplate(Isolate* isolate, Handle<Object> literal_site) { +bool HasBoilerplate(Handle<Object> literal_site) { return !literal_site->IsSmi(); } @@ -196,7 +195,7 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk( UNREACHABLE(); break; -#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: +#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) case TYPE##_ELEMENTS: TYPED_ARRAYS(TYPED_ARRAY_CASE) #undef TYPED_ARRAY_CASE @@ -317,11 +316,11 @@ MaybeHandle<JSObject> DeepCopy(Handle<JSObject> object, return copy; } -struct ObjectBoilerplate { +struct ObjectLiteralHelper { static Handle<JSObject> Create(Isolate* isolate, Handle<HeapObject> description, int flags, PretenureFlag pretenure_flag) { - Handle<Context> native_context = isolate->native_context(); + Handle<NativeContext> native_context = isolate->native_context(); Handle<ObjectBoilerplateDescription> object_boilerplate_description = Handle<ObjectBoilerplateDescription>::cast(description); bool use_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; @@ -392,7 +391,7 @@ struct ObjectBoilerplate { } }; -struct ArrayBoilerplate { +struct ArrayLiteralHelper { static Handle<JSObject> Create(Isolate* isolate, Handle<HeapObject> description, int flags, PretenureFlag pretenure_flag) { @@ -455,20 +454,43 @@ Handle<Object> InnerCreateBoilerplate(Isolate* isolate, if (description->IsObjectBoilerplateDescription()) { Handle<ObjectBoilerplateDescription> object_boilerplate_description = Handle<ObjectBoilerplateDescription>::cast(description); - return ObjectBoilerplate::Create(isolate, object_boilerplate_description, - object_boilerplate_description->flags(), - pretenure_flag); + return ObjectLiteralHelper::Create(isolate, object_boilerplate_description, + object_boilerplate_description->flags(), + pretenure_flag); } else { DCHECK(description->IsArrayBoilerplateDescription()); Handle<ArrayBoilerplateDescription> array_boilerplate_description = Handle<ArrayBoilerplateDescription>::cast(description); - return ArrayBoilerplate::Create( + return ArrayLiteralHelper::Create( isolate, array_boilerplate_description, array_boilerplate_description->elements_kind(), pretenure_flag); } } -template <typename Boilerplate> +inline DeepCopyHints DecodeCopyHints(int flags) { + DeepCopyHints copy_hints = + (flags & AggregateLiteral::kIsShallow) ? kObjectIsShallow : kNoHints; + if (FLAG_track_double_fields && !FLAG_unbox_double_fields) { + // Make sure we properly clone mutable heap numbers on 32-bit platforms. + copy_hints = kNoHints; + } + return copy_hints; +} + +template <typename LiteralHelper> +MaybeHandle<JSObject> CreateLiteralWithoutAllocationSite( + Isolate* isolate, Handle<HeapObject> description, int flags) { + Handle<JSObject> literal = + LiteralHelper::Create(isolate, description, flags, NOT_TENURED); + DeepCopyHints copy_hints = DecodeCopyHints(flags); + if (copy_hints == kNoHints) { + DeprecationUpdateContext update_context(isolate); + RETURN_ON_EXCEPTION(isolate, DeepWalk(literal, &update_context), JSObject); + } + return literal; +} + +template <typename LiteralHelper> MaybeHandle<JSObject> CreateLiteral(Isolate* isolate, Handle<FeedbackVector> vector, int literals_index, @@ -476,41 +498,25 @@ MaybeHandle<JSObject> CreateLiteral(Isolate* isolate, FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index)); CHECK(literals_slot.ToInt() < vector->length()); Handle<Object> literal_site(vector->Get(literals_slot)->ToObject(), isolate); - DeepCopyHints copy_hints = - (flags & AggregateLiteral::kIsShallow) ? kObjectIsShallow : kNoHints; - if (FLAG_track_double_fields && !FLAG_unbox_double_fields) { - // Make sure we properly clone mutable heap numbers on 32-bit platforms. - copy_hints = kNoHints; - } + DeepCopyHints copy_hints = DecodeCopyHints(flags); Handle<AllocationSite> site; Handle<JSObject> boilerplate; - if (HasBoilerplate(isolate, literal_site)) { + if (HasBoilerplate(literal_site)) { site = Handle<AllocationSite>::cast(literal_site); boilerplate = Handle<JSObject>(site->boilerplate(), isolate); } else { // Eagerly create AllocationSites for literals that contain an Array. bool needs_initial_allocation_site = (flags & AggregateLiteral::kNeedsInitialAllocationSite) != 0; - // TODO(cbruni): Even in the case where we need an initial allocation site - // we could still create the boilerplate lazily to save memory. if (!needs_initial_allocation_site && IsUninitializedLiteralSite(*literal_site)) { PreInitializeLiteralSite(vector, literals_slot); - boilerplate = - Boilerplate::Create(isolate, description, flags, NOT_TENURED); - if (copy_hints == kNoHints) { - DeprecationUpdateContext update_context(isolate); - RETURN_ON_EXCEPTION(isolate, DeepWalk(boilerplate, &update_context), - JSObject); - } - return boilerplate; + return CreateLiteralWithoutAllocationSite<LiteralHelper>( + isolate, description, flags); } else { - PretenureFlag pretenure_flag = - Heap::InNewSpace(*vector) ? NOT_TENURED : TENURED; - boilerplate = - Boilerplate::Create(isolate, description, flags, pretenure_flag); + boilerplate = LiteralHelper::Create(isolate, description, flags, TENURED); } // Install AllocationSite objects. AllocationSiteCreationContext creation_context(isolate); @@ -544,8 +550,28 @@ RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) { CONVERT_ARG_HANDLE_CHECKED(ObjectBoilerplateDescription, description, 2); CONVERT_SMI_ARG_CHECKED(flags, 3); RETURN_RESULT_OR_FAILURE( - isolate, CreateLiteral<ObjectBoilerplate>(isolate, vector, literals_index, - description, flags)); + isolate, CreateLiteral<ObjectLiteralHelper>( + isolate, vector, literals_index, description, flags)); +} + +RUNTIME_FUNCTION(Runtime_CreateObjectLiteralWithoutAllocationSite) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(ObjectBoilerplateDescription, description, 0); + CONVERT_SMI_ARG_CHECKED(flags, 1); + RETURN_RESULT_OR_FAILURE( + isolate, CreateLiteralWithoutAllocationSite<ObjectLiteralHelper>( + isolate, description, flags)); +} + +RUNTIME_FUNCTION(Runtime_CreateArrayLiteralWithoutAllocationSite) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(ArrayBoilerplateDescription, description, 0); + CONVERT_SMI_ARG_CHECKED(flags, 1); + RETURN_RESULT_OR_FAILURE( + isolate, CreateLiteralWithoutAllocationSite<ArrayLiteralHelper>( + isolate, description, flags)); } RUNTIME_FUNCTION(Runtime_CreateArrayLiteral) { @@ -556,8 +582,8 @@ RUNTIME_FUNCTION(Runtime_CreateArrayLiteral) { CONVERT_ARG_HANDLE_CHECKED(ArrayBoilerplateDescription, elements, 2); CONVERT_SMI_ARG_CHECKED(flags, 3); RETURN_RESULT_OR_FAILURE( - isolate, CreateLiteral<ArrayBoilerplate>(isolate, vector, literals_index, - elements, flags)); + isolate, CreateLiteral<ArrayLiteralHelper>( + isolate, vector, literals_index, elements, flags)); } RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) { @@ -573,7 +599,7 @@ RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) { // Check if boilerplate exists. If not, create it first. Handle<Object> literal_site(vector->Get(literal_slot)->ToObject(), isolate); Handle<Object> boilerplate; - if (!HasBoilerplate(isolate, literal_site)) { + if (!HasBoilerplate(literal_site)) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, boilerplate, JSRegExp::New(isolate, pattern, JSRegExp::Flags(flags))); diff --git a/deps/v8/src/runtime/runtime-maths.cc b/deps/v8/src/runtime/runtime-maths.cc index 1804f93229..7695c14657 100644 --- a/deps/v8/src/runtime/runtime-maths.cc +++ b/deps/v8/src/runtime/runtime-maths.cc @@ -5,7 +5,6 @@ #include "src/runtime/runtime-utils.h" #include "src/arguments.h" -#include "src/assembler.h" #include "src/base/utils/random-number-generator.h" #include "src/bootstrapper.h" #include "src/counters.h" diff --git a/deps/v8/src/runtime/runtime-module.cc b/deps/v8/src/runtime/runtime-module.cc index 5c59a2f997..91dac4fa1c 100644 --- a/deps/v8/src/runtime/runtime-module.cc +++ b/deps/v8/src/runtime/runtime-module.cc @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/counters.h" #include "src/objects-inl.h" #include "src/objects/js-promise.h" #include "src/objects/module.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/runtime/runtime-numbers.cc b/deps/v8/src/runtime/runtime-numbers.cc index 2eac95923f..14b91c8f1b 100644 --- a/deps/v8/src/runtime/runtime-numbers.cc +++ b/deps/v8/src/runtime/runtime-numbers.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/base/bits.h" #include "src/bootstrapper.h" #include "src/isolate-inl.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { @@ -70,12 +69,12 @@ RUNTIME_FUNCTION(Runtime_StringParseFloat) { return *isolate->factory()->NewNumber(value); } -RUNTIME_FUNCTION(Runtime_NumberToStringSkipCache) { +RUNTIME_FUNCTION(Runtime_NumberToString) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_NUMBER_ARG_HANDLE_CHECKED(number, 0); - return *isolate->factory()->NumberToString(number, false); + return *isolate->factory()->NumberToString(number); } // Compare two Smis x, y as if they were converted to strings and then diff --git a/deps/v8/src/runtime/runtime-object.cc b/deps/v8/src/runtime/runtime-object.cc index b3a8b18906..81478b0e1b 100644 --- a/deps/v8/src/runtime/runtime-object.cc +++ b/deps/v8/src/runtime/runtime-object.cc @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/bootstrapper.h" #include "src/debug/debug.h" #include "src/isolate-inl.h" #include "src/messages.h" #include "src/objects/hash-table-inl.h" +#include "src/objects/js-array-inl.h" #include "src/objects/property-descriptor-object.h" #include "src/property-descriptor.h" +#include "src/runtime/runtime-utils.h" #include "src/runtime/runtime.h" namespace v8 { @@ -405,34 +405,26 @@ RUNTIME_FUNCTION(Runtime_AddDictionaryProperty) { RUNTIME_FUNCTION(Runtime_ObjectCreate) { HandleScope scope(isolate); Handle<Object> prototype = args.at(0); + Handle<Object> properties = args.at(1); + Handle<JSObject> obj; + // 1. If Type(O) is neither Object nor Null, throw a TypeError exception. if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { THROW_NEW_ERROR_RETURN_FAILURE( isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); } + // 2. Let obj be ObjectCreate(O). + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, obj, JSObject::ObjectCreate(isolate, prototype)); - // Generate the map with the specified {prototype} based on the Object - // function's initial map from the current native context. - // TODO(bmeurer): Use a dedicated cache for Object.create; think about - // slack tracking for Object.create. - Handle<Map> map = - Map::GetObjectCreateMap(isolate, Handle<HeapObject>::cast(prototype)); - - // Actually allocate the object. - Handle<JSObject> object; - if (map->is_dictionary_map()) { - object = isolate->factory()->NewSlowJSObjectFromMap(map); - } else { - object = isolate->factory()->NewJSObjectFromMap(map); - } - - // Define the properties if properties was specified and is not undefined. - Handle<Object> properties = args.at(1); + // 3. If Properties is not undefined, then if (!properties->IsUndefined(isolate)) { - RETURN_FAILURE_ON_EXCEPTION( - isolate, JSReceiver::DefineProperties(isolate, object, properties)); + // a. Return ? ObjectDefineProperties(obj, Properties). + // Define the properties if properties was specified and is not undefined. + RETURN_RESULT_OR_FAILURE( + isolate, JSReceiver::DefineProperties(isolate, obj, properties)); } - - return *object; + // 4. Return obj. + return *obj; } MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, @@ -1239,27 +1231,6 @@ RUNTIME_FUNCTION(Runtime_CreateDataProperty) { return *value; } -// Checks that 22.2.2.1.1 Runtime Semantics: IterableToList produces exactly the -// same result as doing nothing. -RUNTIME_FUNCTION(Runtime_IterableToListCanBeElided) { - HandleScope scope(isolate); - DCHECK_EQ(1, args.length()); - CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); - - // If an iterator symbol is added to the Number prototype, we could see a Smi. - if (obj->IsSmi()) return isolate->heap()->ToBoolean(false); - if (!HeapObject::cast(*obj)->IsJSObject()) { - return isolate->heap()->ToBoolean(false); - } - - // While iteration alone may not have observable side-effects, calling - // toNumber on an object will. Make sure the arg is not an array of objects. - ElementsKind kind = JSObject::cast(*obj)->GetElementsKind(); - if (!IsFastNumberElementsKind(kind)) return isolate->heap()->ToBoolean(false); - - return isolate->heap()->ToBoolean(!obj->IterationHasObservableEffects()); -} - RUNTIME_FUNCTION(Runtime_GetOwnPropertyDescriptor) { HandleScope scope(isolate); diff --git a/deps/v8/src/runtime/runtime-promise.cc b/deps/v8/src/runtime/runtime-promise.cc index ec78904710..eeb92e9a35 100644 --- a/deps/v8/src/runtime/runtime-promise.cc +++ b/deps/v8/src/runtime/runtime-promise.cc @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/api.h" -#include "src/arguments.h" +#include "src/api-inl.h" +#include "src/arguments-inl.h" #include "src/counters.h" #include "src/debug/debug.h" #include "src/elements.h" #include "src/objects-inl.h" #include "src/objects/js-promise-inl.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/runtime/runtime-proxy.cc b/deps/v8/src/runtime/runtime-proxy.cc index 8101ea6d29..7eeee631be 100644 --- a/deps/v8/src/runtime/runtime-proxy.cc +++ b/deps/v8/src/runtime/runtime-proxy.cc @@ -4,7 +4,7 @@ #include "src/runtime/runtime-utils.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/elements.h" #include "src/heap/factory.h" #include "src/isolate-inl.h" diff --git a/deps/v8/src/runtime/runtime-regexp.cc b/deps/v8/src/runtime/runtime-regexp.cc index f58a3dd6f7..3e77bf1f3b 100644 --- a/deps/v8/src/runtime/runtime-regexp.cc +++ b/deps/v8/src/runtime/runtime-regexp.cc @@ -2,19 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include <functional> -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/conversions-inl.h" #include "src/isolate-inl.h" #include "src/messages.h" +#include "src/objects/js-array-inl.h" #include "src/regexp/jsregexp-inl.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-utils.h" -#include "src/string-builder.h" +#include "src/runtime/runtime-utils.h" +#include "src/string-builder-inl.h" #include "src/string-search.h" +#include "src/zone/zone-chunk-list.h" namespace v8 { namespace internal { @@ -65,7 +66,7 @@ int LookupNamedCapture(std::function<bool(String*)> name_matches, class CompiledReplacement { public: explicit CompiledReplacement(Zone* zone) - : parts_(1, zone), replacement_substrings_(0, zone), zone_(zone) {} + : parts_(zone), replacement_substrings_(zone) {} // Return whether the replacement is simple. bool Compile(Isolate* isolate, Handle<JSRegExp> regexp, @@ -77,9 +78,7 @@ class CompiledReplacement { int32_t* match); // Number of distinct parts of the replacement pattern. - int parts() { return parts_.length(); } - - Zone* zone() const { return zone_; } + int parts() { return static_cast<int>(parts_.size()); } private: enum PartType { @@ -142,10 +141,10 @@ class CompiledReplacement { }; template <typename Char> - bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts, + bool ParseReplacementPattern(ZoneChunkList<ReplacementPart>* parts, Vector<Char> characters, FixedArray* capture_name_map, int capture_count, - int subject_length, Zone* zone) { + int subject_length) { // Equivalent to String::GetSubstitution, except that this method converts // the replacement string into an internal representation that avoids // repeated parsing when used repeatedly. @@ -163,9 +162,8 @@ class CompiledReplacement { case '$': if (i > last) { // There is a substring before. Include the first "$". - parts->Add( - ReplacementPart::ReplacementSubString(last, next_index), - zone); + parts->push_back( + ReplacementPart::ReplacementSubString(last, next_index)); last = next_index + 1; // Continue after the second "$". } else { // Let the next substring start with the second "$". @@ -175,25 +173,25 @@ class CompiledReplacement { break; case '`': if (i > last) { - parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); + parts->push_back(ReplacementPart::ReplacementSubString(last, i)); } - parts->Add(ReplacementPart::SubjectPrefix(), zone); + parts->push_back(ReplacementPart::SubjectPrefix()); i = next_index; last = i + 1; break; case '\'': if (i > last) { - parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); + parts->push_back(ReplacementPart::ReplacementSubString(last, i)); } - parts->Add(ReplacementPart::SubjectSuffix(subject_length), zone); + parts->push_back(ReplacementPart::SubjectSuffix(subject_length)); i = next_index; last = i + 1; break; case '&': if (i > last) { - parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); + parts->push_back(ReplacementPart::ReplacementSubString(last, i)); } - parts->Add(ReplacementPart::SubjectMatch(), zone); + parts->push_back(ReplacementPart::SubjectMatch()); i = next_index; last = i + 1; break; @@ -226,11 +224,11 @@ class CompiledReplacement { } if (capture_ref > 0) { if (i > last) { - parts->Add(ReplacementPart::ReplacementSubString(last, i), - zone); + parts->push_back( + ReplacementPart::ReplacementSubString(last, i)); } DCHECK(capture_ref <= capture_count); - parts->Add(ReplacementPart::SubjectCapture(capture_ref), zone); + parts->push_back(ReplacementPart::SubjectCapture(capture_ref)); last = next_index + 1; } i = next_index; @@ -281,12 +279,12 @@ class CompiledReplacement { (1 <= capture_index && capture_index <= capture_count)); if (i > last) { - parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); + parts->push_back(ReplacementPart::ReplacementSubString(last, i)); } - parts->Add((capture_index == -1) - ? ReplacementPart::EmptyReplacement() - : ReplacementPart::SubjectCapture(capture_index), - zone); + parts->push_back( + (capture_index == -1) + ? ReplacementPart::EmptyReplacement() + : ReplacementPart::SubjectCapture(capture_index)); last = closing_bracket_index + 1; i = closing_bracket_index; break; @@ -302,15 +300,14 @@ class CompiledReplacement { // Replacement is simple. Do not use Apply to do the replacement. return true; } else { - parts->Add(ReplacementPart::ReplacementSubString(last, length), zone); + parts->push_back(ReplacementPart::ReplacementSubString(last, length)); } } return false; } - ZoneList<ReplacementPart> parts_; - ZoneList<Handle<String> > replacement_substrings_; - Zone* zone_; + ZoneChunkList<ReplacementPart> parts_; + ZoneVector<Handle<String>> replacement_substrings_; }; bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp, @@ -334,31 +331,31 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp, if (content.IsOneByte()) { simple = ParseReplacementPattern(&parts_, content.ToOneByteVector(), capture_name_map, capture_count, - subject_length, zone()); + subject_length); } else { DCHECK(content.IsTwoByte()); simple = ParseReplacementPattern(&parts_, content.ToUC16Vector(), capture_name_map, capture_count, - subject_length, zone()); + subject_length); } if (simple) return true; } // Find substrings of replacement string and create them as String objects. int substring_index = 0; - for (int i = 0, n = parts_.length(); i < n; i++) { - int tag = parts_[i].tag; + for (ReplacementPart& part : parts_) { + int tag = part.tag; if (tag <= 0) { // A replacement string slice. int from = -tag; - int to = parts_[i].data; - replacement_substrings_.Add( - isolate->factory()->NewSubString(replacement, from, to), zone()); - parts_[i].tag = REPLACEMENT_SUBSTRING; - parts_[i].data = substring_index; + int to = part.data; + replacement_substrings_.push_back( + isolate->factory()->NewSubString(replacement, from, to)); + part.tag = REPLACEMENT_SUBSTRING; + part.data = substring_index; substring_index++; } else if (tag == REPLACEMENT_STRING) { - replacement_substrings_.Add(replacement, zone()); - parts_[i].data = substring_index; + replacement_substrings_.push_back(replacement); + part.data = substring_index; substring_index++; } } @@ -368,9 +365,8 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp, void CompiledReplacement::Apply(ReplacementStringBuilder* builder, int match_from, int match_to, int32_t* match) { - DCHECK_LT(0, parts_.length()); - for (int i = 0, n = parts_.length(); i < n; i++) { - ReplacementPart part = parts_[i]; + DCHECK_LT(0, parts_.size()); + for (ReplacementPart& part : parts_) { switch (part.tag) { case SUBJECT_PREFIX: if (match_from > 0) builder->AddSubjectSlice(0, match_from); @@ -1327,15 +1323,19 @@ V8_WARN_UNUSED_RESULT MaybeHandle<String> RegExpReplace( Object::ToLength(isolate, last_index_obj), String); last_index = PositiveNumberToUint32(*last_index_obj); - - if (last_index > static_cast<uint32_t>(string->length())) last_index = 0; } - Handle<Object> match_indices_obj; - ASSIGN_RETURN_ON_EXCEPTION( - isolate, match_indices_obj, - RegExpImpl::Exec(isolate, regexp, string, last_index, last_match_info), - String); + Handle<Object> match_indices_obj(ReadOnlyRoots(isolate).null_value(), + isolate); + + // A lastIndex exceeding the string length always always returns null + // (signalling failure) in RegExpBuiltinExec, thus we can skip the call. + if (last_index <= static_cast<uint32_t>(string->length())) { + ASSIGN_RETURN_ON_EXCEPTION(isolate, match_indices_obj, + RegExpImpl::Exec(isolate, regexp, string, + last_index, last_match_info), + String); + } if (match_indices_obj->IsNull(isolate)) { if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER); @@ -1658,8 +1658,8 @@ RUNTIME_FUNCTION(Runtime_RegExpSplit) { factory->undefined_value())); if (result->IsNull(isolate)) { - string_index = static_cast<uint32_t>(RegExpUtils::AdvanceStringIndex( - isolate, string, string_index, unicode)); + string_index = static_cast<uint32_t>( + RegExpUtils::AdvanceStringIndex(string, string_index, unicode)); continue; } @@ -1673,8 +1673,8 @@ RUNTIME_FUNCTION(Runtime_RegExpSplit) { const uint32_t end = std::min(PositiveNumberToUint32(*last_index_obj), length); if (end == prev_string_index) { - string_index = static_cast<uint32_t>(RegExpUtils::AdvanceStringIndex( - isolate, string, string_index, unicode)); + string_index = static_cast<uint32_t>( + RegExpUtils::AdvanceStringIndex(string, string_index, unicode)); continue; } diff --git a/deps/v8/src/runtime/runtime-scopes.cc b/deps/v8/src/runtime/runtime-scopes.cc index 93a0629783..4772f400b3 100644 --- a/deps/v8/src/runtime/runtime-scopes.cc +++ b/deps/v8/src/runtime/runtime-scopes.cc @@ -2,12 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include <memory> #include "src/accessors.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/ast/scopes.h" #include "src/bootstrapper.h" #include "src/deoptimizer.h" @@ -15,6 +13,7 @@ #include "src/isolate-inl.h" #include "src/messages.h" #include "src/objects/module-inl.h" +#include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { @@ -671,8 +670,8 @@ RUNTIME_FUNCTION(Runtime_NewScriptContext) { DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 0); - Handle<Context> native_context(isolate->context(), isolate); - DCHECK(native_context->IsNativeContext()); + Handle<NativeContext> native_context(NativeContext::cast(isolate->context()), + isolate); Handle<JSGlobalObject> global_object(native_context->global_object(), isolate); Handle<ScriptContextTable> script_context_table( @@ -722,7 +721,7 @@ RUNTIME_FUNCTION(Runtime_PushModuleContext) { CONVERT_ARG_HANDLE_CHECKED(Module, module, 0); CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); - Handle<Context> outer(isolate->context(), isolate); + Handle<NativeContext> outer(NativeContext::cast(isolate->context()), isolate); Handle<Context> context = isolate->factory()->NewModuleContext(module, outer, scope_info); isolate->set_context(*context); diff --git a/deps/v8/src/runtime/runtime-strings.cc b/deps/v8/src/runtime/runtime-strings.cc index 0c3c82deda..f6537fd073 100644 --- a/deps/v8/src/runtime/runtime-strings.cc +++ b/deps/v8/src/runtime/runtime-strings.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/conversions.h" #include "src/counters.h" #include "src/objects-inl.h" +#include "src/objects/js-array-inl.h" #include "src/regexp/jsregexp-inl.h" #include "src/regexp/regexp-utils.h" -#include "src/string-builder.h" +#include "src/runtime/runtime-utils.h" +#include "src/string-builder-inl.h" #include "src/string-search.h" namespace v8 { diff --git a/deps/v8/src/runtime/runtime-symbol.cc b/deps/v8/src/runtime/runtime-symbol.cc index 1472b4e2be..0c9ea75d5d 100644 --- a/deps/v8/src/runtime/runtime-symbol.cc +++ b/deps/v8/src/runtime/runtime-symbol.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/isolate-inl.h" #include "src/objects-inl.h" -#include "src/string-builder.h" +#include "src/runtime/runtime-utils.h" +#include "src/string-builder-inl.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/runtime/runtime-test.cc b/deps/v8/src/runtime/runtime-test.cc index 03251b67e1..94376e1364 100644 --- a/deps/v8/src/runtime/runtime-test.cc +++ b/deps/v8/src/runtime/runtime-test.cc @@ -7,8 +7,8 @@ #include <memory> #include <sstream> -#include "src/api.h" -#include "src/arguments.h" +#include "src/api-inl.h" +#include "src/arguments-inl.h" #include "src/assembler-inl.h" #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" #include "src/compiler.h" @@ -658,17 +658,6 @@ RUNTIME_FUNCTION(Runtime_SystemBreak) { } -// Sets a v8 flag. -RUNTIME_FUNCTION(Runtime_SetFlags) { - SealHandleScope shs(isolate); - DCHECK_EQ(1, args.length()); - CONVERT_ARG_CHECKED(String, arg, 0); - std::unique_ptr<char[]> flags = - arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); - FlagList::SetFlagsFromString(flags.get(), StrLength(flags.get())); - return ReadOnlyRoots(isolate).undefined_value(); -} - RUNTIME_FUNCTION(Runtime_SetForceSlowPath) { SealHandleScope shs(isolate); DCHECK_EQ(1, args.length()); @@ -847,6 +836,23 @@ RUNTIME_FUNCTION(Runtime_GetWasmRecoveredTrapCount) { return *isolate->factory()->NewNumberFromSize(trap_count); } +namespace { +bool EnableWasmThreads(v8::Local<v8::Context> context) { return true; } + +bool DisableWasmThreads(v8::Local<v8::Context> context) { return false; } +} // namespace + +// This runtime function enables WebAssembly threads through an embedder +// callback and thereby bypasses the value in FLAG_experimental_wasm_threads. +RUNTIME_FUNCTION(Runtime_SetWasmThreadsEnabled) { + DCHECK_EQ(1, args.length()); + CONVERT_BOOLEAN_ARG_CHECKED(flag, 0); + v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); + v8_isolate->SetWasmThreadsEnabledCallback(flag ? EnableWasmThreads + : DisableWasmThreads); + return ReadOnlyRoots(isolate).undefined_value(); +} + #define ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(Name) \ RUNTIME_FUNCTION(Runtime_Has##Name) { \ CONVERT_ARG_CHECKED(JSObject, obj, 0); \ @@ -866,11 +872,10 @@ ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastProperties) #undef ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION - -#define FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION(Type, type, TYPE, ctype, s) \ - RUNTIME_FUNCTION(Runtime_HasFixed##Type##Elements) { \ - CONVERT_ARG_CHECKED(JSObject, obj, 0); \ - return isolate->heap()->ToBoolean(obj->HasFixed##Type##Elements()); \ +#define FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION(Type, type, TYPE, ctype) \ + RUNTIME_FUNCTION(Runtime_HasFixed##Type##Elements) { \ + CONVERT_ARG_CHECKED(JSObject, obj, 0); \ + return isolate->heap()->ToBoolean(obj->HasFixed##Type##Elements()); \ } TYPED_ARRAYS(FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION) @@ -900,19 +905,18 @@ RUNTIME_FUNCTION(Runtime_PromiseSpeciesProtector) { // Take a compiled wasm module and serialize it into an array buffer, which is // then returned. RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { - HandleScope shs(isolate); + HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0); wasm::NativeModule* native_module = module_obj->native_module(); - size_t compiled_size = - wasm::GetSerializedNativeModuleSize(isolate, native_module); + wasm::WasmSerializer wasm_serializer(isolate, native_module); + size_t compiled_size = wasm_serializer.GetSerializedNativeModuleSize(); void* array_data = isolate->array_buffer_allocator()->Allocate(compiled_size); Handle<JSArrayBuffer> array_buffer = isolate->factory()->NewJSArrayBuffer(); JSArrayBuffer::Setup(array_buffer, isolate, false, array_data, compiled_size); if (!array_data || - !wasm::SerializeNativeModule( - isolate, native_module, + !wasm_serializer.SerializeNativeModule( {reinterpret_cast<uint8_t*>(array_data), compiled_size})) { return ReadOnlyRoots(isolate).undefined_value(); } @@ -922,31 +926,20 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { // Take an array buffer and attempt to reconstruct a compiled wasm module. // Return undefined if unsuccessful. RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) { - HandleScope shs(isolate); + HandleScope scope(isolate); DCHECK_EQ(2, args.length()); CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0); CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, wire_bytes, 1); - uint8_t* mem_start = reinterpret_cast<uint8_t*>(buffer->backing_store()); - size_t mem_size = static_cast<size_t>(buffer->byte_length()->Number()); - // Note that {wasm::DeserializeNativeModule} will allocate. We assume the - // JSArrayBuffer doesn't get relocated. - bool already_external = wire_bytes->is_external(); - if (!already_external) { - wire_bytes->set_is_external(true); - isolate->heap()->UnregisterArrayBuffer(*wire_bytes); - } + // JSArrayBuffer backing store doesn't get relocated. MaybeHandle<WasmModuleObject> maybe_module_object = wasm::DeserializeNativeModule( - isolate, {mem_start, mem_size}, - Vector<const uint8_t>( - reinterpret_cast<uint8_t*>(wire_bytes->backing_store()), - static_cast<int>(wire_bytes->byte_length()->Number()))); - if (!already_external) { - wire_bytes->set_is_external(false); - isolate->heap()->RegisterNewArrayBuffer(*wire_bytes); - } + isolate, + {reinterpret_cast<uint8_t*>(buffer->backing_store()), + static_cast<size_t>(buffer->byte_length()->Number())}, + {reinterpret_cast<uint8_t*>(wire_bytes->backing_store()), + static_cast<size_t>(wire_bytes->byte_length()->Number())}); Handle<WasmModuleObject> module_object; if (!maybe_module_object.ToHandle(&module_object)) { return ReadOnlyRoots(isolate).undefined_value(); @@ -1005,7 +998,7 @@ RUNTIME_FUNCTION(Runtime_RedirectToWasmInterpreter) { } RUNTIME_FUNCTION(Runtime_WasmTraceMemory) { - HandleScope hs(isolate); + HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_ARG_CHECKED(Smi, info_addr, 0); @@ -1025,16 +1018,29 @@ RUNTIME_FUNCTION(Runtime_WasmTraceMemory) { // TODO(titzer): eliminate dependency on WasmModule definition here. int func_start = frame->wasm_instance()->module()->functions[func_index].code.offset(); - wasm::ExecutionEngine eng = frame->wasm_code()->is_liftoff() - ? wasm::ExecutionEngine::kLiftoff - : wasm::ExecutionEngine::kTurbofan; - wasm::TraceMemoryOperation(eng, info, func_index, pos - func_start, + wasm::ExecutionTier tier = frame->wasm_code()->is_liftoff() + ? wasm::ExecutionTier::kBaseline + : wasm::ExecutionTier::kOptimized; + wasm::TraceMemoryOperation(tier, info, func_index, pos - func_start, mem_start); return ReadOnlyRoots(isolate).undefined_value(); } +RUNTIME_FUNCTION(Runtime_WasmTierUpFunction) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0); + CONVERT_SMI_ARG_CHECKED(function_index, 1); + if (!isolate->wasm_engine()->CompileFunction( + isolate, instance->module_object()->native_module(), function_index, + wasm::ExecutionTier::kOptimized)) { + return ReadOnlyRoots(isolate).exception(); + } + return ReadOnlyRoots(isolate).undefined_value(); +} + RUNTIME_FUNCTION(Runtime_IsLiftoffFunction) { - HandleScope shs(isolate); + HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); CHECK(WasmExportedFunction::IsWasmExportedFunction(*function)); diff --git a/deps/v8/src/runtime/runtime-typedarray.cc b/deps/v8/src/runtime/runtime-typedarray.cc index d68bb06e82..c101219d2c 100644 --- a/deps/v8/src/runtime/runtime-typedarray.cc +++ b/deps/v8/src/runtime/runtime-typedarray.cc @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/elements.h" #include "src/heap/factory.h" +#include "src/heap/heap-inl.h" #include "src/messages.h" #include "src/objects-inl.h" +#include "src/objects/js-array-buffer-inl.h" +#include "src/runtime/runtime-utils.h" #include "src/runtime/runtime.h" namespace v8 { @@ -123,7 +124,7 @@ RUNTIME_FUNCTION(Runtime_TypedArraySortFast) { Handle<FixedTypedArrayBase> elements( FixedTypedArrayBase::cast(array->elements()), isolate); switch (array->type()) { -#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype, size) \ +#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype) \ case kExternal##Type##Array: { \ ctype* data = static_cast<ctype*>(elements->DataPtr()); \ if (kExternal##Type##Array == kExternalFloat64Array || \ diff --git a/deps/v8/src/runtime/runtime-utils.h b/deps/v8/src/runtime/runtime-utils.h index 4a80ff5d40..e58934ba33 100644 --- a/deps/v8/src/runtime/runtime-utils.h +++ b/deps/v8/src/runtime/runtime-utils.h @@ -122,8 +122,8 @@ static inline ObjectPair MakePair(Object* x, Object* y) { } #elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT // For x32 a 128-bit struct return is done as rax and rdx from the ObjectPair -// are used in the full codegen and Crankshaft compiler. An alternative is -// using uint64_t and modifying full codegen and Crankshaft compiler. +// are used in generated code. An alternative is using uint64_t and modifying +// generated code. struct ObjectPair { Object* x; uint32_t x_upper; diff --git a/deps/v8/src/runtime/runtime-wasm.cc b/deps/v8/src/runtime/runtime-wasm.cc index 55c549a6cf..5a6c782292 100644 --- a/deps/v8/src/runtime/runtime-wasm.cc +++ b/deps/v8/src/runtime/runtime-wasm.cc @@ -2,10 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - -#include "src/arguments.h" -#include "src/assembler.h" +#include "src/arguments-inl.h" #include "src/compiler/wasm-compiler.h" #include "src/conversions.h" #include "src/debug/debug.h" @@ -13,6 +10,7 @@ #include "src/heap/factory.h" #include "src/objects-inl.h" #include "src/objects/frame-array-inl.h" +#include "src/runtime/runtime-utils.h" #include "src/trap-handler/trap-handler.h" #include "src/v8memory.h" #include "src/wasm/module-compiler.h" @@ -195,7 +193,7 @@ RUNTIME_FUNCTION(Runtime_WasmExceptionGetElement) { CONVERT_SMI_ARG_CHECKED(index, 0); CHECK_LT(index, Smi::ToInt(values->length())); auto* vals = - reinterpret_cast<uint16_t*>(values->GetBuffer()->allocation_base()); + reinterpret_cast<uint16_t*>(values->GetBuffer()->backing_store()); return Smi::FromInt(vals[index]); } } @@ -265,8 +263,13 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { frame_pointer = it.frame()->fp(); } - bool success = instance->debug_info()->RunInterpreter(frame_pointer, - func_index, arg_buffer); + // Run the function in the interpreter. Note that neither the {WasmDebugInfo} + // nor the {InterpreterHandle} have to exist, because interpretation might + // have been triggered by another Isolate sharing the same WasmEngine. + Handle<WasmDebugInfo> debug_info = + WasmInstanceObject::GetOrCreateDebugInfo(instance); + bool success = WasmDebugInfo::RunInterpreter( + isolate, debug_info, frame_pointer, func_index, arg_buffer); if (!success) { DCHECK(isolate->has_pending_exception()); diff --git a/deps/v8/src/runtime/runtime.cc b/deps/v8/src/runtime/runtime.cc index 64f487398f..ec35131c90 100644 --- a/deps/v8/src/runtime/runtime.cc +++ b/deps/v8/src/runtime/runtime.cc @@ -4,13 +4,13 @@ #include "src/runtime/runtime.h" -#include "src/assembler.h" #include "src/base/hashmap.h" #include "src/contexts.h" #include "src/handles-inl.h" #include "src/heap/heap.h" #include "src/isolate.h" #include "src/objects-inl.h" +#include "src/reloc-info.h" #include "src/runtime/runtime-utils.h" namespace v8 { diff --git a/deps/v8/src/runtime/runtime.h b/deps/v8/src/runtime/runtime.h index accb97d0e6..5a6364f644 100644 --- a/deps/v8/src/runtime/runtime.h +++ b/deps/v8/src/runtime/runtime.h @@ -79,7 +79,6 @@ namespace internal { #define FOR_EACH_INTRINSIC_CLASSES(F) \ F(DefineClass, -1 /* >= 3 */, 1) \ - F(GetSuperConstructor, 1, 1) \ F(HomeObjectSymbol, 0, 1) \ F(LoadFromSuper, 3, 1) \ F(LoadKeyedFromSuper, 3, 1) \ @@ -97,8 +96,6 @@ namespace internal { #define FOR_EACH_INTRINSIC_COLLECTIONS(F) \ F(GetWeakMapEntries, 2, 1) \ F(GetWeakSetValues, 2, 1) \ - F(IsJSWeakMap, 1, 1) \ - F(IsJSWeakSet, 1, 1) \ F(MapGrow, 1, 1) \ F(MapIteratorClone, 1, 1) \ F(MapShrink, 1, 1) \ @@ -203,33 +200,39 @@ namespace internal { #ifdef V8_INTL_SUPPORT #define FOR_EACH_INTRINSIC_INTL(F) \ F(AvailableLocalesOf, 1, 1) \ - F(BreakIteratorAdoptText, 2, 1) \ F(BreakIteratorBreakType, 1, 1) \ F(BreakIteratorCurrent, 1, 1) \ F(BreakIteratorFirst, 1, 1) \ F(BreakIteratorNext, 1, 1) \ F(CanonicalizeLanguageTag, 1, 1) \ + F(CollatorResolvedOptions, 1, 1) \ F(CreateBreakIterator, 3, 1) \ - F(CreateCollator, 3, 1) \ F(CreateDateTimeFormat, 3, 1) \ F(CreateNumberFormat, 3, 1) \ - F(CreatePluralRules, 3, 1) \ F(CurrencyDigits, 1, 1) \ F(DateCacheVersion, 0, 1) \ + F(DefaultNumberOption, 5, 1) \ + F(DefineWEProperty, 3, 1) \ + F(FormatList, 2, 1) \ + F(FormatListToParts, 2, 1) \ F(GetDefaultICULocale, 0, 1) \ - F(InternalCompare, 3, 1) \ - F(InternalDateFormat, 2, 1) \ - F(InternalNumberFormat, 2, 1) \ + F(GetNumberOption, 5, 1) \ F(IntlUnwrapReceiver, 5, 1) \ F(IsInitializedIntlObjectOfType, 2, 1) \ + F(IsWellFormedCurrencyCode, 1, 1) \ F(MarkAsInitializedIntlObjectOfType, 2, 1) \ + F(ParseExtension, 1, 1) \ + F(PluralRulesResolvedOptions, 1, 1) \ F(PluralRulesSelect, 2, 1) \ - F(StringLocaleConvertCase, 3, 1) \ + F(ToDateTimeOptions, 3, 1) \ + F(ToLocaleDateTime, 6, 1) \ F(StringToLowerCaseIntl, 1, 1) \ - F(StringToUpperCaseIntl, 1, 1) + F(StringToUpperCaseIntl, 1, 1) \ + F(SupportedLocalesOf, 3, 1) \ +// End of macro. #else #define FOR_EACH_INTRINSIC_INTL(F) -#endif +#endif // V8_INTL_SUPPORT #define FOR_EACH_INTRINSIC_INTERNAL(F) \ F(AllocateInNewSpace, 1, 1) \ @@ -277,9 +280,11 @@ namespace internal { F(Typeof, 1, 1) \ F(UnwindAndFindExceptionHandler, 0, 1) -#define FOR_EACH_INTRINSIC_LITERALS(F) \ - F(CreateArrayLiteral, 4, 1) \ - F(CreateObjectLiteral, 4, 1) \ +#define FOR_EACH_INTRINSIC_LITERALS(F) \ + F(CreateArrayLiteral, 4, 1) \ + F(CreateArrayLiteralWithoutAllocationSite, 2, 1) \ + F(CreateObjectLiteral, 4, 1) \ + F(CreateObjectLiteralWithoutAllocationSite, 2, 1) \ F(CreateRegExpLiteral, 4, 1) #define FOR_EACH_INTRINSIC_MATHS(F) F(GenerateRandomNumbers, 0, 1) @@ -295,7 +300,7 @@ namespace internal { F(IsSmi, 1, 1) \ F(IsValidSmi, 1, 1) \ F(MaxSmi, 0, 1) \ - F(NumberToStringSkipCache, 1, 1) \ + F(NumberToString, 1, 1) \ F(SmiLexicographicCompare, 2, 1) \ F(StringParseFloat, 1, 1) \ F(StringParseInt, 2, 1) \ @@ -330,7 +335,6 @@ namespace internal { F(HasProperty, 2, 1) \ F(InternalSetPrototype, 2, 1) \ F(IsJSReceiver, 1, 1) \ - F(IterableToListCanBeElided, 1, 1) \ F(KeyedGetProperty, 2, 1) \ F(NewObject, 2, 1) \ F(ObjectCreate, 2, 1) \ @@ -515,6 +519,7 @@ namespace internal { F(InNewSpace, 1, 1) \ F(IsAsmWasmCode, 1, 1) \ F(IsConcurrentRecompilationSupported, 0, 1) \ + F(WasmTierUpFunction, 2, 1) \ F(IsLiftoffFunction, 1, 1) \ F(IsWasmCode, 1, 1) \ F(IsWasmTrapHandlerEnabled, 0, 1) \ @@ -527,7 +532,6 @@ namespace internal { F(RunningInSimulator, 0, 1) \ F(SerializeWasmModule, 1, 1) \ F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \ - F(SetFlags, 1, 1) \ F(SetForceSlowPath, 1, 1) \ F(SetWasmCompileControls, 2, 1) \ F(SetWasmInstantiateControls, 0, 1) \ @@ -541,7 +545,8 @@ namespace internal { F(WasmGetNumberOfInstances, 1, 1) \ F(WasmNumInterpretedCalls, 1, 1) \ F(WasmTraceMemory, 1, 1) \ - F(WasmMemoryHasFullGuardRegion, 1, 1) + F(WasmMemoryHasFullGuardRegion, 1, 1) \ + F(SetWasmThreadsEnabled, 1, 1) #define FOR_EACH_INTRINSIC_TYPEDARRAY(F) \ F(ArrayBufferNeuter, 1, 1) \ @@ -578,6 +583,8 @@ namespace internal { F(KeyedLoadIC_Miss, 4, 1) \ F(KeyedStoreIC_Miss, 5, 1) \ F(KeyedStoreIC_Slow, 5, 1) \ + F(LoadAccessorProperty, 4, 1) \ + F(LoadCallbackProperty, 4, 1) \ F(LoadElementWithInterceptor, 2, 1) \ F(LoadGlobalIC_Miss, 3, 1) \ F(LoadGlobalIC_Slow, 3, 1) \ @@ -588,7 +595,9 @@ namespace internal { F(StoreGlobalIC_Slow, 5, 1) \ F(StoreIC_Miss, 5, 1) \ F(StoreInArrayLiteralIC_Slow, 5, 1) \ - F(StorePropertyWithInterceptor, 5, 1) + F(StorePropertyWithInterceptor, 5, 1) \ + F(CloneObjectIC_Miss, 4, 1) \ + F(CloneObjectIC_Slow, 2, 1) #define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \ FOR_EACH_INTRINSIC_ARRAY(F) \ |