| 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 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef jspubtd_h |
| 8 |
#define jspubtd_h |
| 9 |
|
| 10 |
/* |
| 11 |
* JS public API typedefs. |
| 12 |
*/ |
| 13 |
|
| 14 |
#include "mozilla/Assertions.h" // MOZ_ASSERT_UNREACHABLE |
| 15 |
|
| 16 |
#include "jstypes.h" |
| 17 |
|
| 18 |
#include "js/ProtoKey.h" |
| 19 |
#include "js/Result.h" |
| 20 |
#include "js/TraceKind.h" |
| 21 |
#include "js/TypeDecls.h" |
| 22 |
|
| 23 |
#if defined(JS_GC_ZEAL) || defined(DEBUG) |
| 24 |
# define JSGC_HASH_TABLE_CHECKS |
| 25 |
# define JS_CHECK_UNSAFE_CALL_WITH_ABI |
| 26 |
#endif |
| 27 |
|
| 28 |
namespace JS { |
| 29 |
|
| 30 |
class CallArgs; |
| 31 |
|
| 32 |
class JS_PUBLIC_API RealmOptions; |
| 33 |
|
| 34 |
} // namespace JS |
| 35 |
|
| 36 |
/* Result of typeof operator enumeration. */ |
| 37 |
enum JSType { |
| 38 |
JSTYPE_UNDEFINED, /* undefined */ |
| 39 |
JSTYPE_OBJECT, /* object */ |
| 40 |
JSTYPE_FUNCTION, /* function */ |
| 41 |
JSTYPE_STRING, /* string */ |
| 42 |
JSTYPE_NUMBER, /* number */ |
| 43 |
JSTYPE_BOOLEAN, /* boolean */ |
| 44 |
JSTYPE_SYMBOL, /* symbol */ |
| 45 |
JSTYPE_BIGINT, /* bigint */ |
| 46 |
JSTYPE_LIMIT |
| 47 |
}; |
| 48 |
|
| 49 |
inline const char* JSTypeToString(JSType type) { |
| 50 |
switch (type) { |
| 51 |
case JSTYPE_UNDEFINED: |
| 52 |
return "undefined"; |
| 53 |
case JSTYPE_OBJECT: |
| 54 |
return "object"; |
| 55 |
case JSTYPE_FUNCTION: |
| 56 |
return "function"; |
| 57 |
case JSTYPE_STRING: |
| 58 |
return "string"; |
| 59 |
case JSTYPE_NUMBER: |
| 60 |
return "number"; |
| 61 |
case JSTYPE_BOOLEAN: |
| 62 |
return "boolean"; |
| 63 |
case JSTYPE_SYMBOL: |
| 64 |
return "symbol"; |
| 65 |
case JSTYPE_BIGINT: |
| 66 |
return "bigint"; |
| 67 |
default: |
| 68 |
MOZ_ASSERT_UNREACHABLE("Unknown JSType"); |
| 69 |
} |
| 70 |
return ""; |
| 71 |
} |
| 72 |
|
| 73 |
/* Dense index into cached prototypes and class atoms for standard objects. */ |
| 74 |
enum JSProtoKey { |
| 75 |
#define PROTOKEY_AND_INITIALIZER(name, clasp) JSProto_##name, |
| 76 |
JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) |
| 77 |
#undef PROTOKEY_AND_INITIALIZER |
| 78 |
JSProto_LIMIT |
| 79 |
}; |
| 80 |
|
| 81 |
/* Struct forward declarations. */ |
| 82 |
struct JSClass; |
| 83 |
class JSErrorReport; |
| 84 |
struct JSFunctionSpec; |
| 85 |
struct JSPrincipals; |
| 86 |
struct JSPropertySpec; |
| 87 |
struct JSSecurityCallbacks; |
| 88 |
struct JSStructuredCloneCallbacks; |
| 89 |
struct JSStructuredCloneReader; |
| 90 |
struct JSStructuredCloneWriter; |
| 91 |
class JS_PUBLIC_API JSTracer; |
| 92 |
|
| 93 |
class JSLinearString; |
| 94 |
|
| 95 |
template <typename T> |
| 96 |
struct JSConstScalarSpec; |
| 97 |
using JSConstDoubleSpec = JSConstScalarSpec<double>; |
| 98 |
using JSConstIntegerSpec = JSConstScalarSpec<int32_t>; |
| 99 |
|
| 100 |
namespace js { |
| 101 |
|
| 102 |
inline JS::Realm* GetContextRealm(const JSContext* cx); |
| 103 |
inline JS::Compartment* GetContextCompartment(const JSContext* cx); |
| 104 |
inline JS::Zone* GetContextZone(const JSContext* cx); |
| 105 |
|
| 106 |
// Whether the current thread is permitted access to any part of the specified |
| 107 |
// runtime or zone. |
| 108 |
JS_PUBLIC_API bool CurrentThreadCanAccessRuntime(const JSRuntime* rt); |
| 109 |
|
| 110 |
#ifdef DEBUG |
| 111 |
JS_PUBLIC_API bool CurrentThreadIsMainThread(); |
| 112 |
JS_PUBLIC_API bool CurrentThreadIsPerformingGC(); |
| 113 |
#endif |
| 114 |
|
| 115 |
} // namespace js |
| 116 |
|
| 117 |
namespace JS { |
| 118 |
|
| 119 |
class JS_PUBLIC_API PropertyDescriptor; |
| 120 |
|
| 121 |
// Decorates the Unlinking phase of CycleCollection so that accidental use |
| 122 |
// of barriered accessors results in assertions instead of leaks. |
| 123 |
class MOZ_STACK_CLASS JS_PUBLIC_API AutoEnterCycleCollection { |
| 124 |
#ifdef DEBUG |
| 125 |
JSRuntime* runtime_; |
| 126 |
|
| 127 |
public: |
| 128 |
explicit AutoEnterCycleCollection(JSRuntime* rt); |
| 129 |
~AutoEnterCycleCollection(); |
| 130 |
#else |
| 131 |
public: |
| 132 |
explicit AutoEnterCycleCollection(JSRuntime* rt) {} |
| 133 |
~AutoEnterCycleCollection() {} |
| 134 |
#endif |
| 135 |
}; |
| 136 |
|
| 137 |
} /* namespace JS */ |
| 138 |
|
| 139 |
extern "C" { |
| 140 |
|
| 141 |
// Defined in NSPR prio.h. |
| 142 |
using PRFileDesc = struct PRFileDesc; |
| 143 |
} |
| 144 |
|
| 145 |
#endif /* jspubtd_h */ |