Skip to content

Commit 1bc80ba

Browse files
committed
Mitigated issue #132
1 parent 8a3e90a commit 1bc80ba

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

source/loaders/node_loader/source/node_loader_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ napi_value node_loader_impl_value_to_napi(loader_impl_node node_impl, napi_env e
11001100
else if (id == TYPE_CLASS)
11011101
{
11021102
/* TODO */
1103-
napi_throw_error(env, NULL, "NodeJS Loader class is not implemented");
1103+
/* napi_throw_error(env, NULL, "NodeJS Loader class is not implemented"); */
11041104

11051105
/*
11061106
klass cls = value_to_class(arg_value);

source/ports/node_port/index.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,22 @@ mod.prototype.require = function (name) {
228228
const index = name.lastIndexOf('.');
229229

230230
if (index !== -1) {
231-
/* If there is extension, load the module depending on the tag */
232-
const extension = name.substr(index + 1);
233-
const tag = tags[extension];
231+
/* If there is extension, load the module depending on the tag */
232+
const extension = name.substr(index + 1);
233+
const tag = tags[extension];
234234

235-
if (tag && tag !== 'node') {
236-
/* Load with MetaCall if we found a tag and it is not NodeJS */
237-
return metacall_require(tag, name);
238-
}
235+
if (tag && tag !== 'node') {
236+
/* Load with MetaCall if we found a tag and it is not NodeJS */
237+
return metacall_require(tag, name);
238+
}
239239
}
240240

241241
try {
242-
return node_require.apply(this, [ name ]);
242+
return node_require.apply(this, [ name ]);
243243
} catch (e) {
244-
if (e.code !== 'MODULE_NOT_FOUND') {
245-
throw e;
246-
}
244+
if (e.code !== 'MODULE_NOT_FOUND') {
245+
throw e;
246+
}
247247
}
248248

249249
/* If there is no extension or the extension is not supported or it is 'node', load it with NodeJS require */

source/ports/node_port/test/index.js

+30-15
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,33 @@ describe('metacall', () => {
123123
assert.strictEqual(asd.mixed_args('a', 3, 4, 3.4, 'NOT IMPLEMENTED'), 65);
124124
});
125125
it('require (py)', () => {
126-
// TODO: Both methods work, should we disable the commented out style to be NodeJS compilant?
127-
// const example = require('example.py');
128-
const example = require('./example.py');
129-
assert.notStrictEqual(example, undefined);
130-
assert.strictEqual(example.multiply(2, 2), 4);
131-
assert.strictEqual(example.divide(4.0, 2.0), 2.0);
132-
assert.strictEqual(example.sum(2, 2), 4);
133-
assert.strictEqual(example.strcat('2', '2'), '22');
134-
assert.deepStrictEqual(example.return_array(), [1, 2, 3]);
135-
assert.deepStrictEqual(example.return_same_array([1, 2, 3]), [1, 2, 3]);
126+
const verify = (example) => {
127+
assert.notStrictEqual(example, undefined);
128+
assert.strictEqual(example.multiply(2, 2), 4);
129+
assert.strictEqual(example.divide(4.0, 2.0), 2.0);
130+
assert.strictEqual(example.sum(2, 2), 4);
131+
assert.strictEqual(example.strcat('2', '2'), '22');
132+
assert.deepStrictEqual(example.return_array(), [1, 2, 3]);
133+
assert.deepStrictEqual(example.return_same_array([1, 2, 3]), [1, 2, 3]);
134+
};
135+
136+
verify(require('./example.py'));
137+
138+
// TODO: Should we enable this format? I think it should work right now but it does not, we must review it
139+
// verify(require('example.py'));
140+
});
141+
it('require (py class)', () => {
142+
const classname = require('./classname.py');
143+
assert.notStrictEqual(classname.function_returns_object_new_local_variable, undefined);
144+
assert.notStrictEqual(classname.return_bound_method_param, undefined);
145+
assert.notStrictEqual(classname.return_object_function, undefined);
146+
assert.notStrictEqual(classname.return_itself, undefined);
147+
assert.notStrictEqual(classname.return_object_bound_method_call, undefined);
148+
assert.notStrictEqual(classname.return_class_function, undefined);
149+
assert.notStrictEqual(classname.return_object_bound_method_new_object, undefined);
150+
151+
// TODO: Implement classes
152+
// assert.notStrictEqual(classname.MyClass, undefined);
136153
});
137154
it('require (py module)', () => {
138155
// This code loads directly a module without extension from Python
@@ -145,11 +162,9 @@ describe('metacall', () => {
145162
const { find_library } = require('ctypes.util');
146163
assert.notStrictEqual(find_library, undefined);
147164

148-
// TODO: This fails because the submodule imports a class, which
149-
// is not yet supported by the NodeJS loader
150-
//const { py_encode_basestring_ascii } = require('json.encoder');
151-
//assert.notStrictEqual(py_encode_basestring_ascii, undefined);
152-
//assert.strictEqual(py_encode_basestring_ascii('asd'), '"asd"');
165+
const { py_encode_basestring_ascii } = require('json.encoder');
166+
assert.notStrictEqual(py_encode_basestring_ascii, undefined);
167+
assert.strictEqual(py_encode_basestring_ascii('asd'), '"asd"');
153168
});
154169
it('require (rb)', () => {
155170
// TODO: Both methods work, should we disable the commented out style to be NodeJS compilant?

0 commit comments

Comments
 (0)