Repository navigation
feat(runtime): ns:interop builtin modules, global interop as compat - #527
Draft
edusperoni wants to merge 3 commits into
Draft
edusperoni wants to merge 3 commits into
edusperoni wants to merge 3 commits into
Conversation
ns:interop carries the cross-platform native memory and value API (Pointer, Reference, FunctionReference, sizeof, alloc, free, handleof, stringFromCString, the C primitive types); ns:interop/ios carries adopt, bufferFromData and the Objective-C types, with ns:interop/visionos and ns:interop/macos as aliases canonicalized before every cache, so each spelling yields the same exports object and the same ES module. ns:runtime gains escapeException, setExternalSize and getExternalSize. The global interop becomes a lazy global (interop-global.js) assembled from the three modules through the builtin require: same key set, every member and all twenty types identical to the module exports, still mutable and enumerable. Workers get it through the same global template instead of a second registration. The primitive type objects are created natively on first use, by the module bindings or by native marshalling (GetInteropType), so pointer and C-string results keep their types even when no app code reads interop. inline-functions.js takes the void type from ns:interop when a decorator runs rather than from the global.
…ditions Pointer, Reference<T>, FunctionReference<T>, Type<T>, StructType<T>, Unmanaged<T> and AdoptedPointer are module exports, so declarations can `import type * as interop from "ns:interop"`. bufferFromData takes `NSData & object` against an empty global NSData interface, which merges into @nativescript/types-ios's class when present and accepts any object otherwise.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adoption step 0 of rfcs#58 ("
interopand runtime helpers").interopmoves into builtin modules, and the globalinteropbecomes a compat layer built from them. Android counterpart: NativeScript/android#2074.Modules
ns:interopPointer,Reference,FunctionReference,sizeof,alloc,free,handleof,stringFromCString,types(the C primitives:void,bool,int8…uint64,ulong,slong,float,double)ns:interop/ios(alsons:interop/visionos,ns:interop/macos)adopt,bufferFromData,types(id,class,selector,protocol,unichar,noop)ns:runtime(new members)escapeException,setExternalSize,getExternalSizetypesobjects are frozen, like the otherns:modules.ns:interop/iosbefore any cache lookup, sorequirereturns the same exports object and ESM gets the same module (one namespace object).The global
interopruntime/js/interop-global.js, which requires the three modules through the builtinrequire. Thens:files never refer to it.types) is===its module export.interopproperty is still enumerable.kLazyGlobals), built on first read. No C++ reads it.inline-functions.js(the@ObjCMethod/@ObjCParamdecorators) getsvoidfromns:interopat decorator time, so apps that never touchinteropdon't build these modules.Native changes
StateForslot).GetInteropTypehands them out when marshalling pointer and C-string results, so they have to exist even if no JS ever loadsns:interop.noopstill wins the shared void encoding.interop.typeswere different objects. There's now one set per isolate.Pointer,Reference,FunctionReferenceandUnmanagedalready create their constructors lazily, so native marshalling never depends on the module having loaded.Types
types/ns-interop.d.tsandtypes/ns-interop-ios.d.ts, plus thens:runtimeadditions, all shipped with the runtime and referenced fromtypes/index.d.ts.Pointer,Reference<T>,FunctionReference<T>,Type<T>,StructType<T>,Unmanaged<T>andAdoptedPointerare module exports. That means generated declarations can writeimport type * as interop from "ns:interop"and keep their existinginterop.Pointerreferences unchanged.bufferFromData(data: NSData & object)relies on an empty globalinterface NSData {}.@nativescript/types-iosin the program, it merges into that package'sNSDataclass.interopdeclaration stays in@nativescript/types-ios. Switching it to alias these modules is a follow-up there.Tests
NsInteropTests.js, with a worker fixture and an ESM fixture. It covers:require, staticimportand dynamicimport();===its module export, on the main thread and in a worker.Open points
interop.setExternalSize …/interop.escapeException …, including when called throughns:runtime. They were left as-is because existing tests and docs match on them.interop.initializer/interop.Args(rfcs#56) aren't onmainyet. They'll joinns:interopwhen that lands.