Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ jobs:
with:
name: NativeScript-dSYMs
path: dist/dSYMs
metadata-generator-tests:
name: Metadata generator tests
runs-on: macos-15
steps:
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
xcode-version: ${{env.XCODE_VERSION}}
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false # disable to prevent leaking credentials to build scripts
- name: LLVM cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ./llvm
key: ${{ hashFiles('download_llvm.sh') }}
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version: "22"
package-manager-cache: false
- name: Build
run: |
./download_llvm.sh
cmake -S metadata-generator -B metadata-generator/build -DCMAKE_BUILD_TYPE=Release -DMETADATA_BINARY_ARCH=arm64 -DCMAKE_OSX_ARCHITECTURES=arm64
cmake --build metadata-generator/build -j$(sysctl -n hw.ncpu) --target swift-symbolgraph-tests
# Swift interop: symbol graph loading, classification, compiler
# verification, thunk and TypeScript snapshots (tsc checks the
# declarations).
- name: Swift interop tests
run: |
npm install --no-save --prefix "$RUNNER_TEMP/tsc" typescript@5.9.3
NS_TSC="$RUNNER_TEMP/tsc/node_modules/.bin/tsc" ./metadata-generator/build/bin/swift-symbolgraph-tests
test:
name: ${{ matrix.name }}
runs-on: macos-15
Expand Down
1 change: 1 addition & 0 deletions NativeScript/runtime/DataWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum class WrapperType {
ExtVector = 1 << 18,
Worker = 1 << 19,
UnmanagedType = 1 << 20,
SwiftObject = 1 << 21,
};

struct V8Args {
Expand Down
6 changes: 6 additions & 0 deletions NativeScript/runtime/IsolateTracked.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class IsolateTracked {
}
}

protected:
// The bound object while it is alive; empty once collected.
v8::Local<v8::Object> TrackedObject(v8::Isolate* isolate) const {
return weakHandle_.Get(isolate);
}

private:
static void Finalizer(const v8::WeakCallbackInfo<IsolateTracked>& data) {
IsolateTracked* self = data.GetParameter();
Expand Down
26 changes: 25 additions & 1 deletion NativeScript/runtime/NsBuiltinModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ModuleInternalCallbacks.h"
#include "Runtime.h"
#include "StructuredSerialization.h"
#include "SwiftInterop.h"
#include "TextEncoding.h"
#include "URLImpl.h"
#include "URLSearchParamsImpl.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ struct Registration {
constexpr Registration kRegistry[] = {
{"ns:module", BuiltinId::kNsModule, NsModuleBinding},
{"ns:runtime", BuiltinId::kNsRuntime, NsRuntimeBinding},
{"ns:swift", BuiltinId::kNsSwift, SwiftInterop::CreateBinding},
{"ns:url", BuiltinId::kNsUrl, NsUrlBinding},
{"ns:util", BuiltinId::kNsUtil, NsUtilBinding},
{"ns:worker_threads", BuiltinId::kNsWorkerThreads, NsWorkerThreadsBinding},
Expand Down Expand Up @@ -178,6 +180,18 @@ bool HasPrefix(const std::string& specifier, const char* prefix) {
return specifier.rfind(prefix, 0) == 0;
}

// `ns:swift/<Module>`: a Swift module's exports (SwiftInterop.h); the module
// name, not the registry, decides whether it exists.
constexpr const char* kSwiftModulePrefix = "ns:swift/";

bool SwiftModuleName(const std::string& specifier, std::string& name) {
if (!HasPrefix(specifier, kSwiftModulePrefix)) {
return false;
}
name = specifier.substr(std::char_traits<char>::length(kSwiftModulePrefix));
return !name.empty();
}

MaybeLocal<Object> NsModuleBinding(Local<Context> context) {
Isolate* isolate = v8::Isolate::GetCurrent();
Local<Object> binding = Object::New(isolate);
Expand Down Expand Up @@ -361,6 +375,10 @@ bool NsBuiltinModules::IsNsScheme(const std::string& specifier) {

bool NsBuiltinModules::IsRegistered(const std::string& specifier,
bool includeInternal) {
std::string swiftModule;
if (SwiftModuleName(specifier, swiftModule)) {
return true;
}
const Registration* registration = Find(specifier);
return registration != nullptr &&
(includeInternal || !registration->internalOnly);
Expand All @@ -372,6 +390,10 @@ std::string NsBuiltinModules::NotFoundMessage(const std::string& specifier) {

MaybeLocal<Object> NsBuiltinModules::GetExports(Local<Context> context,
const std::string& specifier) {
std::string swiftModule;
if (SwiftModuleName(specifier, swiftModule)) {
return SwiftInterop::LoadModule(context, swiftModule);
}
const Registration* registration = Find(specifier);
if (registration == nullptr) {
return MaybeLocal<Object>();
Expand Down Expand Up @@ -413,8 +435,10 @@ MaybeLocal<Module> NsBuiltinModules::GetModule(Local<Context> context,
const std::string& specifier) {
// The module system is the app-facing entry point; the internal tier only
// exists behind the require builtins receive.
std::string swiftModule;
const Registration* registration = Find(specifier);
if (registration == nullptr || registration->internalOnly) {
if (!SwiftModuleName(specifier, swiftModule) &&
(registration == nullptr || registration->internalOnly)) {
return MaybeLocal<Module>();
}

Expand Down
Loading
Loading