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

221 commits

Author SHA1 Message Date
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
Bartek Iwańczuk
bddefbc2b2 Implicitly enter Isolate in v8::error (#191) 2020-01-05 18:07:50 +01:00
Bert Belder
db1c44c9be
Fix: Global::get() now actually creates a new Local handle (#187)
Closes: #182
2020-01-05 06:08:21 +01:00
Bartek Iwańczuk
2aaa62ae41 Add v8::Boolean::new() (#184) 2020-01-05 00:08:27 +01:00
Bert Belder
bd598fe8dc
Improve generated v8::Data type hierarchy and add tests (#180) 2020-01-04 03:27:43 +01:00
Bert Belder
e0b8f2d02c
Fix some issues with v8::StartupData (#178) 2020-01-04 01:26:27 +01:00
Ry Dahl
19398816ab
SnapshotCreator changes for libdeno (#176) 2020-01-03 16:52:05 -05:00
Ry Dahl
a4f519c643
Add Value::{number_value, integer_value, uint32_value, int32_value}
#174
2020-01-03 12:17:11 -05:00
Ry Dahl
8adf85ea89
add to_uint32, to_int32, to_integer, to_detail_string, to_big_int (#173) 2020-01-03 11:14:50 -05:00
Bert Belder
64136e684e Add safe downcasts for Local<Value> with TryFrom (#166) (#166) 2020-01-03 08:41:16 -05:00
Ry Dahl
45b766c01f
happy new year (#170) 2020-01-02 13:57:00 -05:00