Repository navigation
v0.3.0
Engine Lifecycle Safety, Promise/Proxy Support & Native Binding Hardening
Added
- Promise support:
jspp::PromiseandPromiseResolverwith microtask integration on both backends — QuickJS pumps pending jobs on EngineScope exit, V8 at the next engine checkpoint. - Proxy support: the
Proxytype is exposed through the value layer;isArray(),isInstanceOf()and friends keep ECMA semantics through proxy traps. - QuickJS
scriptctool andBytecodeContainer: compile ES modules into bytecode, embed the containers into the executable and evaluate them withevalModule(), including pure-bytecode deployment. - Constructor factory:
.ctor(factory)accepts a callable returningstd::unique_ptr<T>/std::shared_ptr<T>, enabling non-default construction paths for bound classes. - Instance provider:
instanceProvider()exposes a native singleton as a static class; bound member functions borrow the instance on every call. - Custom instance storage:
traits::NativeInstanceFactory<T>customization point withjspp::binding::factory::newNativeInstanceFor()/newNativeInstanceFrom(). - Module loading API:
Engine::loadModule(),evalModule(),evalModuleNamespace()withfile://module names used as cache keys andimport.meta.url. - CMake install/export rule:
jspp::jspptarget, headers andjsppConfig.cmakeforfind_package()consumption. Number::newNumber()overload foruint32_t.
Changed
ReturnValuePolicy::kAutomaticdeduction reworked: values are copied or moved, pointers and references are borrowed (kReference), smart pointers keep their ownership.- const semantics:
kCopy/kMovedrop the source's const qualifier, member property getters unwrap const correctly, borrowed member accesses auto-adjust tokReferenceInternal, and lambdas/free functions are accepted as instance methods. - Enum handling and type traits updated (flags, mixed enum values).
- API naming cleanup:
NativeInstancefactory functions renamed tonewNativeInstanceFor()/newNativeInstanceFrom(),Arguments::runtime()toengine(),clear()toreset()on handles and resolvers, export functions renamed. - Removed
userDefinedConstructor; constructor resolution is centralized in the constructor callbacks.
Fixed
- Engine destruction: fixed use-after-free with tracked handles and trampolines after the engine is gone — post-destruction virtual calls fall back to the base implementation or throw the pure-virtual exception. The ownership transfer now pins the script handle, keeping the script implementation alive while C++ holds the instance.
- Native instance binding: fixed use-after-free with non-native receivers (e.g. Proxy) — receivers are validated through class tags and the class-id registry before unwrapping, and foreign receivers reject with a clean
TypeError. enable_shared_from_this: types deriving it are now constructed throughstd::make_sharedsoshared_from_this()works; combining it withunique_ptrconstruction is rejected at compile time, and unreachable/private bases report diagnostics.- TransientObjectScope: fixed the use-after-free in callback argument wrapping with provenance-based scope tracking.
- Module-exported classes are lazily bound on native-to-JS conversion instead of requiring an explicit registration order.
Local<Value>::kind()resolves object-like kinds (e.g. Proxy) before reportingkObject.std::functionconverter: argument conversion and lifetime handling corrected.- Value modifiers no longer break template matching for callable bindings.
- pImpl-style classes with destructors defined in a single translation unit are exposed as reference-only types instead of failing to instantiate.
- Numeric conversions check for overflow and truncation at the
int64_t/doubleboundary. - QuickJS addon: missing EngineScope added around instance finalization.
Full Changelog: v0.2.1...v0.3.0
v0.3.0(简体中文)
引擎生命周期安全、Promise/Proxy 支持与原生绑定加固
新增
- Promise 支持:
jspp::Promise与PromiseResolver,双后端微任务集成 — QuickJS 在 EngineScope 退出时泵送,V8 在下一个引擎检查点执行。 - Proxy 支持:
Proxy类型接入值层,isArray()、isInstanceOf()等查询穿透 trap 保持 ECMA 语义。 - QuickJS
scriptc工具与BytecodeContainer:将 ES 模块编译为字节码,容器嵌入可执行文件并以evalModule()求值,支持纯字节码部署。 - 构造器工厂:
.ctor(factory)接受返回std::unique_ptr<T>/std::shared_ptr<T>的可调用对象,为绑定类提供非默认构造路径。 - 实例提供器:
instanceProvider()将原生单例暴露为静态类,绑定的成员函数每次调用借用实例。 - 自定义实例存储:
traits::NativeInstanceFactory<T>定制点与jspp::binding::factory::newNativeInstanceFor()/newNativeInstanceFrom()。 - 模块加载 API:
Engine::loadModule()、evalModule()、evalModuleNamespace(),file://模块名兼作缓存键与import.meta.url。 - CMake install/导出规则:
jspp::jspp目标、头文件与jsppConfig.cmake供find_package()消费。 Number::newNumber()新增uint32_t重载。
变更
ReturnValuePolicy::kAutomatic推导重做:值类型拷贝或移动,指针与引用借用(kReference),智能指针保持所有权。- const 语义:
kCopy/kMove去除源对象 const 限定,成员属性 getter 正确解包 const,借用型成员访问自动调整为kReferenceInternal,lambda 与自由函数可用作实例方法。 - 枚举处理与类型 traits 更新(flags、混合枚举值)。
- API 命名清理:
NativeInstance工厂函数更名newNativeInstanceFor()/newNativeInstanceFrom(),Arguments::runtime()更名engine(),句柄与解析器的clear()更名reset(),导出函数统一命名。 - 移除
userDefinedConstructor,构造解析集中到构造回调。
修复
- 引擎销毁:修复引擎销毁后跟踪句柄与跳板的 use-after-free — 销毁后的虚调用回落到基类实现或抛出纯虚异常。所有权移交现以强引用固定脚本对象,C++ 持有期间脚本实现保持存活。
- 原生实例绑定:修复非原生接收者(如 Proxy)的 use-after-free — 解包前经 class tag 与 class-id 注册表校验接收者,外部接收者以
TypeError拒绝。 enable_shared_from_this:派生该基类的类型改经std::make_shared构造,shared_from_this()正常工作;与unique_ptr构造的组合在编译期拒绝,不可达/private 基类给出诊断。- TransientObjectScope:以溯源式作用域跟踪修复回调参数包装中的 use-after-free。
- 模块导出类在 native-to-JS 转换时延迟绑定,不再要求显式注册顺序。
Local<Value>::kind()先解析对象型 kind(如 Proxy)再报告kObject。std::function转换器:参数转换与生命周期处理修正。- 值修饰符不再破坏可调用绑定的模板匹配。
- 析构函数定义在单一编译单元内的 pImpl 风格类改为仅引用方式暴露。
- 数值转换在
int64_t/double边界增加溢出与截断检查。 - QuickJS addon:实例 finalizer 周围补充缺失的 EngineScope。
Full Changelog: v0.2.1...v0.3.0