0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-12 00:54:15 -05:00

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
This commit is contained in:
Ben Noordhuis 2020-11-15 00:07:52 +01:00 committed by GitHub
parent 0e54213cc8
commit 3fa9fb36ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View file

@ -348,7 +348,6 @@ pub struct Module(Opaque);
impl_deref! { Data for Module }
impl_try_from! { Data for Module if d => d.is_module() }
impl_eq! { for Module }
impl_hash! { for Module }
impl_partial_eq! { Data for Module use identity }
impl_partial_eq! { Module for Module use identity }

View file

@ -1,4 +1,6 @@
use std::convert::TryInto;
use std::hash::Hash;
use std::hash::Hasher;
use std::mem::MaybeUninit;
use std::ptr::null;
@ -371,3 +373,9 @@ impl Module {
.into()
}
}
impl Hash for Module {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write_i32(self.get_identity_hash());
}
}

View file

@ -4,8 +4,10 @@
extern crate lazy_static;
use std::any::type_name;
use std::collections::hash_map::DefaultHasher;
use std::convert::{Into, TryFrom, TryInto};
use std::ffi::c_void;
use std::hash::Hash;
use std::ptr::NonNull;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
@ -1989,6 +1991,7 @@ fn module_evaluation() {
assert!(module.is_source_text_module());
assert!(!module.is_synthetic_module());
assert_eq!(v8::ModuleStatus::Uninstantiated, module.get_status());
module.hash(&mut DefaultHasher::new()); // Should not crash.
let result = module
.instantiate_module(scope, compile_specifier_as_module_resolve_callback);