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> {
|
-> Fallible<JSVal> {
|
||||||
let mut callable = UndefinedValue();
|
let mut callable = UndefinedValue();
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = CString::new(name).unwrap();
|
let c_name = CString::new(name).unwrap();
|
||||||
if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 {
|
if JS_GetProperty(cx, self.callback(), c_name.as_ptr(), &mut callable) == 0 {
|
||||||
return Err(Error::JSFailed);
|
return Err(Error::JSFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !callable.is_object() ||
|
if !callable.is_object() ||
|
||||||
JS_ObjectIsCallable(cx, callable.to_object()) == 0 {
|
JS_ObjectIsCallable(cx, callable.to_object()) == 0 {
|
||||||
// FIXME(#347)
|
return Err(Error::Type(
|
||||||
//ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
|
format!("The value of the {} property is not callable", name)));
|
||||||
return Err(Error::JSFailed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(callable)
|
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' });
|
assert_node(walker.currentNode, { type: Element, id: 'B1' });
|
||||||
}, 'Testing with undefined filter');
|
}, 'Testing with undefined filter');
|
||||||
|
|
||||||
// XXX Servo breaks the test when a callback isn't callable
|
|
||||||
test(function()
|
test(function()
|
||||||
{
|
{
|
||||||
var walker = document.createTreeWalker(testElement, /*NodeFilter.*/SHOW_ELEMENT, {});
|
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_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' });
|
assert_node(walker.currentNode, { type: Element, id: 'root' });
|
||||||
}, 'Testing with object lacking acceptNode property');
|
}, 'Testing with object lacking acceptNode property');
|
||||||
|
|
||||||
// XXX Servo breaks the test when a callback isn't callable
|
|
||||||
test(function()
|
test(function()
|
||||||
{
|
{
|
||||||
var walker = document.createTreeWalker(testElement, /*NodeFilter.*/SHOW_ELEMENT, { acceptNode: "foo" });
|
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_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' });
|
assert_node(walker.currentNode, { type: Element, id: 'root' });
|
||||||
}, 'Testing with object with non-function acceptNode property');
|
}, 'Testing with object with non-function acceptNode property');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue