0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-28 16:21:04 -05:00
Commit graph

276 commits

Author SHA1 Message Date
Andreu Botella
1ed35fd22e
feat: Weak handles and finalizers (#895)
This change adds support for weak handles that don't prevent GC of the
referenced objects, through the `v8::Weak<T>` API. A weak handle can
be empty (if it was created empty or its object was GC'd) or
non-empty, and if non-empty it allows getting its object as a global
or local.

When creating a `v8::Weak` you can also set a finalizer that will be
called at some point after the object is GC'd, as long as the weak
handle is still alive at that point. This finalization corresponds to
the second-pass callback in `kParameter` mode in the C++ API, so it
will only be called after the object is GC'd. The finalizer function
is a `FnOnce` that may close over data, and which takes a
`&mut Isolate` as an argument.

The C++ finalization API doesn't guarantee _when_ or even _if_ the
finalizer will ever be called, but in order to prevent memory leaks,
the rusty_v8 wrapper ensures that it will be called at some point,
even if it's just before the isolate gets dropped.

`v8::Weak<T>` implements `Clone`, but a finalizer is tied to a single
weak handle, so its clones won't be able to keep the finalizer alive.
And in fact, cloning will create a new weak handle that isn't tied to
a finalizer at all. `v8::Weak::clone_with_finalizer` can be used to
make a clone of a weak handle which has a finalizer tied to it.

Note that `v8::Weak<T>` doesn't implement `Hash`, because the hash
would have to change once the handle's object is GC'd, which is a big
gotcha and would break some of the algorithms that rely on hashes,
such as the Rust std's `HashMap`.
2022-05-09 12:20:55 +02:00
Luca Casonato
2dcced58d1
feat: add WasmModuleObject::compile bindings (#960)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-05-07 18:02:39 +02:00
legendecas
196145abf1
feat: add binding for Context::SetPromiseHooks (#938) 2022-05-05 18:31:29 +02:00
Aaron O'Mullan
7772779210
feat: v8::ArrayBuffer::new_backing_store_from_vec (#946)
So we can avoid `.into_boxed_slice()` calls which may require a (costly) memmove when instantiating from a Vec
2022-04-20 19:36:10 +02:00
DjDeveloper
aa9f78e09c
feat: ArrayBuffer::new_backing_store_from_ptr (#926) 2022-04-05 15:55:25 +02:00
Bert Belder
48cc6cb791
Sync V8 heap object type hierarchy with C++ (#929) 2022-03-25 03:15:30 +01:00
Aaron O'Mullan
aaacaa292f
feat: raw APIs to build v8::Functions from ptrs (#917)
Unblocks https://github.com/denoland/deno/pull/13861

The MapFnTo trait is quite contrived and can't be turned into a trait object thus blocking declarative ops
2022-03-10 23:04:48 +01:00
Ryan Dahl
184467a9cc
Upgrade to ICU 70 (#919) 2022-03-10 09:27:22 -08:00
github-actions[bot]
b91d363d2f
Rolling to V8 10.0.139.6 (#915)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-03-09 14:41:46 +01:00
Divy Srivastava
6b0dcdb440
chore: upgrade Rust to 1.59.0 (#909) 2022-03-02 17:30:58 +05:30
Divy Srivastava
90f2f79c42
Add ObjectTemplate::set_accessor_property (#908) 2022-03-02 15:40:54 +05:30
Romain Marcadier
2404d208f5
feat: add bindings for String::kMaxLength and TypedArray::kMaxLength (#904) 2022-02-22 21:23:28 -08:00
Divy Srivastava
fe447c88df
feat: support adding raw pointers to ExternalReferences (#901) 2022-02-18 16:08:54 -08:00
Bartek Iwańczuk
da7ef32ead
feat: v8::Global::from_raw, v8::Global::into_raw (#902)
Co-authored-by: Bert Belder <bertbelder@gmail.com>
2022-02-18 01:26:00 +01:00
Divy Srivastava
41003d097d
Add v8::FunctionCallbackInfo::NewTarget bindings (#898) 2022-02-11 20:51:13 +05:30
Divy Srivastava
378631e793
Add v8::Object::HasOwnProperty bindings (#897) 2022-02-11 10:04:14 +05:30
Divy Srivastava
0f34359fb4
Add v8::Value::InstanceOf bindings (#879) 2022-02-11 08:27:56 +05:30
Romain Marcadier
db7229ef14
Add bindings for v8::ScriptCompiler::CreateCodeCacheForFunction (#888) 2022-02-04 06:29:53 -08:00
github-actions[bot]
b12987ac81
Rolling to V8 9.9.115.5 (#887)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-02-02 00:51:14 +01:00
Romain Marcadier
a09d392711
Make v8::script_compiler::Source.get_cached_data return Option (#885)
The `cached_data` property of `Source` is optional, so reading the value
should return `Option<&CachedData>`.
2022-02-01 01:15:49 +01:00
Romain Marcadier
729c5b323f
Add support for v8::Object.set_integrity_level (#874)
This allows making objects frozen or sealed from rust code. This is
useful to control mutations that are allowed to happen in JS on the
given object.
2022-01-24 11:09:05 +01:00
Romain Marcadier
2180716923
Add v8::Map bindings (#872)
Support v8::Map operations (`new`, `clear`, `get`, `set`, `has`,
and `delete`).
2022-01-19 19:01:55 +01:00
Divy Srivastava
a29740df6b
Add aarch64-linux-android support (#860) 2022-01-04 21:32:48 +01:00
Aaron O'Mullan
b3e09e69a0
feat: v8::StackTrace::CurrentStackTrace() bindings (#800) 2021-12-28 16:52:12 +01:00
Bert Belder
65e78fd960
chore: upgrade Rust to 1.57.0 (#856) 2021-12-14 21:25:10 -08:00
Andreu Botella
06648dd1bd
fix: segfault when dropping BackingStore constructed from empty slice (#851)
This fixes in a segmentation fault when dropping a `BackingStore`
constructed through `ArrayBuffer::new_backing_store_from_boxed_slice()`
from an empty slice, since zero length boxed slices are invalid
(dangling) pointers, while Rust expects a `Box<c_void>` to always be a
valid pointer.

Fixes: #849
2021-12-13 15:37:59 -08:00
Sujay Jayakar
62d33c4d7e
Add Function::GetScript{Line,Column}Number bindings (#843) 2021-11-30 21:55:41 +01:00
Andreu Botella
aac37a6d4f
refactor: Have BackingStore::data return Option<NonNull<c_void>> (#817)
The pointer returned by `BackingStore::data` might be null if the
backing store has zero length, but the return type `*mut c_void` does
not force the user to consider this case. This change makes the return
type `Option<NonNull<c_void>>`, which is semantically equivalent, but
which forces users of the API to handle the `None` case.

This is a breaking API change.
2021-11-17 12:14:03 +01:00
Rafael Ávila de Espíndola
a043407ae8
Make lifetime in FunctionCallback signature more restrictive (#822)
This makes the callbacks themselves less restrictive. A test is added
the would fail to compile before.
2021-11-08 12:51:53 -08:00
Luca Casonato
5ee0a375f2
chore: rename rusty_v8 to v8 (#803) 2021-10-27 14:32:12 +02:00
Andreu Botella
2a21f5abf9
fix: Make derefing a zero-size BackingStore no longer UB (#809)
For zero-size `BackingStore`s, it seems like `BackingStore::data` always
returns a null pointer. The `Deref` impl for `BackingStore` called
`std::slice::from_raw_parts` on that pointer, even though it is UB to
call that function on a null pointer even for empty slices. This change
fixes that by obtaining a valid pointer from `NonNull::dangling()` if
the original is null.

Reported in
https://github.com/denoland/rusty_v8/issues/711#issuecomment-950637136.
2021-10-25 22:40:14 +02:00
Bert Belder
d478c450dd
Rename Handle::get() to Handle::open() instead (#806)
This also adds a deprecated `Global::get()` method to avoid unnecessarily
breaking a lot of users code.

Ref: #799
2021-10-13 21:45:10 +02:00
Rafael Ávila de Espíndola
8285b3da34
Rename Handle::get() to Handle::inner() (#799) 2021-10-13 16:47:34 +02:00
Aaron O'Mullan
6ccf15c69d
feat: Function::get/set_name() (#792)
Add bindings for v8::Function::GetName() and v8::Function::SetName()
2021-10-01 22:38:05 +02:00
Andreu Botella
b32d0b0540
feat: WasmStreaming::set_url, CompiledWasmModule::source_url (#786)
Needed for denoland/deno#12151
2021-09-22 14:34:39 -04:00
Ben Noordhuis
09347d32c8
Throw DataCloneError if SAB cannot be cloned (#781)
Best case, it produces serialized output that cannot be deserialized.

Worst case, it hits this assert in V8:

    # Fatal error in v8::FromJust
    # Maybe value is Nothing.
2021-09-18 15:21:04 +02:00
Andreu Botella
babe41a990
feat: Add v8::CompiledWasmModule (#776)
`v8::CompiledWasmModule` is a representation of a compiled WebAssembly
module, which can be shared by multiple `v8::WasmModuleObject`s.

Closes #759.
2021-09-17 12:02:40 -04:00
Ben Noordhuis
cb07d4f914
feat: implement counter_lookup_callback (#756) 2021-08-19 14:05:48 +02:00
Bartek Iwańczuk
c525555e42
feat: add V8InspectorSession::can_dispatch_method (#746) 2021-08-09 15:53:30 +02:00
Ben Noordhuis
24bef1e54b
chore: test String object serialization (#747)
Serializing `new String("")` requires that the wire format header is
written, otherwise V8 assumes an incompatible legacy wire format when
deserializing.
2021-08-07 23:33:53 +02:00
Ben Noordhuis
b56902c306
fix: remove race in terminate_execution test (#736)
The test started a new thread that slept for a bit, then terminated the
isolate, assuming that the delay was long enough for the isolate and the
context to get fully initialized. It wasn't.

Fixes #710.
2021-07-11 22:32:34 +02:00
Bartek Iwańczuk
45006fb7e7
Add Isolate::has_pending_background_tasks (#724) 2021-07-02 20:17:48 +02:00
Tim Ramlot
14bcf04bef
Add support for Platform::pump_message_loop and Platform::run_idle_tasks (#706)
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
2021-07-01 16:05:07 +02:00
Jomer
89c8ae8af3
feat: add various FunctionTemplate methods (#718)
This commit adds the following methods:
* `FunctionTemplate::inherit()`
* `FunctionTemplate::prototype_template()`
* `FunctionTemplate::read_only_prototype()`
* `FunctionTemplate::remove_prototype()`
2021-06-30 16:55:14 +02:00
Luca Casonato
cfa5d7060f
fix: pass serializer helpers as mut refs (#712)
They are only useful in read_host_object and write_host_object if
the helpers are available as a mut ref.
2021-06-24 15:59:03 +02:00
Andreu Botella
dfd5842913
Add missing methods for one- and two-byte strings (#704)
Fixes #703.
2021-06-22 14:11:38 +02:00
Yusuke Tanaka
f85508868e
chore: upgrade Rust to 1.53.0 (#705) 2021-06-18 11:35:53 -04:00
Ryan Dahl
fca78fb0c1
Rename set_common_data to set_common_data_69 (#702) 2021-06-18 06:55:38 -04:00
Matthew McAllister
6d25d19b4c
Add ObjectTemplate::set_accessor{_with_setter} (#687) 2021-05-11 16:40:53 +02:00
Ben Noordhuis
92ea90bdbf
Add ScriptCompiler::compile_function_in_context() (#670) 2021-04-27 20:32:40 +02:00