Skip to content

Commit

Permalink
Solve minor bugs in fail paths for nodejs require.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Feb 18, 2021
1 parent 7e3d58c commit 104afeb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ namespace CSLoader
public static class MetacallEntryPoint
{
private static LoaderBase loader = null;
private static ConsoleLog log = new ConsoleLog();

static MetacallEntryPoint()
{

var log = new ConsoleLog();

log.Info("CSLoader static initialization");

#if NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP1_2
Expand All @@ -45,7 +43,13 @@ public static bool Load(string source)

public static bool Load(string[] files)
{
return loader.LoadFromSourceFunctions(files.Select(x => System.IO.File.ReadAllText(x)).ToArray());
try {
return loader.LoadFromSourceFunctions(files.Select(x => System.IO.File.ReadAllText(x)).ToArray());
} catch (FileNotFoundException ex) {
// TODO: Implement error handling
log.Info(ex.Message);
return false;
}
}

public static ReflectFunction[] GetFunctionsInternal()
Expand Down
5 changes: 5 additions & 0 deletions source/ports/node_port/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,15 @@ mod.prototype.require = function (name) {
/* NodeJS Loader */
js: 'node',
node: 'node',

/* TODO: TypeScript Loader is not supported to run with NodeJS Loader at the same time yet */

/* TypeScript Loader */
/*
ts: 'ts',
jsx: 'ts',
tsx: 'ts',
*/

/* Note: By default js extension uses NodeJS loader instead of JavaScript V8 */
/* Probably in the future we can differenciate between them, but it is not trivial */
Expand Down
6 changes: 6 additions & 0 deletions source/ports/node_port/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ describe('metacall', () => {
});
});

describe('fail', () => {
it('require', () => {
assert.strictEqual(require('./asd.invalid'), undefined);
});
});

describe('load', () => {
it('metacall_load_from_file (py)', () => {
assert.strictEqual(metacall_load_from_file('py', [ 'helloworld.py' ] ), undefined);
Expand Down
1 change: 1 addition & 0 deletions source/tests/metacall_node_port_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ if(OPTION_BUILD_LOADERS_COB)
endif()

add_dependencies(${target}
node_port
node_loader
mock_loader
py_loader
Expand Down

0 comments on commit 104afeb

Please sign in to comment.