Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deps/v8shim/src/arraybuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<BackingStore> ArrayBuffer::NewBackingStore(
Expand Down Expand Up @@ -298,6 +299,13 @@ Local<SharedArrayBuffer> SharedArrayBuffer::New(
ArrayBufferFor(std::move(backing_store), true, false));
}

std::unique_ptr<BackingStore> SharedArrayBuffer::NewBackingStore(
void* data, size_t byte_length, BackingStore::DeleterCallback deleter,
void* deleter_data) {
return std::unique_ptr<BackingStore>(
NewStore(data, byte_length, true, deleter, deleter_data));
}

size_t SharedArrayBuffer::ByteLength() const {
return host::array_buffer_length(Self(this));
}
Expand Down
10 changes: 10 additions & 0 deletions deps/v8shim/src/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions deps/v8shim/src/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Local<Value> Isolate::ThrowException(Local<Value> exception) {
return Utils::ToLocal<Value>(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() {
Expand Down
4 changes: 4 additions & 0 deletions deps/v8shim/src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Maybe<bool> Object::Has(Local<Context> context, Local<Value> key) {
return ToMaybeBool(host::object_has(Self(this), Utils::Open(key)));
}

Maybe<bool> Object::Has(Local<Context> context, uint32_t index) {
return ToMaybeBool(host::object_has(Self(this), host::number_new(index)));
}

Maybe<bool> Object::Delete(Local<Context> context, Local<Value> key) {
return ToMaybeBool(host::object_delete(Self(this), Utils::Open(key)));
}
Expand Down
4 changes: 4 additions & 0 deletions deps/v8shim/src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 41 additions & 0 deletions deps/v8shim/src/values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -143,6 +146,21 @@ Maybe<double> Value::NumberValue(Local<Context> context) const {
return Just(value);
}

MaybeLocal<Number> Value::ToNumber(Local<Context> context) const {
if (Is(this, host::kIsNumber)) {
return Utils::ToLocal<Number>(Self(this));
}
Maybe<double> number = NumberValue(context);
if (number.IsNothing()) return MaybeLocal<Number>();
return Utils::ToLocal<Number>(host::number_new(number.FromJust()));
}

Maybe<bool> Value::InstanceOf(Local<Context> context, Local<Object> object) {
int32_t result = host::value_instance_of(Self(this), Utils::Open(object));
if (result < 0) return Nothing<bool>();
return Just(result != 0);
}

namespace {

// ECMAScript ToInt32 / ToUint32 from a Number.
Expand Down Expand Up @@ -259,6 +277,25 @@ uint64_t BigInt::Uint64Value(bool* lossless) const {
return value;
}

MaybeLocal<BigInt> BigInt::NewFromWords(Local<Context> context, int sign_bit,
int word_count, const uint64_t* words) {
if (word_count < 0) return MaybeLocal<BigInt>();
Address value = host::bigint_from_words(sign_bit != 0, word_count, words);
if (value == 0) return MaybeLocal<BigInt>();
return Utils::ToLocal<BigInt>(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);
Expand Down Expand Up @@ -480,4 +517,8 @@ MaybeLocal<Value> Date::New(Local<Context> context, double time) {
return Utils::ToMaybeLocal<Value>(host::date_new(time));
}

double Date::ValueOf() const { return host::date_value(Self(this)); }

void Date::CheckCast(Value* that) {}

} // namespace v8
Loading