npx skills add ...
npx skills add facebook/hermes --skill modify-jsi-features
npx skills add facebook/hermes --skill modify-jsi-features
Guide for adding new JSI functionality to the JavaScript Interface (JSI) layer. Use when the user asks to add, create, or implement new methods or features in the JSI Runtime interface. Covers all required files across JSI core, Hermes implementation, and SynthTrace replay support.
When adding new functionality (methods) to the JSI Runtime interface, you must modify a specific set of files across multiple layers. This skill describes each file, the patterns to follow, and important conventions.
JSI (JavaScript Interface) is an abstraction layer that allows C++ code to interact with JavaScript runtimes. The architecture consists of:
xplat/jsi/jsi/) — The abstract interface definitionsxplat/static_h/API/hermes/) — Hermes-specific implementationxplat/static_h/API/hermes/) — Recording and replay infrastructure for debuggingxplat/jsi/jsi/jsi.h — Add pure virtual method declaration to IRuntime interface AND override declaration in Runtime classxplat/jsi/jsi/jsi.cpp — Add default implementation (if providing one)xplat/jsi/jsi/jsi-inl.h — Add inline helper methods (if needed)xplat/jsi/jsi/decorator.h — Add method overrides to RuntimeDecorator and WithRuntimeDecoratorxplat/jsi/jsi/test/testlib.cpp — Add tests for the JSI APIxplat/static_h/API/hermes/hermes.cpp — Add Hermes-specific implementation in HermesRuntimeImplxplat/static_h/unittests/API/APITest.cpp — Add Hermes-specific testsxplat/static_h/API/hermes/SynthTrace.h — Add new Record typesxplat/static_h/API/hermes/SynthTrace.cpp — Implement Record serializationxplat/static_h/API/hermes/TracingRuntime.h — Declare tracing method overridesxplat/static_h/API/hermes/TracingRuntime.cpp — Implement tracing logicxplat/static_h/API/hermes/SynthTraceParser.cpp — Add parsing for new recordsxplat/static_h/API/hermes/TraceInterpreter.cpp — Add replay logicxplat/static_h/unittests/API/SynthTraceTest.cpp — Add replay testsxplat/static_h/unittests/API/SynthTraceSerializationTest.cpp — Add serialization testsxplat/static_h/unittests/API/SynthTraceParserTest.cpp — Add parser testsWhen adding new features (methods) to the JSI Runtime, you have two options:
Provide a default implementation in jsi::Runtime that works via JavaScript
calls. This allows all runtimes (JSC, V8, etc.) to work without modification.
Make the method pure virtual, requiring all runtimes (JSCRuntime, V8Runtime, HermesRuntime) to implement it. Only use this when a JavaScript-based default is not possible.
jsi.h (JSI Core Interface)Add the pure virtual method declaration to the IRuntime interface, and the override declaration to the Runtime class:
Important: The IRuntime interface contains the pure virtual declarations (= 0),
while the Runtime class provides the default implementation with override keyword.
This separation allows other runtimes to implement the interface differently while
Runtime provides a JavaScript-based fallback.
jsi.cppImplement the default using JavaScript APIs when possible:
jsi-inl.h (If Needed)For methods that return incomplete types at declaration time:
decorator.hAdd method overrides to both RuntimeDecorator and WithRuntimeDecorator:
test/testlib.cppTest the default implementation using a RuntimeDecorator:
hermes.cppImplement the optimized version using Hermes VM APIs inside HermesRuntimeImpl:
APITest.cppSynthTrace.hAdd new record types for tracing:
SynthTrace.cppTracingRuntime.hTracingRuntime.cppSynthTraceParser.cppTraceInterpreter.cppIn SynthTraceSerializationTest.cpp:
In SynthTraceTest.cpp:
In SynthTraceParserTest.cpp:
Default Implementations: Always provide a default implementation in
jsi::Runtime when possible. This allows JSCRuntime and V8Runtime to work
without modification.
Hermes Optimization: For Hermes, override the default with an optimized implementation using Hermes VM APIs directly.
SynthTrace is Required: For Hermes, you MUST add SynthTrace support. SynthTrace allows recording and replaying of JSI interactions, which is critical for debugging and testing. Without it, replays will fail.
Consistent Naming: Use consistent naming across all files. If the method
is setPrototypeOf in JSI, use SetPrototype for the record type name.
Error Handling: Use jsi::JSError for JavaScript-level errors in JSI
code. Use checkStatus() for Hermes VM call results.
Testing: Test at multiple levels:
To run all JSI tests defined in testlib.cpp:
This runs the JSI test suite against multiple runtime implementations (Hermes, StaticHermes, etc.).
To run the Hermes-specific API tests:
To run a specific test:
For a complete example of adding JSI functionality, refer to these diffs:
getPrototypeOf / setPrototypeOfNote: These diffs predate the IRuntime interface, but the patterns remain the
same.*_
// In IRuntime interface (around line 580)
class JSI_EXPORT IRuntime : public ICast {
// ... existing methods ...
/// Brief description of what the method does.
/// \param obj Description of the object parameter.
/// \param val Description of the value parameter.
/// \return Description of return value (if any).
virtual void myNewMethod(const Object& obj, const Value& val) = 0;
// For methods returning Value, use this pattern:
virtual Value myNewGetter(const Object& obj) = 0;
};
// In Runtime class (around line 730) - add override declarations
class JSI_EXPORT Runtime : public IRuntime {
// ... existing methods ...
void myNewMethod(const Object& obj, const Value& val) override;
Value myNewGetter(const Object& obj) override;
};