Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

[ocf/promises] Fixed OCF crash because of bug from promise patch #798

Merged
merged 3 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/iotivity-constrained
Submodule iotivity-constrained updated from 057b08 to 12f109
4 changes: 2 additions & 2 deletions src/zjs_promise.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ void zjs_make_promise(jerry_value_t obj, zjs_post_promise_func post,

new->then_id = zjs_add_callback_once(ZJS_UNDEFINED,
obj,
handle,
new,
post_promise);

new->catch_id = zjs_add_callback_once(ZJS_UNDEFINED,
obj,
handle,
new,
post_promise);

// Add the "promise" object to the object passed as a property, because the
Expand Down
22 changes: 21 additions & 1 deletion src/zjs_test_promise.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,35 @@
#include "zjs_promise.h"
#include "zjs_util.h"

typedef struct dummy_handle {
uint32_t value;
} dummy_handle_t;

#define TEST_VAL 42

static void post_promise(void* handle)
{
if (handle) {
dummy_handle_t* h = (dummy_handle_t*)handle;
if (h->value != TEST_VAL) {
ERR_PRINT("Handle was not valid!!!\n");
}
zjs_free(h);
}
}

static jerry_value_t create_promise(const jerry_value_t function_obj,
const jerry_value_t this,
const jerry_value_t argv[],
const jerry_length_t argc)
{
dummy_handle_t* handle = zjs_malloc(sizeof(dummy_handle_t));
handle->value = TEST_VAL;

jerry_value_t promise = jerry_create_object();
ZJS_PRINT("Testing promise, object = %u\n", promise);

zjs_make_promise(promise, NULL, NULL);
zjs_make_promise(promise, post_promise, handle);

return promise;
}
Expand Down