michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: BEGIN_TEST(test_BindCallable) michael@0: { michael@0: JS::RootedValue v(cx); michael@0: EVAL("({ somename : 1717 })", &v); michael@0: CHECK(v.isObject()); michael@0: michael@0: JS::RootedValue func(cx); michael@0: EVAL("(function() { return this.somename; })", &func); michael@0: CHECK(func.isObject()); michael@0: michael@0: JS::RootedObject funcObj(cx, JSVAL_TO_OBJECT(func)); michael@0: JS::RootedObject vObj(cx, JSVAL_TO_OBJECT(v)); michael@0: JSObject* newCallable = JS_BindCallable(cx, funcObj, vObj); michael@0: CHECK(newCallable); michael@0: michael@0: JS::RootedValue retval(cx); michael@0: JS::RootedValue fun(cx, JS::ObjectValue(*newCallable)); michael@0: bool called = JS_CallFunctionValue(cx, JS::NullPtr(), fun, JS::HandleValueArray::empty(), &retval); michael@0: CHECK(called); michael@0: michael@0: CHECK(JSVAL_IS_INT(retval)); michael@0: michael@0: CHECK(JSVAL_TO_INT(retval) == 1717); michael@0: return true; michael@0: } michael@0: END_TEST(test_BindCallable)