diff --git a/deps/v8shim/src/arraybuffer.cc b/deps/v8shim/src/arraybuffer.cc index cefd23a7db9f..6b55caf82d17 100644 --- a/deps/v8shim/src/arraybuffer.cc +++ b/deps/v8shim/src/arraybuffer.cc @@ -197,6 +197,7 @@ ArrayBuffer::Allocator* ArrayBuffer::Allocator::NewDefaultAllocator() { void ArrayBuffer::CheckCast(Value* that) {} void ArrayBufferView::CheckCast(Value* that) {} void SharedArrayBuffer::CheckCast(Value* that) {} +void TypedArray::CheckCast(Value* that) {} void PrimitiveArray::CheckCast(Data* that) {} std::unique_ptr ArrayBuffer::NewBackingStore( @@ -298,6 +299,13 @@ Local SharedArrayBuffer::New( ArrayBufferFor(std::move(backing_store), true, false)); } +std::unique_ptr SharedArrayBuffer::NewBackingStore( + void* data, size_t byte_length, BackingStore::DeleterCallback deleter, + void* deleter_data) { + return std::unique_ptr( + NewStore(data, byte_length, true, deleter, deleter_data)); +} + size_t SharedArrayBuffer::ByteLength() const { return host::array_buffer_length(Self(this)); } diff --git a/deps/v8shim/src/host.h b/deps/v8shim/src/host.h index 4db1f4f098b6..c102c2861840 100644 --- a/deps/v8shim/src/host.h +++ b/deps/v8shim/src/host.h @@ -157,6 +157,16 @@ V8SHIM_IMPORT(bigint_value) int64_t bigint_value(Address value, int32_t is_unsig V8SHIM_IMPORT(identity_hash) int32_t identity_hash(Address value); // new Date(time). V8SHIM_IMPORT(date_new) Address date_new(double time); +// The time value of a Date ([[DateValue]], not its valueOf). +V8SHIM_IMPORT(date_value) double date_value(Address date); +// value instanceof constructor: 1 or 0; -1 if it threw. +V8SHIM_IMPORT(value_instance_of) int32_t value_instance_of(Address value, Address constructor); +// The magnitude of a BigInt as 64-bit words, least significant first: how many there are. +V8SHIM_IMPORT(bigint_word_count) int32_t bigint_word_count(Address value); +// Writes the sign (1 if negative) and up to `capacity` words; returns how many the value has. +V8SHIM_IMPORT(bigint_to_words) int32_t bigint_to_words(Address value, int32_t* sign_bit, int32_t capacity, uint64_t* words); +// A BigInt from a sign and words; 0 if it threw (too large). +V8SHIM_IMPORT(bigint_from_words) Address bigint_from_words(int32_t sign_bit, int32_t count, const uint64_t* words); // The host engine's heap, in bytes: 0 used, 1 total, 2 limit. V8SHIM_IMPORT(heap_size) double heap_size(int32_t which); diff --git a/deps/v8shim/src/isolate.cc b/deps/v8shim/src/isolate.cc index 9b55d574dd97..51e26a1ab075 100644 --- a/deps/v8shim/src/isolate.cc +++ b/deps/v8shim/src/isolate.cc @@ -127,6 +127,12 @@ Local Isolate::ThrowException(Local exception) { return Utils::ToLocal(shim::Undefined()); } +int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes) { + int64_t& amount = shim::StateOf(this).external_memory; + amount += change_in_bytes; + return amount; +} + void Isolate::TerminateExecution() { shim::StateOf(this).terminating = true; } bool Isolate::IsExecutionTerminating() { diff --git a/deps/v8shim/src/objects.cc b/deps/v8shim/src/objects.cc index 4bde6694e98a..9d9249bab429 100644 --- a/deps/v8shim/src/objects.cc +++ b/deps/v8shim/src/objects.cc @@ -88,6 +88,10 @@ Maybe Object::Has(Local context, Local key) { return ToMaybeBool(host::object_has(Self(this), Utils::Open(key))); } +Maybe Object::Has(Local context, uint32_t index) { + return ToMaybeBool(host::object_has(Self(this), host::number_new(index))); +} + Maybe Object::Delete(Local context, Local key) { return ToMaybeBool(host::object_delete(Self(this), Utils::Open(key))); } diff --git a/deps/v8shim/src/state.h b/deps/v8shim/src/state.h index 843d5fea7495..3cea221d948a 100644 --- a/deps/v8shim/src/state.h +++ b/deps/v8shim/src/state.h @@ -57,6 +57,10 @@ struct State { // The innermost open TryCatch; each links to the one around it. TryCatch* try_catch_top = nullptr; + + // What the embedder said it holds outside the heap + // (AdjustAmountOfExternalAllocatedMemory). The host engine collects on its own, so this is only reported back. + int64_t external_memory = 0; }; // The state of the current thread's isolate. diff --git a/deps/v8shim/src/values.cc b/deps/v8shim/src/values.cc index 9a511453990b..885469c4210c 100644 --- a/deps/v8shim/src/values.cc +++ b/deps/v8shim/src/values.cc @@ -36,6 +36,9 @@ bool Value::FullIsNull() const { return Self(this) == shim::Null(); } bool Value::FullIsTrue() const { return Self(this) == shim::True(); } bool Value::FullIsFalse() const { return Self(this) == shim::False(); } bool Value::FullIsString() const { return Is(this, host::kIsString); } +bool Value::IsName() const { + return Is(this, host::kIsString) || Is(this, host::kIsSymbol); +} #define V8SHIM_VALUE_IS(Name, kind) \ bool Value::Is##Name() const { return Is(this, host::kind); } @@ -143,6 +146,21 @@ Maybe Value::NumberValue(Local context) const { return Just(value); } +MaybeLocal Value::ToNumber(Local context) const { + if (Is(this, host::kIsNumber)) { + return Utils::ToLocal(Self(this)); + } + Maybe number = NumberValue(context); + if (number.IsNothing()) return MaybeLocal(); + return Utils::ToLocal(host::number_new(number.FromJust())); +} + +Maybe Value::InstanceOf(Local context, Local object) { + int32_t result = host::value_instance_of(Self(this), Utils::Open(object)); + if (result < 0) return Nothing(); + return Just(result != 0); +} + namespace { // ECMAScript ToInt32 / ToUint32 from a Number. @@ -259,6 +277,25 @@ uint64_t BigInt::Uint64Value(bool* lossless) const { return value; } +MaybeLocal BigInt::NewFromWords(Local context, int sign_bit, + int word_count, const uint64_t* words) { + if (word_count < 0) return MaybeLocal(); + Address value = host::bigint_from_words(sign_bit != 0, word_count, words); + if (value == 0) return MaybeLocal(); + return Utils::ToLocal(value); +} + +int BigInt::WordCount() const { return host::bigint_word_count(Self(this)); } + +void BigInt::ToWordsArray(int* sign_bit, int* word_count, + uint64_t* words) const { + // V8 writes at most *word_count words and then reports how many the value has. + int32_t sign = 0; + int32_t capacity = *word_count < 0 ? 0 : *word_count; + *word_count = host::bigint_to_words(Self(this), &sign, capacity, words); + *sign_bit = sign; +} + int64_t BigInt::Int64Value(bool* lossless) const { int32_t exact = 0; int64_t value = host::bigint_value(Self(this), 0, &exact); @@ -480,4 +517,8 @@ MaybeLocal Date::New(Local context, double time) { return Utils::ToMaybeLocal(host::date_new(time)); } +double Date::ValueOf() const { return host::date_value(Self(this)); } + +void Date::CheckCast(Value* that) {} + } // namespace v8