mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-28 16:21:04 -05:00
Sync V8 heap object type hierarchy with C++ (#929)
This commit is contained in:
parent
25dd770570
commit
48cc6cb791
7 changed files with 312 additions and 169 deletions
|
@ -10,6 +10,8 @@
|
|||
#include "v8/include/v8-platform.h"
|
||||
#include "v8/include/v8-profiler.h"
|
||||
#include "v8/include/v8.h"
|
||||
#include "v8/src/api/api-inl.h"
|
||||
#include "v8/src/api/api.h"
|
||||
#include "v8/src/execution/isolate-utils-inl.h"
|
||||
#include "v8/src/execution/isolate-utils.h"
|
||||
#include "v8/src/flags/flags.h"
|
||||
|
@ -436,25 +438,63 @@ uint32_t v8__ScriptCompiler__CachedDataVersionTag() {
|
|||
return v8::ScriptCompiler::CachedDataVersionTag();
|
||||
}
|
||||
|
||||
size_t v8__TypedArray__kMaxLength() { return v8::TypedArray::kMaxLength; }
|
||||
|
||||
bool v8__Data__EQ(const v8::Data& self, const v8::Data& other) {
|
||||
return ptr_to_local(&self) == ptr_to_local(&other);
|
||||
}
|
||||
|
||||
bool v8__Data__IsValue(const v8::Data& self) { return self.IsValue(); }
|
||||
bool v8__Data__IsBigInt(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsBigInt();
|
||||
}
|
||||
|
||||
bool v8__Data__IsModule(const v8::Data& self) { return self.IsModule(); }
|
||||
bool v8__Data__IsBoolean(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsBoolean();
|
||||
}
|
||||
|
||||
bool v8__Data__IsPrivate(const v8::Data& self) { return self.IsPrivate(); }
|
||||
bool v8__Data__IsContext(const v8::Data& self) { return self.IsContext(); }
|
||||
|
||||
bool v8__Data__IsObjectTemplate(const v8::Data& self) {
|
||||
return self.IsObjectTemplate();
|
||||
bool v8__Data__IsFixedArray(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsFixedArray();
|
||||
}
|
||||
|
||||
bool v8__Data__IsFunctionTemplate(const v8::Data& self) {
|
||||
return self.IsFunctionTemplate();
|
||||
}
|
||||
|
||||
size_t v8__TypedArray__kMaxLength() { return v8::TypedArray::kMaxLength; }
|
||||
bool v8__Data__IsModule(const v8::Data& self) { return self.IsModule(); }
|
||||
|
||||
bool v8__Data__IsModuleRequest(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsModuleRequest();
|
||||
}
|
||||
|
||||
bool v8__Data__IsName(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsName();
|
||||
}
|
||||
|
||||
bool v8__Data__IsNumber(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsNumber();
|
||||
}
|
||||
|
||||
bool v8__Data__IsObjectTemplate(const v8::Data& self) {
|
||||
return self.IsObjectTemplate();
|
||||
}
|
||||
|
||||
bool v8__Data__IsPrimitive(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsPrimitive() && !self.IsPrivate();
|
||||
}
|
||||
|
||||
bool v8__Data__IsPrivate(const v8::Data& self) { return self.IsPrivate(); }
|
||||
|
||||
bool v8__Data__IsString(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsString();
|
||||
}
|
||||
|
||||
bool v8__Data__IsSymbol(const v8::Data& self) {
|
||||
return v8::Utils::OpenHandle(&self)->IsPublicSymbol();
|
||||
}
|
||||
|
||||
bool v8__Data__IsValue(const v8::Data& self) { return self.IsValue(); }
|
||||
|
||||
bool v8__Value__IsUndefined(const v8::Value& self) {
|
||||
return self.IsUndefined();
|
||||
|
@ -624,6 +664,10 @@ bool v8__Value__IsWasmModuleObject(const v8::Value& self) {
|
|||
return self.IsWasmModuleObject();
|
||||
}
|
||||
|
||||
bool v8__Value__IsWasmMemoryObject(const v8::Value& self) {
|
||||
return self.IsWasmMemoryObject();
|
||||
}
|
||||
|
||||
bool v8__Value__IsModuleNamespaceObject(const v8::Value& self) {
|
||||
return self.IsModuleNamespaceObject();
|
||||
}
|
||||
|
@ -2581,7 +2625,7 @@ v8::Isolate* v8__internal__GetIsolateFromHeapObject(const v8::Data& data) {
|
|||
: nullptr;
|
||||
}
|
||||
|
||||
int v8__internal__Object__GetHash(const v8::Data& data) {
|
||||
int v8__Value__GetHash(const v8::Value& data) {
|
||||
namespace i = v8::internal;
|
||||
i::Object object(reinterpret_cast<const i::Address&>(data));
|
||||
i::Isolate* isolate;
|
||||
|
|
351
src/data.rs
351
src/data.rs
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,5 @@
|
|||
use std::hash::Hash;
|
||||
use std::hash::Hasher;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::num::NonZeroI32;
|
||||
use std::ptr::null;
|
||||
|
||||
use crate::support::int;
|
||||
|
@ -242,11 +241,13 @@ impl Module {
|
|||
}
|
||||
}
|
||||
|
||||
/// The `Module` specific equivalent of `Data::get_hash()`.
|
||||
/// This function is kept around for testing purposes only.
|
||||
#[doc(hidden)]
|
||||
pub fn get_identity_hash(&self) -> int {
|
||||
unsafe { v8__Module__GetIdentityHash(self) }
|
||||
/// Returns the V8 hash value for this value. The current implementation
|
||||
/// uses a hidden property to store the identity hash.
|
||||
///
|
||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||
/// unique.
|
||||
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
||||
unsafe { NonZeroI32::new_unchecked(v8__Module__GetIdentityHash(self)) }
|
||||
}
|
||||
|
||||
/// Returns the underlying script's id.
|
||||
|
@ -385,12 +386,6 @@ impl Module {
|
|||
}
|
||||
}
|
||||
|
||||
impl Hash for Module {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_i32(self.get_identity_hash());
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleRequest {
|
||||
/// Returns the module specifier for this ModuleRequest.
|
||||
pub fn get_specifier(&self) -> Local<String> {
|
||||
|
|
14
src/name.rs
14
src/name.rs
|
@ -1,5 +1,7 @@
|
|||
// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use std::num::NonZeroI32;
|
||||
|
||||
use crate::support::int;
|
||||
use crate::Name;
|
||||
|
||||
|
@ -8,10 +10,12 @@ extern "C" {
|
|||
}
|
||||
|
||||
impl Name {
|
||||
/// The `String` or `Symbol` specific equivalent of `Data::get_hash()`.
|
||||
/// This function is kept around for testing purposes only.
|
||||
#[doc(hidden)]
|
||||
pub fn get_identity_hash(&self) -> int {
|
||||
unsafe { v8__Name__GetIdentityHash(self) }
|
||||
/// Returns the V8 hash value for this value. The current implementation
|
||||
/// uses a hidden property to store the identity hash.
|
||||
///
|
||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||
/// unique.
|
||||
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
||||
unsafe { NonZeroI32::new_unchecked(v8__Name__GetIdentityHash(self)) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::Private;
|
|||
use crate::PropertyAttribute;
|
||||
use crate::Value;
|
||||
use std::convert::TryFrom;
|
||||
use std::num::NonZeroI32;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Object__New(isolate: *mut Isolate) -> *const Object;
|
||||
|
@ -379,11 +380,13 @@ impl Object {
|
|||
.into()
|
||||
}
|
||||
|
||||
/// The `Object` specific equivalent of `Data::get_hash()`.
|
||||
/// This function is kept around for testing purposes only.
|
||||
#[doc(hidden)]
|
||||
pub fn get_identity_hash(&self) -> int {
|
||||
unsafe { v8__Object__GetIdentityHash(self) }
|
||||
/// Returns the V8 hash value for this value. The current implementation
|
||||
/// uses a hidden property to store the identity hash.
|
||||
///
|
||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||
/// unique.
|
||||
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
||||
unsafe { NonZeroI32::new_unchecked(v8__Object__GetIdentityHash(self)) }
|
||||
}
|
||||
|
||||
/// Returns the context in which the object was created.
|
||||
|
|
19
src/value.rs
19
src/value.rs
|
@ -1,3 +1,6 @@
|
|||
use std::num::NonZeroI32;
|
||||
|
||||
use crate::support::int;
|
||||
use crate::support::Maybe;
|
||||
use crate::BigInt;
|
||||
use crate::Boolean;
|
||||
|
@ -68,6 +71,7 @@ extern "C" {
|
|||
fn v8__Value__IsDataView(this: *const Value) -> bool;
|
||||
fn v8__Value__IsSharedArrayBuffer(this: *const Value) -> bool;
|
||||
fn v8__Value__IsProxy(this: *const Value) -> bool;
|
||||
fn v8__Value__IsWasmMemoryObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsWasmModuleObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsModuleNamespaceObject(this: *const Value) -> bool;
|
||||
fn v8__Value__StrictEquals(this: *const Value, that: *const Value) -> bool;
|
||||
|
@ -137,6 +141,7 @@ extern "C" {
|
|||
);
|
||||
fn v8__Value__BooleanValue(this: *const Value, isolate: *mut Isolate)
|
||||
-> bool;
|
||||
fn v8__Value__GetHash(this: *const Value) -> int;
|
||||
}
|
||||
|
||||
impl Value {
|
||||
|
@ -415,6 +420,11 @@ impl Value {
|
|||
unsafe { v8__Value__IsProxy(self) }
|
||||
}
|
||||
|
||||
/// Returns true if this value is a WasmMemoryObject.
|
||||
pub fn is_wasm_memory_object(&self) -> bool {
|
||||
unsafe { v8__Value__IsWasmMemoryObject(self) }
|
||||
}
|
||||
|
||||
/// Returns true if this value is a WasmModuleObject.
|
||||
pub fn is_wasm_module_object(&self) -> bool {
|
||||
unsafe { v8__Value__IsWasmModuleObject(self) }
|
||||
|
@ -608,4 +618,13 @@ impl Value {
|
|||
pub fn boolean_value<'s>(&self, scope: &mut HandleScope<'s, ()>) -> bool {
|
||||
unsafe { v8__Value__BooleanValue(self, scope.get_isolate_ptr()) }
|
||||
}
|
||||
|
||||
/// Returns the V8 hash value for this value. The current implementation
|
||||
/// uses a hidden property to store the identity hash on some object types.
|
||||
///
|
||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||
/// unique.
|
||||
pub fn get_hash(&self) -> NonZeroI32 {
|
||||
unsafe { NonZeroI32::new_unchecked(v8__Value__GetHash(self)) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1627,7 +1627,8 @@ fn object() {
|
|||
let object_ = v8::Object::new(scope);
|
||||
assert!(!object_.is_null_or_undefined());
|
||||
let id = object_.get_identity_hash();
|
||||
assert_ne!(id, 0);
|
||||
assert_eq!(id, object_.get_hash());
|
||||
assert_ne!(id, v8::Object::new(scope).get_hash());
|
||||
|
||||
assert!(object.has(scope, n1.into()).unwrap());
|
||||
assert!(object.has_own_property(scope, n1).unwrap());
|
||||
|
@ -2895,7 +2896,6 @@ fn get_hash() {
|
|||
let pri1 = primitives1.get_index(scope, i).unwrap();
|
||||
let pri2 = primitives2.get_index(scope, i).unwrap();
|
||||
let hash = pri1.get_hash();
|
||||
assert_ne!(hash, 0);
|
||||
assert_eq!(hash, pri2.get_hash());
|
||||
if let Ok(name) = v8::Local::<v8::Name>::try_from(pri1) {
|
||||
assert_eq!(hash, name.get_identity_hash());
|
||||
|
@ -2942,7 +2942,6 @@ fn get_hash() {
|
|||
for i in 0..len {
|
||||
let val = objects.get_index(scope, i).unwrap();
|
||||
let hash = val.get_hash();
|
||||
assert_ne!(hash, 0);
|
||||
let obj = v8::Local::<v8::Object>::try_from(val).unwrap();
|
||||
assert_eq!(hash, obj.get_identity_hash());
|
||||
if !hashes.insert(hash) {
|
||||
|
|
Loading…
Reference in a new issue