mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Throw a TypeError when get_callable_property encounters a value that isn't callable.
This commit is contained in:
parent
0607cd3fb5
commit
90a7ef1571
3 changed files with 8 additions and 14 deletions
|
@ -99,16 +99,15 @@ impl CallbackInterface {
|
|||
-> Fallible<JSVal> {
|
||||
let mut callable = UndefinedValue();
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 {
|
||||
let c_name = CString::new(name).unwrap();
|
||||
if JS_GetProperty(cx, self.callback(), c_name.as_ptr(), &mut callable) == 0 {
|
||||
return Err(Error::JSFailed);
|
||||
}
|
||||
|
||||
if !callable.is_object() ||
|
||||
JS_ObjectIsCallable(cx, callable.to_object()) == 0 {
|
||||
// FIXME(#347)
|
||||
//ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
|
||||
return Err(Error::JSFailed);
|
||||
return Err(Error::Type(
|
||||
format!("The value of the {} property is not callable", name)));
|
||||
}
|
||||
}
|
||||
Ok(callable)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[TreeWalker-acceptNode-filter.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -85,23 +85,21 @@ test(function()
|
|||
assert_node(walker.currentNode, { type: Element, id: 'B1' });
|
||||
}, 'Testing with undefined filter');
|
||||
|
||||
// XXX Servo breaks the test when a callback isn't callable
|
||||
test(function()
|
||||
{
|
||||
var walker = document.createTreeWalker(testElement, /*NodeFilter.*/SHOW_ELEMENT, {});
|
||||
assert_throws(null, function () { walker.firstChild(); });
|
||||
assert_throws(new TypeError(), function () { walker.firstChild(); });
|
||||
assert_node(walker.currentNode, { type: Element, id: 'root' });
|
||||
assert_throws(null, function () { walker.nextNode(); });
|
||||
assert_throws(new TypeError(), function () { walker.nextNode(); });
|
||||
assert_node(walker.currentNode, { type: Element, id: 'root' });
|
||||
}, 'Testing with object lacking acceptNode property');
|
||||
|
||||
// XXX Servo breaks the test when a callback isn't callable
|
||||
test(function()
|
||||
{
|
||||
var walker = document.createTreeWalker(testElement, /*NodeFilter.*/SHOW_ELEMENT, { acceptNode: "foo" });
|
||||
assert_throws(null, function () { walker.firstChild(); });
|
||||
assert_throws(new TypeError(), function () { walker.firstChild(); });
|
||||
assert_node(walker.currentNode, { type: Element, id: 'root' });
|
||||
assert_throws(null, function () { walker.nextNode(); });
|
||||
assert_throws(new TypeError(), function () { walker.nextNode(); });
|
||||
assert_node(walker.currentNode, { type: Element, id: 'root' });
|
||||
}, 'Testing with object with non-function acceptNode property');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue