JResult JObject::Call(JObject& this_, JArgList& arg) { IOTJS_ASSERT(IsFunction()); JRawObjectType* this_obj_p = this_.IsNull() ? NULL : this_.raw_value().v_object; JRawValueType res; JRawValueType* val_args = NULL; uint16_t val_argv = 0; if (arg.GetLength() > 0) { val_argv = arg.GetLength(); val_args = new JRawValueType[val_argv]; for (int i = 0; i < val_argv; ++i) { val_args[i] = arg.Get(i)->raw_value(); } } bool is_ok = jerry_api_call_function(_obj_val.v_object, this_obj_p, &res, val_args, val_argv); if (val_args) { delete [] val_args; } JResultType type = is_ok ? JRESULT_OK : JRESULT_EXCEPTION; return JResult(&res, type); }
void JObjectWrap::set_jholder(JObject& jholder) { IOTJS_ASSERT(_jholder == NULL); IOTJS_ASSERT(jholder.IsObject()); JRawValueType raw_value = jholder.raw_value(); _jholder = new JObject(&raw_value, false); }
void JHandlerInfo::Throw(JObject& ret) { IOTJS_ASSERT(_thrown == false); ret.Ref(); *_ret_val_p = ret.raw_value(); _thrown = true; }
void JObject::SetProperty(const char* name, const JObject& val) { IOTJS_ASSERT(IsObject()); JRawValueType v = val.raw_value(); bool is_ok = jerry_api_set_object_field_value( _obj_val.v_object, reinterpret_cast<const jerry_api_char_t*>(name), &v); IOTJS_ASSERT(is_ok); }
JObjectWrap::JObjectWrap(JObject& jobject) : _jobject(NULL) { IOTJS_ASSERT(jobject.IsObject()); // This wrapper hold pointer to the javascript object but never increase // reference count. JRawValueType raw_value = jobject.raw_value(); _jobject = new JObject(&raw_value, false); // Set native pointer of the object to be this wrapper. // If the object is freed by GC, the wrapper instance should also be freed. _jobject->SetNative((uintptr_t)this, FreeObjectWrap); }
void JHandlerInfo::Return(JObject& ret) { ret.Ref(); *_ret_val_p = ret.raw_value(); }