0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-24 15:19:31 -05:00
Commit graph

431 commits

Author SHA1 Message Date
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
Ben Noordhuis
8e9fd60e79
Fix unused import warning (#875) 2022-01-22 04:10:38 +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
Bert Belder
b6a16916ce
test: don't use --harmony-top-level-await flag (#854)
Top level await is now enabled by default and the flag no longer exists.
2021-12-12 21:25:01 -08:00
Sujay Jayakar
62d33c4d7e
Add Function::GetScript{Line,Column}Number bindings (#843) 2021-11-30 21:55:41 +01:00
Bert Belder
c4c48f30b1
v8: fix segfault during concurrent isolate creation/disposal on Windows (#829)
This patch includes a test for this issue.

The V8 patch is intentionally left simple to avoid merge conflicts in
the future. To be landed upstream, the `unwindinfo_use_count_` would
probably have to be made non-atomic and we'd have to add a cctest.

Upstream bug: https://bugs.chromium.org/p/v8/issues/detail?id=12393

Fixes: #714
2021-11-17 09:52:27 -08: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
Yusuke Tanaka
674f44449f
chore: upgrade Rust to 1.55.0 (#770) 2021-09-10 12:32:29 +02:00
Rami Sabbagh
16708359bc
feat: Implement Isolate::remove_slot (#769) 2021-09-09 00:41:50 +02: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
Ben Noordhuis
efa6c71b10
Add Signature::new() (#666)
Refs #478.
2021-04-20 12:48:20 +02:00
Ben Noordhuis
03e74c6f1b
Add new_single_threaded_default_platform() (#659)
This is a v8::Platform implementation that doesn't spawn additional
threads. Useful in combination with the --single_threaded flag.
2021-04-12 21:40:52 +02:00
Bert Belder
de9a7e2698
String::new_external_onebyte_static() should take &[u8] instead of &str (#658) 2021-04-09 19:49:55 +02:00
Ryan Dahl
d78cc3df87
Upgrade V8 to 9.1.246 (#655) 2021-04-03 09:46:38 -04:00
Ryan Dahl
d520fe85bd
Add String::new_from_one_byte (#654) 2021-04-02 16:23:05 -04:00
Ben Noordhuis
7d514ae4cb
Add ArrayBuffer::detach() and is_detachable() (#648)
Fixes #646.
2021-03-16 23:35:27 +01:00
Ben Noordhuis
25608cc000
build: upgrade Rust to 1.50.0 (#645) 2021-03-16 21:05:14 +01:00
Aaron O'Mullan
f2766ed1af
Support for external v8 strings (#641) 2021-03-07 10:21:59 -05:00
Heyang Zhou
a6d36d1193
Add more ScriptCompiler APIs (#638) 2021-03-07 08:05:50 -05:00
Heyang Zhou
be89cfc131
Add code cache API (#635) 2021-03-05 05:26:37 -05:00
Kohei Ueno
dcca57b986
chore: add tests for return values of a function (#634) 2021-02-25 10:18:06 -05:00
Bartek Iwańczuk
8551c62511
Add Module::source_offset_to_location, deprecate old APIs (#624) 2021-02-15 12:08:39 +01:00
Bartek Iwańczuk
ec54f28bfd
feat: Add ModuleRequest (#623) 2021-02-14 19:49:37 +01:00
Ryan Dahl
50a15085f7
update copyrights to 2021 (#620) 2021-02-13 07:31:18 -05:00
Ryan Dahl
753b92fd96
ICU data must be 16-bit aligned (#617) 2021-02-12 05:45:02 -05:00
Ben Noordhuis
5dc6117dd7
Fix ValueDeserializer::read_value() lifetime (#609)
The return value should have the lifetime of the context, not the
deserializer.

Fixes #607.
2021-02-10 07:27:27 +01:00
Ryan Dahl
d60489c395
Support ICU (#603)
Co-authored-by: Kunihiro Ishiguro <kunihiro@zebra.dev>
2021-02-09 09:17:02 -05:00
Ben Noordhuis
64aa11e34d
Add Isolate::set_prepare_stack_trace_callback() (#594)
Refs: https://github.com/denoland/deno/issues/7644
2021-02-08 13:11:48 +01:00
Bartek Iwańczuk
d6be279a06
Add support for import assertions (#598)
This commit adds support for import assertions.

Major changes include:
- removal of "ResolveCallback" (deprecated in V8) 
in favor of "ModuleResolveCallback"
- removal of "HostImportModuleDynamicallyCallback" (deprecated in V8)
in favor of "HostImportModuleDynamicallyWithImportAssertionsCallback"
2021-02-05 00:22:26 +01:00
Ben Noordhuis
30ad399f9b
Add V8InspectorClientImpl::generate_unique_id() (#590) 2021-01-21 10:06:34 +01:00
Ben Noordhuis
0d093a02f6
Upgrade V8 to 8.9.255.3 (#567)
This floats https://chromium-review.googlesource.com/c/v8/v8/+/2608209
because it just missed the merge window for 8.9.
2021-01-18 21:46:44 +01:00
Heyang Zhou
bcbe7e9348
Support setting OOM callback on Isolate (#585) 2021-01-16 10:30:38 +01:00
Heyang Zhou
3fd7cae994
Expose ArrayBuffer::Allocator interface (#578) 2021-01-14 23:29:06 +01:00
Ben Noordhuis
5cb14847aa
Expose v8::WriteOptions (#583)
Without it, v8::String::write_utf8() is pretty much unusable.
2021-01-13 00:49:59 +01:00
Heyang Zhou
584a037800
Add Script::get_unbound_script() and UnboundScript::bind_to_current_context() (#572) 2021-01-11 19:39:51 -08:00
Daniel Bevenius
54a72d7628
Remove set_flags_from_command_line_with_usage test (#570)
This commit removes the set_flags_from_command_line_with_usage and puts
it in an example code section instead.

The motivation for doing this is that the test output currently contains
the usage string and all the V8 options which creates a lot of output
when the tests is run regardless if --nocapture is used or not.
2021-01-07 22:42:30 +01:00
Ben Noordhuis
ea412d0554
Add Isolate::set_wasm_streaming_callback() (#560)
Add the hook necessary to implement `WebAssembly.compileStreaming()`.

Fixes #556
2020-12-31 16:06:29 +01:00
Bartek Iwańczuk
41f29a19c4
Isolate::thread_safe_handle() no longer requires mutable reference (#562) 2020-12-30 23:30:30 -08:00
Bartek Iwańczuk
cf7bb2d001
Add methods for termination to Isolate (#561)
This commit adds following methods to Isolate:
- terminate_execution
- cancel_terminate_execution
- is_execution_terminating
2020-12-25 22:45:57 +01:00
Ben Noordhuis
f37601cab2
Add FunctionBuilder (#512)
v8::Function and v8::FunctionTemplate have a lot of options that can be
configured. The builder() associated functions on those types help with
that.
2020-12-07 17:03:46 -05:00
Ben Noordhuis
530c876aff
Make Private work with context-less HandleScope (#549)
v8::Private is like v8::String and other primitives, it doesn't need an
active v8::Context.
2020-12-07 16:48:51 -05:00
Daniel Bevenius
4e8eaf94c3
Add set_flags_from_command_line_with_usage (#536)
The motivation for this is to enable embedders of rusty_v8 to
pass their own usage string and have their usage printed before V8's
options.
2020-12-07 16:46:38 -05:00
Daniel Bevenius
29396ed40a
typo (#542) 2020-12-07 15:32:09 -05:00
Ben Noordhuis
343d7f2800
Make Symbol work with context-less HandleScope (#550)
v8::Symbol is like v8::String and other primitives, it doesn't need an
active v8::Context.
2020-12-04 13:56:55 +01:00
Ben Noordhuis
c1509cac08
Make PromiseHookType Clone, Copy and PartialEq (#548) 2020-12-04 13:56:27 +01:00
Bartek Iwańczuk
2d68950e7e
build: upgrade Rust to 1.48.0 (#535) 2020-11-19 19:44:06 +01:00
Ben Noordhuis
64faf683d2
Add Value::to_rust_string_lossy() (#530)
If it's convenient to have on String objects, then it's convenient to
have on all Value instances.
2020-11-19 11:58:23 +01:00
Ben Noordhuis
3fa9fb36ed
Fix runtime assert when hashing module object (#522)
The blanket `std:#️⃣:Hash` impl for instances of `v8::Data` invokes
`v8::internal::Object::GetHash()` but that crashes for `v8::Module`
objects. Use a custom impl that calls `v8::Module::get_identity_hash()`.

Fixes the following runtime assertion:

    # Fatal error in ../../../v8/src/objects/objects-inl.h, line 1043
    # Debug check failed: object.IsJSReceiver().

Refs: https://github.com/denoland/deno/pull/8354#discussion_r522157813
2020-11-15 00:07:52 +01:00
l3ops
fb049cb934
Add Function::new_instance (#508) 2020-10-26 08:57:14 +01:00
Ben Noordhuis
b8a2e06dc8
Add Isolate::clear_kept_objects() (#507)
Refs: https://github.com/denoland/deno/issues/7674
2020-10-21 08:00:44 +02:00
Ben Noordhuis
1988c98f3c
Add Isolate::set_allow_atomics_wait() (#500) 2020-10-15 22:12:44 +02:00
Ben Noordhuis
1c38b66093
Add Object::get_private() and friends (#498) 2020-10-15 14:37:29 +02:00
Ben Noordhuis
836557e84f
Add Module::script_id() (#497) 2020-10-15 11:05:38 +02:00
Ben Noordhuis
57390ec4ee
Add Isolate::set_promise_hook() (#496) 2020-10-12 22:33:46 +02:00
Ben Noordhuis
ea0c7c9383
Fix PromiseRejectMessage::get_value() (#493)
Change its return type to `Option<Local<Value>>`. The C++ API
returns `Local<Value>` but that can be an empty handle.

Fixes #491
2020-10-09 12:58:57 +02:00
devsnek
4f924a686a
add all TypedArray constructors (#482) 2020-10-06 14:16:22 -04:00
Inteon
dbc0509f2a
add basic serializer bindings (#442) 2020-10-06 18:39:38 +02:00
devsnek
e5f56e218c
add Symbol, Private, BigInt (#466) 2020-09-29 20:20:07 -04:00
Ben Noordhuis
6b90cbe499
add Object + ObjectTemplate internal field support (#477)
The rusty_v8 API deviates slightly from the V8 C++ API because the
latter is definitely unsound when you pass in out-of-range indexes.
2020-09-29 19:04:59 -04:00
devsnek
405a5a5158
Add APIs to store/retrieve embedder data in a Context or Isolate snapshot (#449)
Co-authored-by: Bert Belder <bertbelder@gmail.com>
2020-09-10 02:39:49 +02:00
Gus Caplan
3b27748a17
Implement TryFrom<Data> for subclasses of Data (#453) 2020-09-09 02:21:58 +02:00
Bert Belder
6409d8b112
Upgrade V8 to 8.7.75 (#462) 2020-09-08 03:02:57 +02:00
Ben Noordhuis
d60e367a9b
Add V8::set_entropy_source() (#460) 2020-09-08 03:01:36 +02:00
Bert Belder
b31dbc89dc
Simplify 'Isolate::get/set_slot()' and use optimized hasher (#461) 2020-09-07 19:50:36 +02:00
Moritz Gunz
8513c8fa69
Add bindings to 'v8::Isolate::LowMemoryNotification()' (#459) 2020-09-07 13:00:35 +02:00
Ben Noordhuis
de58267948
Add V8::set_flags_from_string() (#457) 2020-09-06 15:40:07 -04:00
Bert Belder
21f6ecf483
Fix flaky tests caused by relaxed load in C++ 'shared_ptr::use_count()' (#450)
Fixes: #284
2020-09-02 17:38:39 +02:00
Ben Noordhuis
b88f9f5bbc
Add Date::new() and Date::value_of() (#452) 2020-09-01 22:28:08 -04:00
Bert Belder
e88ea4ad01
Downgrade to V8 8.6.334 again (#447)
After the upgrade some Deno tests started crashing somewhere deep inside
V8, and the cause of these crashes is unclear.

This reverts the following commits:
* 12334ffe Upgrade gn to 6f13aaac; make BUILD.gn compatible with it (#443)
* f53f10d4 Upgrade V8 to 8.7.25 (#443)
2020-08-28 17:52:05 +02:00
Ryan Dahl
f53f10d41f
Upgrade V8 to 8.7.25 (#443) 2020-08-27 23:38:54 +02:00
Bert Belder
fdc03238c4
ci: upgrade to Rust 1.46.0 (#443) 2020-08-27 23:38:53 +02:00
devsnek
6d5686cd7c
Add synthetic module support (#441) 2020-08-25 17:39:18 -04:00
Ben Noordhuis
6b2c7a56a7
Add Isolate::[gs]et_microtasks_policy() (#439)
Isolate::run_microtasks() already exists but the microtasks queue
is also flushed on script entry and exit. Some embedders want strict
control over when microtasks run, which is set by the policy.

And deprecate Isolate::run_microtasks(). The corresponding V8 API is
tagged with V8_DEPRECATE_SOON.
2020-08-23 10:25:16 -04:00
Ben Noordhuis
fd5458c959
Add Isolate::get_heap_statistics() (#440) 2020-08-23 10:16:45 -04:00
Bert Belder
954163ab07
Fix the 'heap_limits' test (#430)
After upgrading to V8 8.6.337, with a 20 MB heap limit, the
near-heap-limit callback never gets called before V8 runs out of memory.

It turns out that this test exhibits memory allocation behavior which
produces so little actual garbage that 'scavenge' type garbage
collections make memory usage go up rather than down. Because of this,
V8 runs out of memory in the middle of a garbage collection cycle, after
it has already decided that there's no need to run the near-heap-limit
callback.

The issue is fixed by making sure that some actual garbage is produced
alongside with the retained objects that will eventually fill up the
heap.
2020-08-06 04:08:14 +02:00
Marcus Weiner
b0dc42f900
Add support for setting V8 heap limits and using a near-heap-limit callback (#427) 2020-07-30 18:40:18 +02:00
Ben Sheffield
e74b6bcd0d
Add 'Object::set_accessor_with_setter' (#422) 2020-07-17 11:17:29 -04:00
Bert Belder
9684640b48
Implement the 'Hash' trait for local and global handles (#415) 2020-07-08 10:27:34 +02:00
Bert Belder
82d0287028
'External' handles can be created without entering a Context (#416) 2020-07-05 01:36:51 +02:00
Bert Belder
91c8c7d1c7
Implement 'Eq' for all subtypes of 'Value' and its handles (#414) 2020-07-04 07:11:56 +02:00
Bert Belder
d3f6e4d36c
Add 'Value::same_value_zero()' (#414) 2020-07-04 07:11:04 +02:00
Skyler Lipthay
1b84bc74f6
Add 'Value::boolean_value()' and 'Value::to_boolean()' (#412) 2020-07-03 14:42:19 +02:00
Skyler Lipthay
8ebfb027c0
Add 'Object::has(_index)' and 'Object::delete(_index)' (#412) 2020-07-03 14:41:40 +02:00
Bert Belder
b981aaceee
Add 'External::new()' and 'External::value()' (#413) 2020-07-03 14:01:42 +02:00
Bert Belder
acf6bfe0e4
Add the 'HandleScope::with_context()' scope constructor (#410) 2020-07-01 10:44:23 +02:00
Bert Belder
c13625148f
Refactor handle types 'Local' and 'Global' (#410)
* Merged all handle type implementations into one file ('handle.h').
* Made it so that `Global` handles cannot be empty.
* Renamed the `AsHandle` trait to `Handle`, and made it more generally
  useful.
* Simplified how `PartialEq` is implemented for V8 heap objects and/or
  the `Local`/`Global` handles that reference them.
2020-07-01 10:44:23 +02:00
Bert Belder
4e64cefc9c
Remove unnecessary 'DerefMut' impl from 'Local<T>' (#406)
Local handles never need to be mutable. This patch also rounds up the
last few places where we were still asking the user to pass an `&mut T`
to an API method.
2020-06-26 15:05:39 +02:00
Bert Belder
b1a4dfea8b
Remove 'context' param from (almost) all public methods (#406) 2020-06-26 03:00:06 +02:00
Bert Belder
de2cca4c7f
Integrate 'TryCatch' in the scope system (#406) 2020-06-26 01:50:32 +02:00
Bert Belder
3b6ed67f5e
Rewrite the scope system from scratch (#406) 2020-06-26 01:42:00 +02:00
Bert Belder
106a8085e2
Remove an unnecessary try_into() call (#407) 2020-06-17 06:15:08 +02:00
Bert Belder
54f6bfe8c1
Reflow comments and strings that exceed the 80-char column limit (#407) 2020-06-17 06:15:08 +02:00
Bert Belder
35e7e73ff4
Add (failing) test: escaping twice from EscapableHandleScope should panic (#401) 2020-06-05 03:57:31 +02:00
Ryan Dahl
5c5ff3a521
Add module_snapshot test (#396) 2020-06-01 17:32:20 -04:00
Max Bruce
1937d30eba
Add bindings for 'Object::get_(own)_property_names()' (#337)
Co-authored-by: Bert Belder <bertbelder@gmail.com>
2020-05-31 23:04:01 +02:00
Bert Belder
405a874c36
Fix remaining Local::from_raw() misuse, and correct some lifetimes (#388) 2020-05-31 19:00:04 +02:00
Bert Belder
af9ac3c4b9
Uncomment broken test, use #[ignore] instead (#388) 2020-05-31 18:59:51 +02:00
Bert Belder
cfbfb9524f
Add test that triggers an unsolved HandleScope bug (#385) 2020-05-31 13:42:13 +02:00
Ryan Dahl
defb39b101
Make get_data and set_data private (#384) 2020-05-29 18:42:54 -04:00
Bert Belder
56c3d9f9c0
Use correct lifetime for TryCatch::exception()/message() return value (#380)
According to v8.h, "the returned handle is valid until this TryCatch
block has been destroyed". This is incorrect, as can be demonstrated
with the test below. In practice the return value lives no longer and
no shorter than the active HandleScope at the time these methods are
called. An issue has been opened about this in the V8 bug tracker:
https://bugs.chromium.org/p/v8/issues/detail?id=10537.

```rust
fn try_catch_bad_lifetimes() {
  let _setup_guard = setup();
  let mut isolate = v8::Isolate::new(Default::default());
  let mut hs = v8::HandleScope::new(&mut isolate);
  let scope = hs.enter();
  let context = v8::Context::new(scope);
  let mut cs = v8::ContextScope::new(scope, context);
  let scope = cs.enter();
  let caught_msg_2 = {
    let mut try_catch = v8::TryCatch::new(scope);
    let try_catch = try_catch.enter();
    let caught_msg_1 = {
      let mut hs = v8::HandleScope::new(scope);
      let scope = hs.enter();

      // Throw exception #1.
      let msg_1 = v8::String::new(scope, "BOOM!").unwrap();
      let exc_1 = v8::Exception::type_error(scope, msg_1);
      scope.isolate().throw_exception(exc_1);
      // Catch exception #1.
      let caught_msg_1 = try_catch.message().unwrap();
      let caught_str_1 =
        caught_msg_1.get(scope).to_rust_string_lossy(scope);
      assert!(caught_str_1.contains("BOOM"));
      // Move `caught_msg_1` out of the HandleScope it was created in.
      // The borrow checker allows this because `caught_msg_1`'s
      // lifetime is contrained to not outlive the TryCatch, but it is
      // allowed to outlive the HandleScope that was active when the
      // exception was caught.
      caught_msg_1
    };
    // Next line crashes.
    let caught_str_1 =
      caught_msg_1.get(scope).to_rust_string_lossy(scope);
    assert!(caught_str_1.contains("BOOM"));

    // Throws exception #2.
    let msg_2 = v8::String::new(scope, "DANG!").unwrap();
    let exc_2 = v8::Exception::type_error(scope, msg_2);
    scope.isolate().throw_exception(exc_2);
    // Catch exception #2.
    let caught_msg_2 = try_catch.message().unwrap();
    let caught_str_2 =
      caught_msg_2.get(scope).to_rust_string_lossy(scope);
    assert!(caught_str_2.contains("DANG"));
    // Move `caught_msg_2` out of the extent of the TryCatch, but still
    // within the extent of its HandleScope. This is unnecessarily
    // rejected at compile time.
    caught_msg_2
  };
  let caught_str_2 =
    caught_msg_2.get(scope).to_rust_string_lossy(scope);
  assert!(caught_str_2.contains("DANG"));
}
```
2020-05-24 21:37:22 +02:00
Bert Belder
6638b05096
Fix: SnapshotCreator's internal Isolate does not get initialized (#371) 2020-05-06 19:26:23 +02:00
Bert Belder
9ad0d35718
Upgrade V8 to 8.4.300 (#368) 2020-05-06 03:48:19 +02:00
Bert Belder
cc626550b1
Explicitly drop slots when disposing an isolate (#364) 2020-04-23 19:48:07 +02:00
Bartek Iwańczuk
3aa1c961dc
upgrade: rust 1.43.0 (#362) 2020-04-23 19:21:22 +02:00
Bert Belder
0d636de447
Add safe alternative to get_data/set_data (#360) 2020-04-23 03:34:28 -04:00
Bert Belder
05782b846f
Make Isolate take ownership of CreateParams (#357) 2020-04-20 21:18:03 +02:00
Bert Belder
fc582316db
Refactor C++ shared pointer wrappers (#355)
* Add `SharedPtr` as a nullable sibling to `SharedRef`.
* Add `Borrow`, `AsRef` and `AsMut` implementations as appropriate.
* `SharedRef<T>` now derefs to `T` rather than to `UnsafeCell<T>`.
* `array_buffer::BackingStore` now derefs to `[Cell<u8>]`.
2020-04-20 19:38:08 +02:00
Bert Belder
256b6710d0
Remove transmutes from UniquePtr/UniqueRef implementation (#352) 2020-04-16 03:21:11 +02:00
Bert Belder
d1ac68f0c8
Always use raw pointers to send V8 handles between C++ and Rust (#349)
And other pointer usage touch-ups on the C++ side:
- const parameters are passed by & reference.
- mutable parameters are passed by * pointer.
2020-04-14 00:34:32 +02:00
Bert Belder
675d585977
Add binding for v8__internal__GetIsolateFromHeapObject() (#348) 2020-04-13 02:18:05 +02:00
FrankBlue
5a5bad9adf
add Map::size and Map::as_array (#333) 2020-04-02 13:37:13 -04:00
Michał Sabiniarz
bb0be74b0b
add v8::Proxy (#330) 2020-04-01 17:47:19 -04:00
Max Bruce
6bf57abb5c
Implement GetPrototype and SetPrototype on objects (#321) 2020-03-23 11:39:43 -04:00
Kevin (Kun) "Kassimo" Qian
747f513cba
Add v8::Function::new_with_data to attach associated data (#310) 2020-03-14 22:42:18 -04:00
Bert Belder
8a3c19ece4
Upgrade V8 to 8.2.308 (#306) 2020-03-13 22:05:16 -07:00
Ben Noordhuis
0df04f2129
Add Isolate::take_heap_snapshot() (#302)
This doesn't really follow the current V8 API (it's pretty close to how
V8 used to be back in 2012 though.) However:

1. The C++ API is very C++-y and doesn't carry over well to Rust, and
2. It addresses the immediate need of being able to take heap snapshots.

Refs #298
2020-03-09 10:30:25 -07:00
Bert Belder
e1b59ec736
Implement 'Eq' and 'PartialEq' traits for local handles (#301) 2020-03-05 19:37:58 -08:00
Ryan Dahl
816b6ad537
Fix BackingStore segfault (#294) 2020-02-28 18:40:48 -05:00
Bert Belder
3803e07065
Revert "Add HandleScope::new2 hack to construct from const ref (#290)"
It's not pretty, and we currently don't need it in Deno.

This reverts commit 4f0662ed57.
2020-02-25 17:22:05 -08:00
Bert Belder
eba98e7a5e
Revert "Add ability to attach arbitrary state to Isolate (#282)"
This patch introduces a bug that breaks Deno.

This reverts commit 457f7ae779.
2020-02-25 17:21:55 -08:00
Ryan Dahl
4f0662ed57
Add HandleScope::new2 hack to construct from const ref (#290) 2020-02-20 03:14:19 -05:00
Ryan Dahl
d3bbd05634
Add new terminate_execution test (#288) 2020-02-19 22:55:44 -05:00
Ryan Dahl
457f7ae779
Add ability to attach arbitrary state to Isolate (#282) 2020-02-18 23:46:00 -05:00
Ben Noordhuis
5d0b9fd760
Add some Array methods (#283) 2020-02-14 09:42:54 -05:00
Ryan Dahl
554f06f6bc
Fix get_slot and set_slot (#281) 2020-02-13 15:03:25 -05:00
Bert Belder
ddc8062644
Move get_*_context() methods to scope::Entered, remove InContext trait (#279)
The `get_current_context()` and `get_entered_or_microtask_context()`
methods now return `Option<Local<Context>>` to reflect that an isolate
may not have entered any context.

They're also moved from `Isolate` to `struct Entered` because it turns
out that the underlying V8 API calls actually create new local handles,
hence they should only be used inside an active HandleScope.

The `InContext` trait has been removed.

A test exercising `ContextScope` and the `get_*_context()` methods
mentioned above was added.

Closes: #248.
2020-02-12 22:00:31 -08:00
Bert Belder
432edd9f24
Split compile_fail tests to have only one error in each test (#277) 2020-02-12 15:21:02 -08:00
Ryan Dahl
47aafbc62e
Add compile_fail test for boxed Local (#275) 2020-02-12 14:45:14 -08:00
Ryan Dahl
27277ad801
Add IsolateHandle (#274)
Co-authored-by: Bert Belder <bertbelder@gmail.com>
2020-02-12 11:33:58 -05:00
Ryan Dahl
32abe84dc6
Remove v8::Locker (#272)
This patch clarifies that v8::Isolate is a single threaded creature,
which can only be accessed from other threads in special circumstances.
To ensure optimal operation in Deno, we remove v8::Locker, which ought
to be unnecessary when a thread is dedicated to each Isolate and the
Isolates never move between threads.

There are valid use-cases for v8::Locker, and we hope to address them in
future versions of rusty_v8.

Co-authored-by: Bert Belder <bertbelder@gmail.com>
2020-02-11 17:01:27 -05:00
Ryan Dahl
4f449b6ec6
Upgrade V8 to 8.1.310 (#263)
Co-authored-by: Bert Belder <bertbelder@gmail.com>
2020-01-30 20:44:28 -05:00
Ryan Dahl
87fdcdc131
dedup inspector client/channel test implementations (#262) 2020-01-29 13:11:22 -05:00
Ryan Dahl
62a52e0241
Do not use std::os::raw::c_int in public API (#259) 2020-01-28 17:16:31 -05:00
Ryan Dahl
2e61735f44
add test for schedule_pause_on_next_statement (#258) 2020-01-28 16:33:34 -05:00
Ben Noordhuis
9e14f18347 Add Object::creation_context() (#255)
And also Array::creation_context(), Function::creation_context(), etc.,
because they inherit from Object.
2020-01-26 17:42:28 +01:00
Ben Noordhuis
683aa2b2a9 Add V8InspectorClientImpl::console_api_message() (#252)
This makes it possible to intercept console.log() messages through
the V8 inspector API.
2020-01-24 09:33:54 -05:00
Ryan Dahl
093e09217c SharedArrayBuffer::new_backing_store_from_boxed_slice doesn't need to be unsafe 2020-01-23 14:24:03 -05:00
Ryan Dahl
aca89c2055
new_backing_store_from_boxed_slice doesn't need to be unsafe (#247) 2020-01-23 10:17:23 -05:00
Bert Belder
2286052468
Rename String::new_empty() to String::empty() (#244)
This is more consistent with the C++ API.
2020-01-22 23:21:56 +01:00
Bert Belder
8617f77fd3
Refactor v8::Object bindings (#243)
* Rename `Object::new2()` to `Object::with_prototype_and_properties()`.
* Make `Object::with_prototype_and_properties()` take a slice of keys
  and a slice of values as arguments, instead of using
  `Vec<v8::Local<v8::Name>>` and `Vec<v8::Local<v8::Value>>>`.
* Remove type `MaybeBool` from the public interface. These methods now
  return `Option<bool>` instead.
* Fix parameter type mismatches between Rust and C++ APIs.
2020-01-22 23:13:58 +01:00
Bert Belder
dcb94533f8
Make SharedRef<T> deref to UnsafeCell<T> instead of T (#242)
Closes: #240
2020-01-22 22:29:03 +01:00
Bert Belder
bf128554fc
Implement Clone for SharedRef<T> (#241) 2020-01-22 22:02:44 +01:00
Ben Noordhuis
ab3a086132 Add String::new_empty() (#238) 2020-01-22 17:23:42 +01:00
Bert Belder
1a1bac3883
Make BackingStore APIs more consistent with C++ (#234) 2020-01-21 16:23:47 +01:00
Bert Belder
b3d93dad78
Some clean-ups after making Locker a Scope (#231) 2020-01-21 03:16:55 +01:00
Bert Belder
44d58f8f48
Make Locker also a Scope (#229) 2020-01-21 02:03:45 +01:00
Bert Belder
937704ab76
Disable test 'handle_scope_escape_to_nowhere' on Windows CI (#227) 2020-01-20 23:34:34 +01:00
Bert Belder
36a12142f2
Make EscapableHandleScope::escape() inheritable, tighten lifetimes (#227) 2020-01-20 23:34:28 +01:00
Ben Noordhuis
6efb395fdc Add Object::define_own_property() (#228)
This commit introduces the NONE, READ_ONLY, DONT_ENUM and DONT_DELETE
property attributes.
2020-01-20 11:16:24 -05:00
Ben Noordhuis
42af31ff38
Add Context::new_from_template() (#225) 2020-01-19 21:58:44 +01:00
Ben Noordhuis
2db5e10b9f
Add FunctionTemplate::set_class_name() (#225) 2020-01-19 21:58:35 +01:00
Ben Noordhuis
7b0269b447
Add ObjectTemplate and Template::set() (#225)
The ObjectTemplate type already existed but now it can also be
instantiated.

This commit also adds Template::set() to actually make that useful.
2020-01-19 21:58:20 +01:00
Bert Belder
6c1d65252a
Add ContextScope and lay foundations for scope inheritance (#223) 2020-01-18 13:41:28 +01:00
Bert Belder
00d8eb8e16
Fix methods that should require '&mut Isolate' but didn't (#222) 2020-01-17 15:40:29 +01:00
Ry Dahl
7a198e0c7e
Reduce nested symbols in API (#220)
- Don't expose empty mod array_buffer_view
- Move v8::platform::new_default_platform() to v8::new_default_platform()
- Move v8::platform::Task to v8::Task
- Move v8::platform::Platform to v8::Platform
2020-01-17 09:26:42 -05:00
Bartek Iwańczuk
bc927c7477 ArrayBuffer::new_backing_store_from_boxed_slice (#202) 2020-01-17 14:41:12 +01:00
Bert Belder
8741681256
Remove unnecessary explicit drop() calls from tests (#218) 2020-01-17 09:04:30 +01:00
Bert Belder
6925e78819
Do not export Isolate::enter() and Isolate::exit() methods (#217) 2020-01-17 08:57:27 +01:00
Bert Belder
fb19eecc31
Rename new_null() to null() and new_undefined() to undefined() (#216)
This is more consistent with V8's C++ API.
2020-01-17 08:34:48 +01:00
Bert Belder
d4cd5d2733
Move error constructors and helper functions under v8::Exception (#215)
* The purpose of this change is to match the C++ API more closely.
* This patch also increases consistency between the 'extern "C"'
  function definitions on the Rust side with those on the C++ side.
* The 'message' parameter (a v8::String) to the various error
  constructors no longer needs to be mutable.
2020-01-17 08:22:16 +01:00
Bert Belder
7862af65e0
Make Function::call() more efficient and more idiomatic (#213) 2020-01-17 03:59:42 +01:00
Bert Belder
b09df9b552
Fix bug in v8::create_message() argument lifetimes (#212) 2020-01-17 02:24:41 +01:00
Bartek Iwańczuk
f650abe44e stub out inspector APIs (#206) 2020-01-16 18:12:25 -05:00
Bert Belder
a230735902
Refactor scopes and callbacks so users don't need to transmute (#183) 2020-01-16 22:48:27 +01:00
Ry Dahl
03cab59c5c
Add Isolate::request_interrupt (#208) 2020-01-15 15:33:47 -05:00
Bert Belder
e6fb4d1a65
Reimplement Module::ResolveCallback ABI fix without global variables (#207) 2020-01-14 21:15:06 +01:00
Bert Belder
bf28a6b2e3
Remove rust-abi wrapper for v8::ResolveCallback (#204)
It will be back, but in a different form.
2020-01-13 06:58:26 +01:00
Bert Belder
ff423d85bd
Format test_api.rs: use 'v8::' prefix consistently (#203) 2020-01-13 05:46:04 +01:00
Bert Belder
fe2a158fad
Format test_api.rs: break up overlong JS source string (#203) 2020-01-13 05:45:21 +01:00