diff options
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 18 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 8 | ||||
-rw-r--r-- | ports/cef/Cargo.lock | 10 | ||||
-rw-r--r-- | ports/gonk/Cargo.lock | 8 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/MANIFEST.json | 6 | ||||
-rw-r--r-- | tests/wpt/mozilla/tests/mozilla/sequence-hole.html | 28 |
6 files changed, 62 insertions, 16 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 0ddee79814b..3bf389a6596 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -97,11 +97,15 @@ impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite impl <T: Reflectable + IDLInterface> FromJSValConvertible for Root<T> { type Config = (); - unsafe fn from_jsval(_cx: *mut JSContext, + unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _config: Self::Config) - -> Result<Root<T>, ()> { - root_from_handlevalue(value) + -> Result<Root<T>, ()> { + let result = root_from_handlevalue(value); + if let Err(()) = result { + throw_type_error(cx, "value is not an object"); + } + result } } @@ -323,16 +327,24 @@ pub fn root_from_object<T>(obj: *mut JSObject) -> Result<Root<T>, ()> } /// Get a `*const T` for a DOM object accessible from a `HandleValue`. +/// Caller is responsible for throwing a JS exception if needed in case of error. pub fn native_from_handlevalue<T>(v: HandleValue) -> Result<*const T, ()> where T: Reflectable + IDLInterface { + if !v.get().is_object() { + return Err(()); + } native_from_object(v.get().to_object()) } /// Get a `Root<T>` for a DOM object accessible from a `HandleValue`. +/// Caller is responsible for throwing a JS exception if needed in case of error. pub fn root_from_handlevalue<T>(v: HandleValue) -> Result<Root<T>, ()> where T: Reflectable + IDLInterface { + if !v.get().is_object() { + return Err(()); + } root_from_object(v.get().to_object()) } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 4b55e6e0f3f..62e60d86b82 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -927,8 +927,8 @@ dependencies = [ [[package]] name = "js" -version = "0.1.1" -source = "git+https://github.com/servo/rust-mozjs#6b53c4937b67dc71414d37dd3f4ad5cf407b2c2b" +version = "0.1.2" +source = "git+https://github.com/servo/rust-mozjs#d88f289340ff32f0aa118e4621e250c0fa2f71e0" dependencies = [ "heapsize 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1580,7 +1580,7 @@ dependencies = [ "hyper 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.2.0 (git+https://github.com/servo/ipc-channel)", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", @@ -2042,7 +2042,7 @@ dependencies = [ "heapsize 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.2.0 (git+https://github.com/servo/ipc-channel)", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 7b61e4decb3..6f961298f7c 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -14,7 +14,7 @@ dependencies = [ "gfx 0.0.1", "gleam 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "glutin_app 0.0.1", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "layers 0.2.1 (git+https://github.com/servo/rust-layers)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -858,8 +858,8 @@ dependencies = [ [[package]] name = "js" -version = "0.1.1" -source = "git+https://github.com/servo/rust-mozjs#6b53c4937b67dc71414d37dd3f4ad5cf407b2c2b" +version = "0.1.2" +source = "git+https://github.com/servo/rust-mozjs#d88f289340ff32f0aa118e4621e250c0fa2f71e0" dependencies = [ "heapsize 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1467,7 +1467,7 @@ dependencies = [ "hyper 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.2.0 (git+https://github.com/servo/ipc-channel)", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", @@ -1938,7 +1938,7 @@ dependencies = [ "heapsize 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.2.0 (git+https://github.com/servo/ipc-channel)", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 0a6fe1fd954..3ce28d5e585 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -840,8 +840,8 @@ dependencies = [ [[package]] name = "js" -version = "0.1.1" -source = "git+https://github.com/servo/rust-mozjs#6b53c4937b67dc71414d37dd3f4ad5cf407b2c2b" +version = "0.1.2" +source = "git+https://github.com/servo/rust-mozjs#d88f289340ff32f0aa118e4621e250c0fa2f71e0" dependencies = [ "heapsize 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1449,7 +1449,7 @@ dependencies = [ "hyper 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.2.0 (git+https://github.com/servo/ipc-channel)", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", @@ -1918,7 +1918,7 @@ dependencies = [ "heapsize 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.2.0 (git+https://github.com/servo/ipc-channel)", - "js 0.1.1 (git+https://github.com/servo/rust-mozjs)", + "js 0.1.2 (git+https://github.com/servo/rust-mozjs)", "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 240916f0e07..2c76939ec47 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6054,6 +6054,12 @@ "url": "/_mozilla/mozilla/script_type.html" } ], + "mozilla/sequence-hole.html": [ + { + "path": "mozilla/sequence-hole.html", + "url": "/_mozilla/mozilla/sequence-hole.html" + } + ], "mozilla/storage.html": [ { "path": "mozilla/storage.html", diff --git a/tests/wpt/mozilla/tests/mozilla/sequence-hole.html b/tests/wpt/mozilla/tests/mozilla/sequence-hole.html new file mode 100644 index 00000000000..00217698594 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/sequence-hole.html @@ -0,0 +1,28 @@ +<!doctype html> +<meta charset="utf-8"> +<title></title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(function() { + var t = new TestBinding; + t.passSequence([1,, 3]); + t.passStringSequence(["camembert",, "comté"]); + assert_throws(new TypeError, function () { t.passInterfaceSequence([new Blob,, new Blob]) }); +}, "Sequences with holes are correctly handled"); + +test(function() { + var test_error = { name: "test" }; + Object.defineProperty(Array.prototype, 1, { get: function() { throw test_error; } }); + var t = new TestBinding; + assert_throws(test_error, function() { + t.passSequence([1,, 3]); + }); + assert_throws(test_error, function() { + t.passStringSequence(["camembert",, "comté"]); + }); + assert_throws(test_error, function() { + t.passInterfaceSequence([new Blob,, new Blob]); + }); +}, "Sequences with holes and a getter on the prototype are correctly handled"); +</script> |