|
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/. */ |
|
4 |
|
5 #include "jsapi-tests/tests.h" |
|
6 |
|
7 BEGIN_TEST(test_BindCallable) |
|
8 { |
|
9 JS::RootedValue v(cx); |
|
10 EVAL("({ somename : 1717 })", &v); |
|
11 CHECK(v.isObject()); |
|
12 |
|
13 JS::RootedValue func(cx); |
|
14 EVAL("(function() { return this.somename; })", &func); |
|
15 CHECK(func.isObject()); |
|
16 |
|
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); |
|
21 |
|
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); |
|
26 |
|
27 CHECK(JSVAL_IS_INT(retval)); |
|
28 |
|
29 CHECK(JSVAL_TO_INT(retval) == 1717); |
|
30 return true; |
|
31 } |
|
32 END_TEST(test_BindCallable) |