Skip to content
Closed
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
10 changes: 6 additions & 4 deletions cmake/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ int main(int argc, char *argv[]) {
initWithApplicationPath:[NSBundle mainBundle].bundlePath];
TNSRuntimeInspector.logsToSystemConsole = YES;

#ifndef NDEBUG
enableDebugging(argc, argv);
#endif
#ifndef NDEBUG
enableDebugging(argc, argv);
#endif

[runtime executeModule:@"./"];
CFRunLoopPerformBlock(CFRunLoopGetCurrent(), kCFRunLoopCommonModes,
^{ [runtime executeModule:@"./"]; });
CFRunLoopRun();

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/NativeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ set(JSFILES
require.js
__extends.js
inlineFunctions.js
systemjs.js
)

add_definitions(
Expand Down
3 changes: 2 additions & 1 deletion src/NativeScript/GlobalObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static EncodedJSValue JSC_HOST_CALL collectGarbage(ExecState* execState) {

this->_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
this->setConsoleClient(this->_inspectorController->consoleClient());
this->putDirect(vm, vm.propertyNames->global, this, DontEnum | ReadOnly | DontDelete);
this->putDirect(vm, vm.propertyNames->global, globalExec->globalThisValue(), DontEnum | ReadOnly | DontDelete);

this->_objCMethodCallStructure.set(vm, this, ObjCMethodCall::createStructure(vm, this, this->functionPrototype()));
this->_objCConstructorCallStructure.set(vm, this, ObjCConstructorCall::createStructure(vm, this, this->functionPrototype()));
Expand Down Expand Up @@ -324,5 +324,6 @@ static EncodedJSValue JSC_HOST_CALL collectGarbage(ExecState* execState) {
JSLockHolder lock(globalObject->vm());
task->run(const_cast<JSGlobalObject*>(globalObject)->globalExec());
});
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
}
58 changes: 5 additions & 53 deletions src/NativeScript/TNSRuntime.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "require.h"
#include "inlineFunctions.h"
#include "systemjs.h"
#import "TNSRuntime.h"
#import "TNSRuntime+Private.h"
#include "JSErrors.h"
Expand Down Expand Up @@ -47,6 +48,9 @@ - (instancetype)initWithApplicationPath:(NSString*)applicationPath {

// HACK: Temporary workaround to add inline functions to global object. Remove when they are added the proper way.
evaluate(self->_globalObject->globalExec(), makeSource(WTF::String(inlineFunctions_js, inlineFunctions_js_len)));

// Evaluate SystemJS as script
evaluate(self->_globalObject->globalExec(), makeSource(WTF::String(systemjs_js, systemjs_js_len), WTF::ASCIILiteral("systemjs.js")));
}

return self;
Expand All @@ -56,63 +60,11 @@ - (JSGlobalContextRef)globalContext {
return toGlobalRef(self->_globalObject->globalExec());
}

static JSC_HOST_CALL EncodedJSValue createModuleFunction(ExecState* execState) {
JSString* moduleBody = jsString(execState, execState->argument(0).toWTFString(execState));
WTF::String moduleUrl = execState->argument(1).toString(execState)->value(execState);
JSString* moduleName = execState->argument(2).toString(execState);

MarkedArgumentBuffer requireArgs;
requireArgs.append(jsString(execState, WTF::ASCIILiteral("require")));
requireArgs.append(jsString(execState, WTF::ASCIILiteral("module")));
requireArgs.append(jsString(execState, WTF::ASCIILiteral("exports")));
requireArgs.append(jsString(execState, WTF::ASCIILiteral("__dirname")));
requireArgs.append(jsString(execState, WTF::ASCIILiteral("__filename")));
requireArgs.append(moduleBody);

JSFunction* moduleFunction = jsCast<JSFunction*>(constructFunction(execState, execState->lexicalGlobalObject(), requireArgs, moduleName->toIdentifier(execState), moduleUrl, WTF::TextPosition()));
if (execState->hadException()) {
return JSValue::encode(jsUndefined());
}
SourceProvider* sourceProvider = moduleFunction->sourceCode()->provider();

TNSRuntime* runtime = static_cast<TNSRuntime*>(WTF::wtfThreadData().m_apiData);
runtime->_sourceProviders.append(sourceProvider);

return JSValue::encode(moduleFunction);
}

- (void)executeModule:(NSString*)entryPointModuleIdentifier {
JSLockHolder lock(*self->_vm);

JSValue exception;
#ifdef DEBUG
SourceCode sourceCode = makeSource(WTF::String(require_js, require_js_len), WTF::ASCIILiteral("require.js"));
#else
SourceCode sourceCode = makeSource(WTF::String(require_js, require_js_len));
#endif
JSValue requireFactory = evaluate(self->_globalObject->globalExec(), sourceCode, JSValue(), &exception);
if (exception) {
reportFatalErrorBeforeShutdown(self->_globalObject->globalExec(), exception);
return;
}

MarkedArgumentBuffer requireFactoryArgs;
requireFactoryArgs.append(jsString(self->_vm.get(), WTF::String(self->_applicationPath)));
requireFactoryArgs.append(JSFunction::create(*self->_vm, self->_globalObject.get(), 2, WTF::emptyString(), createModuleFunction));
CallData requireFactoryCallData;
CallType requireFactoryCallType = requireFactory.asCell()->methodTable()->getCallData(requireFactory.asCell(), requireFactoryCallData);
JSValue require = call(self->_globalObject->globalExec(), requireFactory.asCell(), requireFactoryCallType, requireFactoryCallData, jsNull(), requireFactoryArgs, &exception);
if (exception) {
reportFatalErrorBeforeShutdown(self->_globalObject->globalExec(), exception);
return;
}

MarkedArgumentBuffer requireArgs;
requireArgs.append(jsString(self->_vm.get(), entryPointModuleIdentifier));

CallData requireCallData;
CallType requireCallType = require.asCell()->methodTable()->getCallData(require.asCell(), requireCallData);
call(self->_globalObject->globalExec(), require.asCell(), requireCallType, requireCallData, jsNull(), requireArgs, &exception);
evaluate(self->_globalObject->globalExec(), makeSource(WTF::String("System.import('./bootstrap.js').then(function(m) { UIApplicationMain(0, null, null, null); }, function(e) { console.log('Error:', e); });")), JSValue(), &exception);
if (exception) {
reportFatalErrorBeforeShutdown(self->_globalObject->globalExec(), exception);
}
Expand Down
Loading