Skip to content

Commit 8860718

Browse files
author
Gabriel Schulhof
committed
prefix with file://
1 parent 96caf11 commit 8860718

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/node_api.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,12 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
577577
modobj->Get(context, node_env->filename_string()).ToLocal(&filename_js) &&
578578
filename_js->IsString()) {
579579
node::Utf8Value filename(node_env->isolate(), filename_js); // Cast
580-
module_filename = *filename;
580+
581+
// Turn the absolute path into a URL. Currently the absolute path is always
582+
// a file system path.
583+
// TODO(gabrielschulhof): Pass the `filename` through unchanged if/when we
584+
// receive it as a URL already.
585+
module_filename = std::string("file://") + (*filename);
581586
}
582587

583588
// Create a new napi_env for this specific module.

test/node-api/test_general/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const filename = require.resolve(`./build/${common.buildType}/test_general`);
55
const test_general = require(filename);
66
const assert = require('assert');
77

8-
assert.strictEqual(test_general.filename, filename);
8+
// TODO(gabrielschulhof): This test may need updating if/when the filename
9+
// becomes a full-fledged URL.
10+
assert.strictEqual(test_general.filename, `file://${filename}`);
911

1012
const [ major, minor, patch, release ] = test_general.testGetNodeVersion();
1113
assert.strictEqual(process.version.split('-')[0],

test/node-api/test_general/test_general.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ static napi_value GetFilename(napi_env env, napi_callback_info info) {
2525
const char* filename;
2626
napi_value result;
2727

28-
NAPI_CALL(env, node_api_get_module_file_name(env, &filename));
29-
NAPI_CALL(env,
28+
NODE_API_CALL(env, node_api_get_module_file_name(env, &filename));
29+
NODE_API_CALL(env,
3030
napi_create_string_utf8(env, filename, NAPI_AUTO_LENGTH, &result));
3131

3232
return result;

0 commit comments

Comments
 (0)