Skip to content

Commit

Permalink
Upgrade v8
Browse files Browse the repository at this point in the history
  • Loading branch information
joehoyle committed Nov 28, 2023
1 parent 665fce8 commit 86ac1c2
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 30 deletions.
208 changes: 189 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
ext-php-rs = "0.11.1"
v8 = "0.38.1"
v8 = "0.82.0"

[lib]
crate-type = ["cdylib"]
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ext_php_rs::binary::Binary;
use ext_php_rs::builders::ClassBuilder;
use ext_php_rs::convert::{FromZval, IntoZval};
use ext_php_rs::flags::DataType;
use ext_php_rs::types::{ZendHashTable, ZendObject, Zval};
use ext_php_rs::types::{ZendHashTable, ZendObject, Zval, ZendClassObject};
use ext_php_rs::zend::{ClassEntry, ModuleEntry};
use ext_php_rs::{exception::PhpException, zend::ce};
use ext_php_rs::{info_table_end, info_table_row, info_table_start, prelude::*, php_print};
Expand Down Expand Up @@ -54,9 +54,9 @@ pub fn zval_from_jsvalue(result: v8::Local<v8::Value>, scope: &mut v8::HandleSco
}
if result.is_object() {
let object = v8::Local::<v8::Object>::try_from(result).unwrap();
let properties = object.get_own_property_names(scope).unwrap();
let class_entry = ClassEntry::try_find("V8Object").unwrap();
let mut zend_object = ZendObject::new(class_entry);
let properties = object.get_own_property_names(scope, Default::default()).unwrap();
let mut obj = ZendClassObject::new(V8Object{});
let zend_object = obj.get_mut_zend_obj();
for index in 0..properties.length() {
let key = properties.get_index(scope, index).unwrap();
let value = object.get(scope, key).unwrap();
Expand Down Expand Up @@ -307,7 +307,7 @@ pub fn php_callback(
let isolate: &mut v8::Isolate = scope.as_mut();
let state = JSRuntime::state(isolate);
let state = state.borrow_mut();
let callback_name = args.data().unwrap().to_rust_string_lossy(scope);
let callback_name = args.data().to_rust_string_lossy(scope);
let callback = state.callbacks.get(&callback_name);
if callback.is_none() {
println!("callback not found {:#?}", callback_name);
Expand Down
8 changes: 3 additions & 5 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,9 @@ impl JSRuntime {
pub fn create_snapshot(source: String) -> Option<Vec<u8>> {
// Make sure platform is initted.
JSRuntime::new(None);
let mut snapshot_creator = v8::SnapshotCreator::new(None);
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
let mut snapshot_creator = v8::Isolate::snapshot_creator(None);
{
let scope = &mut v8::HandleScope::new(&mut isolate);
let scope = &mut v8::HandleScope::new(&mut snapshot_creator);
let c = v8::Context::new(scope);
let cg = v8::Local::new(scope, c);
let context = v8::Global::new(scope, cg);
Expand All @@ -302,10 +301,9 @@ impl JSRuntime {
};

script.run(scope);
snapshot_creator.set_default_context(context);
scope.set_default_context(context);
}
// The isolate must be dropped, else PHP will segfault.
std::mem::forget(isolate);
let blob = snapshot_creator.create_blob(v8::FunctionCodeHandling::Clear);
let startup_data = match blob {
Some(data) => data,
Expand Down

0 comments on commit 86ac1c2

Please sign in to comment.