tor-browser

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

testInformalValueTypeName.cpp (1723B)


      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 "js/Array.h"  // JS::NewArrayObject
      9 #include "js/Symbol.h"
     10 #include "jsapi-tests/tests.h"
     11 
     12 BEGIN_TEST(testInformalValueTypeName) {
     13  JS::RootedValue v1(cx, JS::ObjectOrNullValue(JS_NewPlainObject(cx)));
     14  CHECK(strcmp(JS::InformalValueTypeName(v1), "Object") == 0);
     15 
     16  JS::RootedValue v2(cx, JS::ObjectOrNullValue(JS::NewArrayObject(cx, 0)));
     17  CHECK(strcmp(JS::InformalValueTypeName(v2), "Array") == 0);
     18 
     19  JS::RootedValue v3(cx, JS::StringValue(JS_GetEmptyString(cx)));
     20  CHECK(strcmp(JS::InformalValueTypeName(v3), "string") == 0);
     21 
     22  JS::RootedValue v4(cx, JS::SymbolValue(JS::NewSymbol(cx, nullptr)));
     23  CHECK(strcmp(JS::InformalValueTypeName(v4), "symbol") == 0);
     24 
     25  JS::RootedValue v5(cx, JS::NumberValue(50.5));
     26  CHECK(strcmp(JS::InformalValueTypeName(v5), "number") == 0);
     27  JS::RootedValue v6(cx, JS::Int32Value(50));
     28  CHECK(strcmp(JS::InformalValueTypeName(v6), "number") == 0);
     29  JS::RootedValue v7(cx, JS::Float32Value(50.5));
     30  CHECK(strcmp(JS::InformalValueTypeName(v7), "number") == 0);
     31 
     32  JS::RootedValue v8(cx, JS::TrueValue());
     33  CHECK(strcmp(JS::InformalValueTypeName(v8), "boolean") == 0);
     34 
     35  JS::RootedValue v9(cx, JS::NullValue());
     36  CHECK(strcmp(JS::InformalValueTypeName(v9), "null") == 0);
     37 
     38  JS::RootedValue v10(cx, JS::UndefinedValue());
     39  CHECK(strcmp(JS::InformalValueTypeName(v10), "undefined") == 0);
     40 
     41  return true;
     42 }
     43 END_TEST(testInformalValueTypeName)