tor-browser

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

WasmFeatures.h (4271B)


      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 js_wasm_WasmFeatures_h
      8 #define js_wasm_WasmFeatures_h
      9 
     10 #include "js/WasmFeatures.h"
     11 #include "js/TypeDecls.h"
     12 
     13 namespace js {
     14 
     15 class JSStringBuilder;
     16 
     17 namespace wasm {
     18 
     19 // Return whether WebAssembly can in principle be compiled on this platform (ie
     20 // combination of hardware and OS), assuming at least one of the compilers that
     21 // supports the platform is not disabled by other settings.
     22 //
     23 // This predicate must be checked and must be true to call any of the top-level
     24 // wasm eval/compile methods.
     25 
     26 bool HasPlatformSupport();
     27 
     28 // Return whether WebAssembly is supported on this platform. This determines
     29 // whether the WebAssembly object is exposed to JS in this context / realm and
     30 //
     31 // It does *not* guarantee that a compiler is actually available; that has to be
     32 // checked separately, as it is sometimes run-time variant, depending on whether
     33 // a debugger has been created or not.
     34 
     35 bool HasSupport(JSContext* cx);
     36 
     37 // Predicates for compiler availability.
     38 //
     39 // These three predicates together select zero or one baseline compiler and zero
     40 // or one optimizing compiler, based on: what's compiled into the executable,
     41 // what's supported on the current platform, what's selected by options, and the
     42 // current run-time environment.  As it is possible for the computed values to
     43 // change (when a value changes in about:config or the debugger pane is shown or
     44 // hidden), it is inadvisable to cache these values in such a way that they
     45 // could become invalid.  Generally it is cheap always to recompute them.
     46 
     47 bool BaselineAvailable(JSContext* cx);
     48 bool IonAvailable(JSContext* cx);
     49 
     50 // Test all three.
     51 
     52 bool AnyCompilerAvailable(JSContext* cx);
     53 
     54 // Asm.JS is translated to wasm and then compiled using the wasm optimizing
     55 // compiler; test whether this compiler is available.
     56 
     57 bool WasmCompilerForAsmJSAvailable(JSContext* cx);
     58 
     59 // Predicates for white-box compiler disablement testing.
     60 //
     61 // These predicates determine whether the optimizing compilers were disabled by
     62 // features that are enabled at compile-time or run-time.  They do not consider
     63 // the hardware platform on whether other compilers are enabled.
     64 //
     65 // If `reason` is not null then it is populated with a string that describes
     66 // the specific features that disable the compiler.
     67 //
     68 // Returns false on OOM (which happens only when a reason is requested),
     69 // otherwise true, with the result in `*isDisabled` and optionally the reason in
     70 // `*reason`.
     71 
     72 bool BaselineDisabledByFeatures(JSContext* cx, bool* isDisabled,
     73                                JSStringBuilder* reason = nullptr);
     74 bool IonDisabledByFeatures(JSContext* cx, bool* isDisabled,
     75                           JSStringBuilder* reason = nullptr);
     76 
     77 // Predicates for feature availability.
     78 //
     79 // The following predicates check whether particular wasm features are enabled,
     80 // and for each, whether at least one compiler is (currently) available that
     81 // supports the feature.
     82 
     83 // Streaming compilation.
     84 bool StreamingCompilationAvailable(JSContext* cx);
     85 
     86 // Caching of optimized code.  Implies both streaming compilation and an
     87 // optimizing compiler tier.
     88 bool CodeCachingAvailable(JSContext* cx);
     89 
     90 // Shared memory and atomics.
     91 bool ThreadsAvailable(JSContext* cx);
     92 
     93 #define WASM_FEATURE(NAME, ...) bool NAME##Available(JSContext* cx);
     94 JS_FOR_WASM_FEATURES(WASM_FEATURE)
     95 #undef WASM_FEATURE
     96 
     97 // SIMD operations.
     98 bool SimdAvailable(JSContext* cx);
     99 
    100 // Privileged content that can access experimental features.
    101 bool IsPrivilegedContext(JSContext* cx);
    102 
    103 #if defined(ENABLE_WASM_SIMD) && defined(DEBUG)
    104 // Report the result of a Simd simplification to the testing infrastructure.
    105 void ReportSimdAnalysis(const char* data);
    106 #endif
    107 
    108 // Returns true if WebAssembly as configured by compile-time flags and run-time
    109 // options can support try/catch, throw, rethrow, and branch_on_exn (evolving).
    110 bool ExceptionsAvailable(JSContext* cx);
    111 
    112 }  // namespace wasm
    113 }  // namespace js
    114 
    115 #endif  // js_wasm_WasmFeatures_h