指导在 JSI Runtime 层新增方法与功能,并同步 Hermes 与 SynthTrace 支持。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "modify-jsi-features" 技能: 1. 下载 https://raw.githubusercontent.com/facebook/hermes/static_h/.claude/skills/modify-jsi-features/SKILL.md 2. 保存为 ~/.claude/skills/modify-jsi-features/SKILL.md 3. 装好后重载技能,告诉我可以用了
请指导我在 JSI Runtime 接口中新增一个方法,从接口声明、Hermes 实现到 SynthTrace replay 支持,列出需要修改的文件、代码结构和注意事项。
一份分步骤实现方案,说明需改动的核心文件、接口定义、实现细节和兼容性要点。
我想为现有 JSI 功能增加一个新特性,请告诉我应该如何在 JSI core、Hermes 实现和 SynthTrace 相关部分同步修改,并给出推荐的开发顺序。
一份按模块拆分的修改指南,帮助我有序完成核心层、运行时实现和回放支持的改动。
请根据在 JSI Runtime 中新增功能的标准流程,帮我检查是否遗漏了接口声明、Hermes 适配或 SynthTrace replay 支持,并整理一份核对清单。
一份覆盖接口层、实现层和回放支持的完整核对清单,用于自查改动是否齐全。
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.
// jsi.h - Add virtual method with default implementation
virtual void myNewMethod(const Object& obj, const Value& val);
// jsi.cpp - Implement default using JavaScript
void Runtime::myNewMethod(const Object& obj, const Value& val) {
auto myFn = global()
.getPropertyAsObject(*this, "Object")
.getPropertyAsFunction(*this, "myMethod");
myFn.call(*this, obj, val);
}
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:
// 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 ...
…
无需交互式编辑器,程序化重排、拆分、删除或修订任意 Git 历史提交。