14
14
#define js_RealmOptions_h
15
15
16
16
#include " mozilla/Assertions.h" // MOZ_ASSERT
17
+ #include " mozilla/Maybe.h"
17
18
18
19
#include " jstypes.h" // JS_PUBLIC_API
19
20
@@ -320,6 +321,12 @@ class JS_PUBLIC_API RealmCreationOptions {
320
321
bool alwaysUseFdlibm_ = false ;
321
322
};
322
323
324
+ // This is a wrapper for mozilla::RTPCallerType, that can't easily
325
+ // be exposed to the JS engine for layering reasons.
326
+ struct RTPCallerTypeToken {
327
+ uint8_t value;
328
+ };
329
+
323
330
/* *
324
331
* RealmBehaviors specifies behaviors of a realm that can be changed after the
325
332
* realm's been created.
@@ -328,6 +335,17 @@ class JS_PUBLIC_API RealmBehaviors {
328
335
public:
329
336
RealmBehaviors () = default ;
330
337
338
+ // When a JS::ReduceMicrosecondTimePrecisionCallback callback is defined via
339
+ // JS::SetReduceMicrosecondTimePrecisionCallback, a JS::RTPCallerTypeToken (a
340
+ // wrapper for mozilla::RTPCallerType) needs to be set for every Realm.
341
+ mozilla::Maybe<RTPCallerTypeToken> reduceTimerPrecisionCallerType () const {
342
+ return rtpCallerType;
343
+ }
344
+ RealmBehaviors& setReduceTimerPrecisionCallerType (RTPCallerTypeToken type) {
345
+ rtpCallerType = mozilla::Some (type);
346
+ return *this ;
347
+ }
348
+
331
349
// For certain globals, we know enough about the code that will run in them
332
350
// that we can discard script source entirely.
333
351
bool discardSource () const { return discardSource_; }
@@ -342,29 +360,6 @@ class JS_PUBLIC_API RealmBehaviors {
342
360
return *this ;
343
361
}
344
362
345
- class Override {
346
- public:
347
- Override () : mode_(Default) {}
348
-
349
- bool get (bool defaultValue) const {
350
- if (mode_ == Default) {
351
- return defaultValue;
352
- }
353
- return mode_ == ForceTrue;
354
- }
355
-
356
- void set (bool overrideValue) {
357
- mode_ = overrideValue ? ForceTrue : ForceFalse;
358
- }
359
-
360
- void reset () { mode_ = Default; }
361
-
362
- private:
363
- enum Mode { Default, ForceTrue, ForceFalse };
364
-
365
- Mode mode_;
366
- };
367
-
368
363
// A Realm can stop being "live" in all the ways that matter before its global
369
364
// is actually GCed. Consumers that tear down parts of a Realm or its global
370
365
// before that point should set isNonLive accordingly.
@@ -375,6 +370,7 @@ class JS_PUBLIC_API RealmBehaviors {
375
370
}
376
371
377
372
private:
373
+ mozilla::Maybe<RTPCallerTypeToken> rtpCallerType;
378
374
bool discardSource_ = false ;
379
375
bool clampAndJitterTime_ = true ;
380
376
bool isNonLive_ = false ;
@@ -423,6 +419,11 @@ extern JS_PUBLIC_API const RealmBehaviors& RealmBehaviorsRef(JSContext* cx);
423
419
424
420
extern JS_PUBLIC_API void SetRealmNonLive (Realm* realm);
425
421
422
+ // This behaves like RealmBehaviors::setReduceTimerPrecisionCallerType, but
423
+ // can be used even after the Realm has already been created.
424
+ extern JS_PUBLIC_API void SetRealmReduceTimerPrecisionCallerType (
425
+ Realm* realm, RTPCallerTypeToken type);
426
+
426
427
} // namespace JS
427
428
428
429
#endif // js_RealmOptions_h
0 commit comments