1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 07:43:50 +00:00

1. Unified how JS modules can be integrated, by creating an ILibDuktape_Polyfills_JS_Init() method.

2. Updated behavior so when modules are queried, local filesystem takes precedence on search results
3. Updated 'promise' integration to use the new method above
4. Added 'win-registry' integration on windows, so it can be used by agentcore.c
This commit is contained in:
Bryan Roe
2019-01-28 15:56:41 -08:00
parent f38ec1df08
commit 61de975f3a
4 changed files with 37 additions and 222 deletions

View File

@@ -136,7 +136,6 @@ int ILibDuktape_ModSearch_AddModule(duk_context *ctx, char *id, char *module, in
}
duk_pop(ctx); // ...
//if (ILibHashtable_Get(table, NULL, id, idLen) != NULL || ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, idLen) != NULL) { return 1; }
char *newModule = (char*)ILibDuktape_Memory_Alloc(ctx, moduleLen+1);
memcpy_s(newModule, moduleLen + 1, module, moduleLen);
newModule[moduleLen] = 0;
@@ -194,22 +193,10 @@ duk_ret_t mod_Search_Files(duk_context *ctx, char* id)
duk_push_lstring(ctx, data, dataLen);
free(data);
return 1;
//if (duk_peval_string(ctx, data) == 0)
//{
// duk_put_prop_string(ctx, 3, "exports");
// return 0;
//}
//else
//{
// snprintf(fileName, sizeof(fileName), "Module: %s (ERROR)", id);
// duk_push_string(ctx, fileName);
// duk_throw(ctx);
// return DUK_RET_ERROR;
//}
}
else
{
return(ILibDuktape_Error(ctx, "Module: %s (NOT FOUND)", id));
return(0);
}
}
void ILibDuktape_ModSearch_AddHandler_AlsoIncludeJS(duk_context *ctx, char *js, size_t jsLen)
@@ -245,7 +232,7 @@ duk_ret_t mod_Search(duk_context *ctx)
duk_get_prop_string(ctx, -1, "ModSearchTable");
table = (ILibHashtable)duk_to_pointer(ctx, -1);
// First check if there is a JS override
// First check if there is a JS Object override
j = ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleObject, id, (int)idLen);
if (j != NULL)
{
@@ -254,9 +241,18 @@ duk_ret_t mod_Search(duk_context *ctx)
return(0);
}
// Check if there is a native handler
func = (ILibDuktape_ModSearch_PUSH_Object)ILibHashtable_Get(table, NULL, id, (int)idLen);
if (func == NULL)
{
// then check the local filesystem, becuase if present, those should take precedence
if(mod_Search_Files(ctx, id) == 1)
{
return(1);
}
// Next check if a handler was added via ILibDuktape_ModSearch_AddModule()
if ((module = (char*)ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, (int)idLen)) != NULL)
{
duk_push_string(ctx, module);
@@ -264,10 +260,12 @@ duk_ret_t mod_Search(duk_context *ctx)
}
else if (mDS == NULL)
{
return mod_Search_Files(ctx, id);
// If No database, then nothing more we can do
return(ILibDuktape_Error(ctx, "Module: %s (NOT FOUND)", id));
}
else
{
// Next Check the database
char key[255];
int keyLen;
char *value;
@@ -284,7 +282,8 @@ duk_ret_t mod_Search(duk_context *ctx)
}
else
{
return mod_Search_Files(ctx, id);
// Not in database, then nothing more we can do
return(ILibDuktape_Error(ctx, "Module: %s (NOT FOUND)", id));
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -22,5 +22,6 @@ limitations under the License.
extern int g_displayStreamPipeMessages;
extern int g_displayFinalizerMessages;
void ILibDuktape_Polyfills_Init(duk_context *ctx);
void ILibDuktape_Polyfills_JS_Init(duk_context *ctx);
#endif

View File

@@ -1885,6 +1885,8 @@ duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx3(duk_conte
ILibLifeTime_Add(ILibGetBaseTimer(Duktape_GetChain(ctx)), timeoutKey, executionTimeout, ILibDuktape_ScriptContainer_ExecTimeout, NULL);
}
ILibDuktape_Polyfills_JS_Init(ctx);
return ctx;
}