Skip to content

Commit 5422f57

Browse files
committed
Merge pull request #322 from NativeScript/plamen5kov/add_module_id
add id propery to module object
2 parents 143ca4d + d43b28a commit 5422f57

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/jni/Module.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ Local<Object> Module::LoadModule(Isolate *isolate, const string& modulePath)
284284

285285
moduleObj->Set(ConvertToV8String("require"), require);
286286

287+
auto moduleIdProp = ConvertToV8String("id");
288+
const auto readOnlyFlags = static_cast<PropertyAttribute>(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
289+
Maybe<bool> success = moduleObj->DefineOwnProperty(isolate->GetCurrentContext(), moduleIdProp, fileName, readOnlyFlags);
290+
if(success.IsNothing()) {
291+
throw NativeScriptException(string("Couldn't execute method 'DefineOwnProperty' on 'moduleObj' in 'Module::LoadModule'."));
292+
}
293+
287294
auto thiz = Object::New(isolate);
288295
auto extendsName = ConvertToV8String("__extends");
289296
thiz->Set(extendsName, isolate->GetCurrentContext()->Global()->Get(extendsName));

0 commit comments

Comments
 (0)