forked from cory/tildefriends
require -> import
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3904 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
25
src/task.c
25
src/task.c
@ -1044,7 +1044,7 @@ JSValue _tf_task_require(JSContext* context, JSValueConst this_val, int argc, JS
|
||||
};
|
||||
task->_scriptExports = export;
|
||||
const char* source = _task_loadFile(path);
|
||||
printf("Requiring script %s\n", path);
|
||||
printf("Requiring script %sn", path);
|
||||
if (source)
|
||||
{
|
||||
JSValue global = JS_GetGlobalObject(task->_context);
|
||||
@ -1408,17 +1408,26 @@ JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name,
|
||||
{
|
||||
tf_task_t* task = opaque;
|
||||
JSValue source_value = JS_GetPropertyStr(context, task->_loadedFiles, module_name);
|
||||
|
||||
char* source = NULL;
|
||||
size_t length = 0;
|
||||
uint8_t* array = tf_util_try_get_array_buffer(context, &length, source_value);
|
||||
if (array)
|
||||
|
||||
if (!JS_IsUndefined(source_value))
|
||||
{
|
||||
source = tf_malloc(length + 1);
|
||||
memcpy(source, array, length);
|
||||
source[length] = '\0';
|
||||
uint8_t* array = tf_util_try_get_array_buffer(context, &length, source_value);
|
||||
if (array)
|
||||
{
|
||||
source = tf_malloc(length + 1);
|
||||
memcpy(source, array, length);
|
||||
source[length] = '\0';
|
||||
}
|
||||
JS_FreeValue(context, source_value);
|
||||
}
|
||||
|
||||
if (!source && task->_trusted)
|
||||
{
|
||||
source = (char*)_task_loadFile(module_name);
|
||||
length = source ? strlen(source) : 0;
|
||||
}
|
||||
JS_FreeValue(context, source_value);
|
||||
|
||||
if (!source)
|
||||
{
|
||||
|
Reference in New Issue
Block a user