From 20ed06753543282e5981f605343ba039df2c9c44 Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 24 Mar 2019 11:44:06 +0300 Subject: [PATCH 1/2] Update .travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6c5cb10..cf4193c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: xenial language: rust rust: - nightly @@ -10,6 +11,7 @@ addons: apt: packages: - libgtk-3-dev + - libmount-dev script: - rustc --version - cargo build From 86c37159161dc596f9d54ca1d000d05e2bc88a31 Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 24 Mar 2019 08:19:54 +0300 Subject: [PATCH 2/2] Add stub for JSCValue and JSCContext --- Cargo.toml | 2 +- javascriptcore-sys/src/lib.rs | 2 ++ src/lib.rs | 57 +++++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed35a4e..e1e686d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ name = "javascriptcore" git = "https://github.com/gtk-rs/glib" [dependencies.javascriptcore-rs-sys] -git = "https://github.com/gtk-rs/javascriptcore-rs" +path = "./javascriptcore-sys" version = "0.1.1" diff --git a/javascriptcore-sys/src/lib.rs b/javascriptcore-sys/src/lib.rs index 5f8bedb..2d29f65 100644 --- a/javascriptcore-sys/src/lib.rs +++ b/javascriptcore-sys/src/lib.rs @@ -6,6 +6,8 @@ extern crate libc; use libc::{c_char, c_double, c_void}; +pub type JSCValue = *mut c_void; +pub type JSCContext = *mut c_void; pub type JSGlobalContextRef = *mut c_void; pub type JSValueRef = *mut c_void; pub type JSStringRef = *mut c_void; diff --git a/src/lib.rs b/src/lib.rs index 39caf57..78316c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,48 +10,52 @@ use std::ptr; use glib::translate::{FromGlibPtrFull, FromGlibPtrNone}; use javascriptcore_sys::*; -pub struct GlobalContext { +pub struct GlobalContextRef { raw: JSGlobalContextRef, } -pub struct Value { +pub struct ValueRef { raw: JSValueRef, } -impl Value { - pub fn is_boolean(&self, context: &GlobalContext) -> bool { +pub struct Value { + raw: JSCValue, +} + +impl ValueRef { + pub fn is_boolean(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsBoolean(context.raw, self.raw) != 0 } } - pub fn is_null(&self, context: &GlobalContext) -> bool { + pub fn is_null(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsNull(context.raw, self.raw) != 0 } } - pub fn is_undefined(&self, context: &GlobalContext) -> bool { + pub fn is_undefined(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsUndefined(context.raw, self.raw) != 0 } } - pub fn is_number(&self, context: &GlobalContext) -> bool { + pub fn is_number(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsNumber(context.raw, self.raw) != 0 } } - pub fn is_string(&self, context: &GlobalContext) -> bool { + pub fn is_string(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsString(context.raw, self.raw) != 0 } } - pub fn is_object(&self, context: &GlobalContext) -> bool { + pub fn is_object(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsObject(context.raw, self.raw) != 0 } } - pub fn is_array(&self, context: &GlobalContext) -> bool { + pub fn is_array(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsArray(context.raw, self.raw) != 0 } } - pub fn is_date(&self, context: &GlobalContext) -> bool { + pub fn is_date(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueIsDate(context.raw, self.raw) != 0 } } - pub fn to_number(&self, context: &GlobalContext) -> Option { + pub fn to_number(&self, context: &GlobalContextRef) -> Option { let mut exception = ptr::null_mut(); let result = unsafe { JSValueToNumber(context.raw, self.raw, &mut exception) }; if exception.is_null() { @@ -61,11 +65,11 @@ impl Value { } } - pub fn to_boolean(&self, context: &GlobalContext) -> bool { + pub fn to_boolean(&self, context: &GlobalContextRef) -> bool { unsafe { JSValueToBoolean(context.raw, self.raw) != 0} } - pub fn to_string(&self, context: &GlobalContext) -> Option { + pub fn to_string(&self, context: &GlobalContextRef) -> Option { unsafe { let mut exception = ptr::null_mut(); let jsstring = JSValueToStringCopy(context.raw, self.raw, &mut exception); @@ -84,33 +88,42 @@ impl Value { } } -impl FromGlibPtrNone for Value { +impl FromGlibPtrNone for ValueRef { unsafe fn from_glib_none(ptr: JSValueRef) -> Self { - Value { + ValueRef { raw: ptr, } } } -impl FromGlibPtrFull for Value { +impl FromGlibPtrFull for ValueRef { unsafe fn from_glib_full(ptr: JSValueRef) -> Self { - Value { + ValueRef { raw: ptr, } } } -impl FromGlibPtrNone for GlobalContext { +impl FromGlibPtrNone<*mut JSCValue> for Value { + unsafe fn from_glib_none(ptr: *mut JSCValue) -> Self { + assert!(ptr != ptr::null_mut()); + Value { + raw: *ptr, + } + } +} + +impl FromGlibPtrNone for GlobalContextRef { unsafe fn from_glib_none(ptr: JSGlobalContextRef) -> Self { - GlobalContext { + GlobalContextRef { raw: ptr, } } } -impl FromGlibPtrFull for GlobalContext { +impl FromGlibPtrFull for GlobalContextRef { unsafe fn from_glib_full(ptr: JSGlobalContextRef) -> Self { - GlobalContext { + GlobalContextRef { raw: ptr, } }