Skip to content
Merged
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
5 changes: 4 additions & 1 deletion NativeScript/runtime/MetadataBuilder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ NamedPropertyHandlerConfiguration config(MetadataBuilder::GlobalPropertyGetter,
const FunctionMeta* funcMeta = static_cast<const FunctionMeta*>(meta);
void* functionPointer =
SymbolLoader::instance().loadFunctionSymbol(meta->topLevelModule(), meta->name());
// Metadata can list functions the running OS or linked binary doesn't export
// (newer SDK, weak-linked or stripped symbol); expose those as undefined so
// `typeof fn === "undefined"` works as feature detection.
if (functionPointer == nullptr) {
Log(@"Unable to load \"%s\" function", meta->name());
tns::Assert(false, isolate);
return v8::Intercepted::kNo;
}

CacheItem<FunctionMeta>* item =
Expand Down
4 changes: 4 additions & 0 deletions TestFixtures/Functions/TNSFunctions.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
CFArrayRef CFArrayCreateWithString(CFStringRef string);

// Declared for the metadata generator but intentionally left undefined, so the
// symbol is listed in metadata yet absent at runtime.
void TNSFunctionMissingAtRuntime(void);
7 changes: 7 additions & 0 deletions TestRunner/app/tests/ApiTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ describe(module.id, function () {
expect(object.hash).toBe(3);
});

it("exposes a C function listed in metadata but missing at runtime as undefined", function () {
expect(typeof TNSFunctionMissingAtRuntime).toBe("undefined");
expect(global.TNSFunctionMissingAtRuntime).toBeUndefined();
expect("TNSFunctionMissingAtRuntime" in global).toBe(false);
expect(function () { TNSFunctionMissingAtRuntime(); }).toThrowError(ReferenceError);
});

it("preserves a lone high surrogate when bridging a JS string to NSString", function () {
// A lone high surrogate (U+D834, range U+D800-U+DBFF) is a valid JS string
// code unit but has no UTF-8 encoding. The old UTF-8 round-trip replaced it
Expand Down
Loading