0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-25 15:29:43 -05:00
Commit graph

277 commits

Author SHA1 Message Date
Bert Belder
d90742277d
Format source code and fix clippy warning (#443) 2020-08-27 20:46:25 +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
d84be8ca2a
SnapshotCreator::GetIsolate() should have been a const method (#432) 2020-08-07 18:35:51 +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
Bert Belder
da0c5f76e4
Add 'CallbackScope<()>' that doesn't assume an entered Context (#425)
Certain callbacks (e.g. `WasmLoadSourceMapCallback`) expect the
embedder to return a local handle (a `Local<String>` in this case), but
do not provide a `Local<Context>` as an argument, nor does it provide
any other argument that we might obtain a context from. This is not
unexpected - WASM execution as such is not tied to a context, and a
`Local<String>` can be created without a context too because it's a
primitive value that has no JavaScript prototype.
2020-07-19 11:02:23 +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
2b11a57d47
Refactor 'v8__internal__GetIsolateFromHeapObject' (#415)
It turns out that using `v8::internal::MaybeObject` was, although
harmless, not appropriate here, because this function does not deal
deal with (potentially) weak handles.
2020-07-08 09:41:37 +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
850af2e857
Remove 'FinalizationGroup' bindings (#410)
V8 no longer supports or even defines this type.
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
8a4dc30445
Rename to_local() to cast_local(), use a closure (#406)
This makes it possible to add a run-time check that verifies that the
specified closure is actually the one that contains the local handle.
2020-06-19 20:18:07 +02:00
Bert Belder
6db41791ca
Remove unused 'v8::Locker' constructor/destructor bindings (#407) 2020-06-17 06:15:09 +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
74d806cbe3
Make error constructors in Exception less repetitive (#394) 2020-06-01 08:57:45 +02:00
Bert Belder
e4c260b8d2
Fix typo in signature of trait method 'Shared::from_unique_ptr()' (#393) 2020-06-01 08:44:10 +02:00
Bert Belder
771acbab02
Reflow comment and fix a typo in it (#391)
Closes: #374
2020-05-31 23:05:23 +02: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
a9ea69b5d5
Add more comments explaining why Local::from_raw() is appropriate (#389) 2020-05-31 19:39:08 +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
c114c46e15
Fix incorrect function signatures in module.rs (#388)
* `usize` and `int` are not equivalent or interchangeable at any level.
* Removed an unnecessary mutable borrow.
2020-05-31 19:00:01 +02:00
Bert Belder
8213c0e428
Remove incorrect uses of Local::from_raw() (#385) 2020-05-31 13:41:42 +02:00
Bert Belder
9540732a6a
Relax some Function/PropertyCallbackArguments lifetime constraints (#385) 2020-05-31 13:41:10 +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
Ryan Dahl
11340c9ca3
There should be a single entry point for creating IsolateHandle (#361) 2020-04-23 16:46:53 -04:00
Bert Belder
db5bbf6e43
Move 'create_param_allocations' from OwnedIsolate to IsolateAnnex (#365) 2020-04-23 20:15:39 +02:00
Bert Belder
cc626550b1
Explicitly drop slots when disposing an isolate (#364) 2020-04-23 19:48:07 +02:00
Bert Belder
ce54d39929
Clarify the purpose of the mutex in struct IsolateAnnex (#363) 2020-04-23 19:22:05 +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
d3a6c1403b
Fix race condition in v8::platform::Task tests (#355) 2020-04-20 19:19:00 +02:00
Bert Belder
3d0a90c1c8
Clippy (#354) 2020-04-16 15:35:27 +02:00
Bert Belder
b85346047e
Remove the 'Delete' trait, use regular 'Drop' instead (#353) 2020-04-16 05:24:07 +02:00
Bert Belder
256b6710d0
Remove transmutes from UniquePtr/UniqueRef implementation (#352) 2020-04-16 03:21:11 +02:00