Bug 1454512 - Fix JS::Value's is_symbol predicate. r=sfink
authorRobin Templeton <robin@igalia.com>
Wed, 18 Apr 2018 15:44:43 -0400
changeset 467955 fd6fc6aa64483fca4e85f67690e08233707c9d81
parent 467954 088d40fae53da887d353577b5b855475a8617bf9
child 467956 15b7d9b0d059df9ae3527c33c2c104790eaa23f1
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1454512
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1454512 - Fix JS::Value's is_symbol predicate. r=sfink
js/rust/Cargo.toml
js/rust/src/jsval.rs
js/rust/tests/value.rs
--- a/js/rust/Cargo.toml
+++ b/js/rust/Cargo.toml
@@ -23,16 +23,18 @@ name = "panic"
 name = "rooting"
 [[test]]
 name = "runtime"
 [[test]]
 name = "typedarray"
 [[test]]
 name = "stack_limit"
 [[test]]
+name = "value"
+[[test]]
 name = "vec_conversion"
 
 [lib]
 doctest = false
 
 [features]
 debugmozjs = ['mozjs_sys/debugmozjs']
 promises = ['mozjs_sys/promises']
--- a/js/rust/src/jsval.rs
+++ b/js/rust/src/jsval.rs
@@ -346,17 +346,17 @@ impl JS::Value {
             (self.asBits() >> 32) == ValueTag::OBJECT as u64
         }
     }
 
     #[inline(always)]
     #[cfg(target_pointer_width = "64")]
     pub fn is_symbol(&self) -> bool {
         unsafe {
-            self.asBits() == ValueShiftedTag::SYMBOL as u64
+            (self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::SYMBOL as u64
         }
     }
 
     #[inline(always)]
     #[cfg(target_pointer_width = "32")]
     pub fn is_symbol(&self) -> bool {
         unsafe {
             (self.asBits() >> 32) == ValueTag::SYMBOL as u64
new file mode 100644
--- /dev/null
+++ b/js/rust/tests/value.rs
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#[macro_use]
+extern crate js;
+
+use js::jsapi::root::JS::CompartmentOptions;
+use js::jsapi::root::JS_NewGlobalObject;
+use js::jsapi::root::JS::OnNewGlobalHookOption;
+use js::jsval::UndefinedValue;
+use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
+
+use std::ptr;
+
+#[test]
+fn is_symbol() {
+    let rt = Runtime::new(false).unwrap();
+    let cx = rt.cx();
+
+    unsafe {
+        rooted!(in(cx) let global =
+            JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(),
+                               OnNewGlobalHookOption::FireOnNewGlobalHook,
+                               &CompartmentOptions::default())
+        );
+        rooted!(in(cx) let mut rval = UndefinedValue());
+        assert!(rt.evaluate_script(global.handle(), "Symbol('test')",
+                                   "test", 1, rval.handle_mut()).is_ok());
+        assert!(rval.is_symbol());
+    }
+}
+
+#[test]
+fn is_not_symbol() {
+    let rt = Runtime::new(false).unwrap();
+    let cx = rt.cx();
+
+    unsafe {
+        rooted!(in(cx) let global =
+            JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(),
+                               OnNewGlobalHookOption::FireOnNewGlobalHook,
+                               &CompartmentOptions::default())
+        );
+        rooted!(in(cx) let mut rval = UndefinedValue());
+        assert!(rt.evaluate_script(global.handle(), "'not a symbol'",
+                                   "test", 1, rval.handle_mut()).is_ok());
+        assert!(!rval.is_symbol());
+    }
+}