Actually serialize doubles. Yikes.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4463 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
b23b0ca239
commit
e921b4a86a
@ -33,6 +33,7 @@ void tf_packetstream_destroy(tf_packetstream_t* stream)
|
|||||||
{
|
{
|
||||||
tf_free(stream->buffer);
|
tf_free(stream->buffer);
|
||||||
stream->buffer = NULL;
|
stream->buffer = NULL;
|
||||||
|
stream->buffer_size = 0;
|
||||||
}
|
}
|
||||||
if (stream->stream.data)
|
if (stream->stream.data)
|
||||||
{
|
{
|
||||||
|
@ -173,23 +173,16 @@ static bool _serialize_storeInternal(tf_task_t* task, tf_taskstub_t* to, buffer_
|
|||||||
else if (JS_IsNumber(value))
|
else if (JS_IsNumber(value))
|
||||||
{
|
{
|
||||||
int64_t result = 0;
|
int64_t result = 0;
|
||||||
if (JS_ToInt64(context, &result, value) == 0)
|
double float_result = 0.0;
|
||||||
|
if (JS_VALUE_GET_TAG(value) == JS_TAG_INT && JS_ToInt64(context, &result, value) == 0)
|
||||||
{
|
{
|
||||||
_serialize_writeInt32(buffer, kInt64);
|
_serialize_writeInt32(buffer, kInt64);
|
||||||
_serialize_writeInt64(buffer, result);
|
_serialize_writeInt64(buffer, result);
|
||||||
}
|
}
|
||||||
else
|
else if (JS_ToFloat64(context, &float_result, value) == 0)
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to store integer.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (JS_IsNumber(value))
|
|
||||||
{
|
|
||||||
double result = 0.0;
|
|
||||||
if (JS_ToFloat64(context, &result, value) == 0)
|
|
||||||
{
|
{
|
||||||
_serialize_writeInt32(buffer, kNumber);
|
_serialize_writeInt32(buffer, kNumber);
|
||||||
_serialize_writeDouble(buffer, result);
|
_serialize_writeDouble(buffer, float_result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
47
src/tests.c
47
src/tests.c
@ -438,6 +438,52 @@ static void _test_uint8array(const tf_test_options_t* options)
|
|||||||
unlink("out/child.js");
|
unlink("out/child.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _test_float(const tf_test_options_t* options)
|
||||||
|
{
|
||||||
|
FILE* file = fopen("out/test.js", "w");
|
||||||
|
fprintf(file,
|
||||||
|
"var task = new Task();\n"
|
||||||
|
"task.onExit = function() {\n"
|
||||||
|
" print('child exited');\n"
|
||||||
|
"};\n"
|
||||||
|
"task.activate();\n"
|
||||||
|
"File.readFile('out/child.js').then(function(data) {\n"
|
||||||
|
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
|
||||||
|
" print('get exports');\n"
|
||||||
|
" let test = (await task.getExports()).test;\n"
|
||||||
|
" print('calling export');\n"
|
||||||
|
" let result = await test(1.2);\n"
|
||||||
|
" print(result);\n"
|
||||||
|
" exit(result == 1.2 ? 0 : 1);\n"
|
||||||
|
" });\n"
|
||||||
|
"});");
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
file = fopen("out/child.js", "w");
|
||||||
|
fprintf(file,
|
||||||
|
"print(\"child\");\n"
|
||||||
|
"exports = {\n"
|
||||||
|
" test: function(value) {\n"
|
||||||
|
" print(value);\n"
|
||||||
|
" return value;\n"
|
||||||
|
" }\n"
|
||||||
|
"};\n"
|
||||||
|
"print(\"child ready\");\n"
|
||||||
|
);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
char command[256];
|
||||||
|
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
|
||||||
|
tf_printf("%s\n", command);
|
||||||
|
int result = system(command);
|
||||||
|
(void)result;
|
||||||
|
assert(WIFEXITED(result));
|
||||||
|
assert(WEXITSTATUS(result) == 0);
|
||||||
|
|
||||||
|
unlink("out/test.js");
|
||||||
|
unlink("out/child.js");
|
||||||
|
}
|
||||||
|
|
||||||
static void _test_socket(const tf_test_options_t* options)
|
static void _test_socket(const tf_test_options_t* options)
|
||||||
{
|
{
|
||||||
FILE* file = fopen("out/test.js", "w");
|
FILE* file = fopen("out/test.js", "w");
|
||||||
@ -664,6 +710,7 @@ void tf_tests(const tf_test_options_t* options)
|
|||||||
_tf_test_run(options, "exit", _test_exit);
|
_tf_test_run(options, "exit", _test_exit);
|
||||||
_tf_test_run(options, "icu", _test_icu);
|
_tf_test_run(options, "icu", _test_icu);
|
||||||
_tf_test_run(options, "uint8array", _test_uint8array);
|
_tf_test_run(options, "uint8array", _test_uint8array);
|
||||||
|
_tf_test_run(options, "float", _test_float);
|
||||||
_tf_test_run(options, "socket", _test_socket);
|
_tf_test_run(options, "socket", _test_socket);
|
||||||
_tf_test_run(options, "file", _test_file);
|
_tf_test_run(options, "file", _test_file);
|
||||||
_tf_test_run(options, "sign", _test_sign);
|
_tf_test_run(options, "sign", _test_sign);
|
||||||
|
Loading…
Reference in New Issue
Block a user