Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/scripting/EngineScriptConversions.cpp
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
u32 length = (u32)(val.m_W * val.m_H); | u32 length = (u32)(val.m_W * val.m_H); | ||||
u32 nbytes = (u32)(length * sizeof(u8)); | u32 nbytes = (u32)(length * sizeof(u8)); | ||||
JS::RootedObject objArr(cx, JS_NewUint8Array(cx, length)); | JS::RootedObject objArr(cx, JS_NewUint8Array(cx, length)); | ||||
// Copy the array data and then remove the no-GC check to allow further changes to the JS data | // Copy the array data and then remove the no-GC check to allow further changes to the JS data | ||||
{ | { | ||||
JS::AutoCheckCannotGC nogc; | JS::AutoCheckCannotGC nogc; | ||||
memcpy((void*)JS_GetUint8ArrayData(objArr, nogc), val.m_Data, nbytes); | bool shared; | ||||
memcpy((void*)JS_GetUint8ArrayData(objArr, &shared, nogc), val.m_Data, nbytes); | |||||
} | } | ||||
JS::RootedValue data(cx, JS::ObjectValue(*objArr)); | JS::RootedValue data(cx, JS::ObjectValue(*objArr)); | ||||
JS::RootedValue w(cx); | JS::RootedValue w(cx); | ||||
JS::RootedValue h(cx); | JS::RootedValue h(cx); | ||||
ScriptInterface::ToJSVal(cx, &w, val.m_W); | ScriptInterface::ToJSVal(cx, &w, val.m_W); | ||||
ScriptInterface::ToJSVal(cx, &h, val.m_H); | ScriptInterface::ToJSVal(cx, &h, val.m_H); | ||||
Show All 9 Lines | |||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
u32 length = (u32)(val.m_W * val.m_H); | u32 length = (u32)(val.m_W * val.m_H); | ||||
u32 nbytes = (u32)(length * sizeof(u16)); | u32 nbytes = (u32)(length * sizeof(u16)); | ||||
JS::RootedObject objArr(cx, JS_NewUint16Array(cx, length)); | JS::RootedObject objArr(cx, JS_NewUint16Array(cx, length)); | ||||
// Copy the array data and then remove the no-GC check to allow further changes to the JS data | // Copy the array data and then remove the no-GC check to allow further changes to the JS data | ||||
{ | { | ||||
JS::AutoCheckCannotGC nogc; | JS::AutoCheckCannotGC nogc; | ||||
memcpy((void*)JS_GetUint16ArrayData(objArr, nogc), val.m_Data, nbytes); | bool shared; | ||||
memcpy((void*)JS_GetUint16ArrayData(objArr, &shared, nogc), val.m_Data, nbytes); | |||||
} | } | ||||
JS::RootedValue data(cx, JS::ObjectValue(*objArr)); | JS::RootedValue data(cx, JS::ObjectValue(*objArr)); | ||||
JS::RootedValue w(cx); | JS::RootedValue w(cx); | ||||
JS::RootedValue h(cx); | JS::RootedValue h(cx); | ||||
ScriptInterface::ToJSVal(cx, &w, val.m_W); | ScriptInterface::ToJSVal(cx, &w, val.m_W); | ||||
ScriptInterface::ToJSVal(cx, &h, val.m_H); | ScriptInterface::ToJSVal(cx, &h, val.m_H); | ||||
JS::RootedObject obj(cx, JS_NewPlainObject(cx)); | JS::RootedObject obj(cx, JS_NewPlainObject(cx)); | ||||
JS_SetProperty(cx, obj, "width", w); | JS_SetProperty(cx, obj, "width", w); | ||||
JS_SetProperty(cx, obj, "height", h); | JS_SetProperty(cx, obj, "height", h); | ||||
JS_SetProperty(cx, obj, "data", data); | JS_SetProperty(cx, obj, "data", data); | ||||
ret.setObject(*obj); | ret.setObject(*obj); | ||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<TNSpline>(JSContext* cx, JS::HandleValue v, TNSpline& out) | template<> bool ScriptInterface::FromJSVal<TNSpline>(JSContext* cx, JS::HandleValue v, TNSpline& out) | ||||
{ | { | ||||
if (!v.isObject()) | if (!v.isObject()) | ||||
FAIL("Argument must be an object"); | FAIL("Argument must be an object"); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedObject obj(cx, &v.toObject()); | JS::RootedObject obj(cx, &v.toObject()); | ||||
if (!JS_IsArrayObject(cx, obj)) | bool realArray; | ||||
if (!JS_IsArrayObject(cx, obj, &realArray)) | |||||
FAIL("Argument must be an array"); | FAIL("Argument must be an array"); | ||||
u32 numberOfNodes = 0; | u32 numberOfNodes = 0; | ||||
if (!JS_GetArrayLength(cx, obj, &numberOfNodes)) | if (!JS_GetArrayLength(cx, obj, &numberOfNodes)) | ||||
FAIL("Failed to get array length"); | FAIL("Failed to get array length"); | ||||
for (u32 i = 0; i < numberOfNodes; ++i) | for (u32 i = 0; i < numberOfNodes; ++i) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator