Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "jsapi-tests/tests.h"
7 BEGIN_TEST(test_BindCallable)
8 {
9 JS::RootedValue v(cx);
10 EVAL("({ somename : 1717 })", &v);
11 CHECK(v.isObject());
13 JS::RootedValue func(cx);
14 EVAL("(function() { return this.somename; })", &func);
15 CHECK(func.isObject());
17 JS::RootedObject funcObj(cx, JSVAL_TO_OBJECT(func));
18 JS::RootedObject vObj(cx, JSVAL_TO_OBJECT(v));
19 JSObject* newCallable = JS_BindCallable(cx, funcObj, vObj);
20 CHECK(newCallable);
22 JS::RootedValue retval(cx);
23 JS::RootedValue fun(cx, JS::ObjectValue(*newCallable));
24 bool called = JS_CallFunctionValue(cx, JS::NullPtr(), fun, JS::HandleValueArray::empty(), &retval);
25 CHECK(called);
27 CHECK(JSVAL_IS_INT(retval));
29 CHECK(JSVAL_TO_INT(retval) == 1717);
30 return true;
31 }
32 END_TEST(test_BindCallable)