Skip to content

Commit e00d413

Browse files
committed
more work on runtime and make it work on deno
1 parent 4d41fc5 commit e00d413

File tree

9 files changed

+43
-11
lines changed

9 files changed

+43
-11
lines changed

examples/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@nativescript/runtime-examples",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "Examples for NativeScript runtime",
6+
"type": "module",
7+
"scripts": {},
8+
"author": "DjDeveloperr <[email protected]>",
9+
"license": "MIT"
10+
}

packages/macos/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/// <reference types="@nativescript/objc-node-api" />
21
/// <reference path="./types/index.d.ts" />
32

3+
import "@nativescript/objc-node-api";
4+
45
export * from "./lib/native.js";

runtime/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.15)
44

55
set(NAME NativeScriptRuntime)
66
set(VERSION 0.1.0)
7+
set(BUNDLE_IDENTIFIER "org.nativescript.hermes-runtime")
78

89
project(${NAME} VERSION ${VERSION} LANGUAGES CXX)
910

@@ -78,7 +79,6 @@ include_directories(
7879
set(RT_SOURCE_FILES
7980
src/Console.cpp
8081
src/Runtime.cpp
81-
src/segappend.cpp
8282
src/Require.cpp
8383
src/Performance.cpp
8484
)
@@ -113,7 +113,7 @@ set_target_properties(
113113
PUBLIC_HEADER "${PUBLIC_HEADERS}"
114114
VERSION ${VERSION}
115115
SOVERSION ${VERSION}
116-
MACOSX_FRAMEWORK_IDENTIFIER org.nativescript.hermes-runtime
116+
MACOSX_FRAMEWORK_IDENTIFIER ${BUNDLE_IDENTIFIER}
117117
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION}
118118
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION}
119119
FRAMEWORK_VERSION ${VERSION}
@@ -122,7 +122,7 @@ set_target_properties(
122122
target_link_options(
123123
NativeScriptRuntime
124124
PRIVATE
125-
-Wl,-F${NS_BRIDGE_PATH},-F${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/hermes.xcframework/${TARGET_PLATFORM_SPEC},-rpath,${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/hermes.xcframework/${TARGET_PLATFORM_SPEC}
125+
-Wl,-F${NS_BRIDGE_PATH},-F${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/hermes.xcframework/${TARGET_PLATFORM_SPEC},-rpath,${NS_BRIDGE_PATH},-rpath,${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/hermes.xcframework/${TARGET_PLATFORM_SPEC}
126126
)
127127

128128
if (TARGET_PLATFORM_MACOS)
@@ -152,6 +152,7 @@ if(TARGET_PLATFORM_MACOS)
152152
charon
153153
src/main.cpp
154154
src/Compiler.cpp
155+
src/segappend.cpp
155156
)
156157

157158
target_link_options(

runtime/mod.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
exports.test = function() {
1+
exports.test = function mod__exports__test() {
2+
console.log(new Error().stack);
23
console.log('mod.js');
34
}

runtime/src/Require.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ std::string Require::resolve(std::string &spec) {
7474
napi_value Require::require(napi_env env, std::string &spec) {
7575
std::string path = resolve(spec);
7676

77+
// std::cout << "================\nrequire: " << path << std::endl;
78+
7779
char *source = nullptr;
7880
size_t size = 0;
7981
FILE *file = fopen(path.c_str(), "r");
@@ -139,7 +141,14 @@ napi_value Require::require(napi_env env, std::string &spec) {
139141

140142
napi_value argv[5] = {exports, require, module, __filename, __dirname};
141143

144+
// std::cout << "napi_call_function(env: " << env << ", global: " << global << ", func: " << func << ", argc: 5, argv: " << argv[0] << ", " << argv[1] << ", " << argv[2] << ", " << argv[3] << ", " << argv[4] << ", result: " << result << std::endl;
145+
146+
std::cout << "require eval: " << path << std::endl;
147+
142148
status = napi_call_function(env, global, func, 5, argv, &result);
149+
150+
std::cout << "require eval done: " << path << std::endl;
151+
143152
if (status != napi_ok) {
144153
const napi_extended_error_info *info;
145154
napi_get_last_error_info(env, &info);

runtime/src/Runtime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include <iostream>
77
#include <CoreFoundation/CFRunLoop.h>
88

9+
// #include <NativeScript/NativeScript.h>
10+
11+
extern "C" {
12+
void objc_bridge_init(napi_env env, const char *metadata_path);
13+
}
14+
915
namespace charon {
1016

1117
class BytecodeBuffer : public facebook::jsi::Buffer {

runtime/src/main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ int main(int argc, char **argv) {
5151

5252
runtime.addEventLoopToRunLoop(true);
5353

54-
int code = runtime.executeJS(argv[2]);
55-
if (code != 0) {
56-
std::cout << "Failed to execute JS" << std::endl;
57-
return code;
58-
}
54+
std::string spec = argv[2];
55+
56+
runtime.evaluateModule(spec);
57+
// if (code != 0) {
58+
// std::cout << "Failed to execute JS" << std::endl;
59+
// return code;
60+
// }
5961

6062
runtime.runRunLoop();
6163

runtime/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const { test } = require("./mod.js");
44

55
test();
66

7+
console.log(new Error().stack);
8+
79
// const timer = NSTimer.scheduledTimerWithTimeIntervalRepeatsBlock(1, true, () => {
810
// console.log("timer");
911
// timer.invalidate();

src/Interop.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ napi_value interop_bufferFromData(napi_env env, napi_callback_info info) {
694694
const napi_property_descriptor properties[] = {
695695
{
696696
.utf8name = "value",
697-
.attributes = napi_enumerable,
697+
.attributes = (napi_property_attributes) (napi_enumerable | napi_writable),
698698
.getter = Reference::get_value,
699699
.setter = Reference::set_value,
700700
.value = nullptr,

0 commit comments

Comments
 (0)