tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testBoundFunction.cpp (1023B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #include "jsapi-tests/tests.h"
      9 
     10 BEGIN_TEST(testBoundFunction) {
     11  EXEC("function foo() {}");
     12  JS::RootedValue foo(cx);
     13  EVAL("foo", &foo);
     14  JS::RootedValue bound(cx);
     15  EVAL("foo.bind(1)", &bound);
     16 
     17  JS::Rooted<JSObject*> foofun(cx, &foo.toObject());
     18  JS::Rooted<JSObject*> boundfun(cx, &bound.toObject());
     19 
     20  CHECK(!JS_ObjectIsBoundFunction(foofun));
     21  CHECK(JS_ObjectIsBoundFunction(boundfun));
     22 
     23  CHECK(!JS_GetBoundFunctionTarget(foofun));
     24  JSObject* target = JS_GetBoundFunctionTarget(boundfun);
     25  CHECK(!!target);
     26  CHECK(JS_ObjectIsFunction(target));
     27  JS::RootedValue targetVal(cx, JS::ObjectValue(*target));
     28  CHECK_SAME(foo, targetVal);
     29 
     30  return true;
     31 }
     32 END_TEST(testBoundFunction)