Skip to content

Commit

Permalink
fix: replace calls to JS_GetOpaque3
Browse files Browse the repository at this point in the history
This function does not exist in upstream quickjs, but was added in the copy inside lv_binding_js.
Replace it with one of the existing alternatives.
  • Loading branch information
jspngh committed May 30, 2024
1 parent 94f49d7 commit 25f835d
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/render/native/components/arc/arc_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WRAPPED_JS_CLOSE_COMPONENT(Arc, "Arc")

static JSValue NativeCompSetRange(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, ArcClassID);
int32_t min;
int32_t max;
JSValue min_value = JS_GetPropertyUint32(ctx, argv[0], 0);
Expand All @@ -39,7 +39,7 @@ static JSValue NativeCompSetRange(JSContext *ctx, JSValueConst this_val, int arg

static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, ArcClassID);
int32_t value;
JS_ToInt32(ctx, &value, argv[0]);

Expand All @@ -51,7 +51,7 @@ static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int arg

static JSValue NativeCompSetArcImage(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && (JS_IsObject(argv[0]) || JS_IsNull(argv[0])) && JS_IsNumber(argv[1])) {
COMP_REF* s = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* s = (COMP_REF*)JS_GetOpaque(this_val, ArcClassID);
size_t size;
int32_t type;
int32_t image_bytelength = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/render/native/components/calendar/calendar_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WRAPPED_JS_CLOSE_COMPONENT(Calendar, "Calendar")

static JSValue NativeCompSetHightLights(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, CalendarClassID);

int32_t len;
int32_t num = 0;
Expand Down Expand Up @@ -58,7 +58,7 @@ static JSValue NativeCompSetHightLights(JSContext *ctx, JSValueConst this_val, i

static JSValue NativeCompSetToday (JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0]) && JS_IsNumber(argv[1]) && JS_IsNumber(argv[2])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, CalendarClassID);

int32_t year;
int32_t month;
Expand All @@ -74,7 +74,7 @@ static JSValue NativeCompSetToday (JSContext *ctx, JSValueConst this_val, int ar

static JSValue NativeCompSetShownMonth (JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0]) && JS_IsNumber(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, CalendarClassID);

int32_t year;
int32_t month;
Expand Down
79 changes: 42 additions & 37 deletions src/render/native/components/component.hpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/render/native/components/dropdownlist/dropdownlist_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WRAPPED_JS_CLOSE_COMPONENT(Dropdownlist, "Dropdownlist")

static JSValue NativeCompSetItems(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
std::vector<std::string> items;

int32_t item_len;
Expand Down Expand Up @@ -43,7 +43,7 @@ static JSValue NativeCompSetItems(JSContext *ctx, JSValueConst this_val, int arg

static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
int32_t index;
JS_ToInt32(ctx, &index, argv[0]);

Expand All @@ -55,7 +55,7 @@ static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int arg

static JSValue NativeCompSeText(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsString(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
size_t len;
const char* str = JS_ToCStringLen(ctx, &len, argv[0]);
std::string s = str;
Expand All @@ -70,7 +70,7 @@ static JSValue NativeCompSeText(JSContext *ctx, JSValueConst this_val, int argc,

static JSValue NativeCompSetDir(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
int32_t dir;
JS_ToInt32(ctx, &dir, argv[0]);

Expand All @@ -82,7 +82,7 @@ static JSValue NativeCompSetDir(JSContext *ctx, JSValueConst this_val, int argc,

static JSValue NativeCompSetArrowDir(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
int32_t dir;
JS_ToInt32(ctx, &dir, argv[0]);

Expand All @@ -94,7 +94,7 @@ static JSValue NativeCompSetArrowDir(JSContext *ctx, JSValueConst this_val, int

static JSValue NativeCompSetHighLightSelect(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsBool(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
bool payload = JS_ToBool(ctx, argv[0]);

((Dropdownlist*)(ref->comp))->setHighLightSelect(payload);
Expand Down
3 changes: 2 additions & 1 deletion src/render/native/components/keyboard/keyboard_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ WRAPPED_JS_CLOSE_COMPONENT(Keyboard, "Keyboard")

static JSValue NativeCompSetTextarea(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsObject(argv[0])) {
COMP_REF* child = (COMP_REF*)JS_GetOpaque3(argv[0]);
JSClassID _class_id;
COMP_REF* child = (COMP_REF*)JS_GetAnyOpaque(argv[0], &_class_id);
COMP_REF* parent = (COMP_REF*)JS_GetOpaque(this_val, KeyboardClassID);

((Keyboard*)(parent->comp))->setTextarea(static_cast<BasicComponent*>(child->comp));
Expand Down
2 changes: 1 addition & 1 deletion src/render/native/components/line/line_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WRAPPED_JS_CLOSE_COMPONENT(Line, "Line")

static JSValue NativeCompSetPoints(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, LineClassID);

int32_t len;
int32_t num = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/render/native/components/list/list_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ WRAPPED_JS_CLOSE_COMPONENT(List, "List")

static JSValue NativeCompRemoveChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsObject(argv[0])) {
COMP_REF* child = (COMP_REF*)JS_GetOpaque3(argv[0]);
JSClassID _class_id;
COMP_REF* child = (COMP_REF*)JS_GetAnyOpaque(argv[0], &_class_id);
COMP_REF* parent = (COMP_REF*)JS_GetOpaque(this_val, ListClassID);

((List*)(parent->comp))->removeChild((void*)(child->comp));
Expand All @@ -25,7 +26,8 @@ static JSValue NativeCompRemoveChild(JSContext *ctx, JSValueConst this_val, int

static JSValue NativeCompAppendChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsObject(argv[0])) {
COMP_REF* child = (COMP_REF*)JS_GetOpaque3(argv[0]);
JSClassID _class_id;
COMP_REF* child = (COMP_REF*)JS_GetAnyOpaque(argv[0], &_class_id);
COMP_REF* parent = (COMP_REF*)JS_GetOpaque(this_val, ListClassID);

((List*)(parent->comp))->appendChild((void*)(child->comp));
Expand Down
4 changes: 2 additions & 2 deletions src/render/native/components/progressbar/progressbar_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WRAPPED_JS_CLOSE_COMPONENT(ProgressBar, "ProgressBar")

static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0]) && JS_IsBool(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, ProgressBarClassID);
int32_t value;
JS_ToInt32(ctx, &value, argv[0]);
bool use_animation = JS_ToBool(ctx, argv[1]);
Expand All @@ -28,7 +28,7 @@ static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int arg

static JSValue NativeCompSetRange(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0]) && JS_IsNumber(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, ProgressBarClassID);
int32_t start;
JS_ToInt32(ctx, &start, argv[0]);
int32_t end;
Expand Down
6 changes: 3 additions & 3 deletions src/render/native/components/roller/roller_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WRAPPED_JS_CLOSE_COMPONENT(Roller, "Roller")

static JSValue NativeCompSetOptions(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, RollerClassID);
std::vector<std::string> items;

int32_t item_len;
Expand Down Expand Up @@ -45,7 +45,7 @@ static JSValue NativeCompSetOptions(JSContext *ctx, JSValueConst this_val, int a

static JSValue NativeCompSetSelectIndex(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, RollerClassID);
int32_t index;
JS_ToInt32(ctx, &index, argv[0]);

Expand All @@ -57,7 +57,7 @@ static JSValue NativeCompSetSelectIndex(JSContext *ctx, JSValueConst this_val, i

static JSValue NativeCompSetVisibleRowCount(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, RollerClassID);
int32_t count;
JS_ToInt32(ctx, &count, argv[0]);

Expand Down
4 changes: 2 additions & 2 deletions src/render/native/components/slider/slider_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WRAPPED_JS_CLOSE_COMPONENT(Slider, "Slider")

static JSValue NativeCompSetRange(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, SliderClassID);
int32_t min;
int32_t max;
JSValue min_value = JS_GetPropertyUint32(ctx, argv[0], 0);
Expand All @@ -32,7 +32,7 @@ static JSValue NativeCompSetRange(JSContext *ctx, JSValueConst this_val, int arg

static JSValue NativeCompSetValue(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsNumber(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, SliderClassID);
int32_t value;
JS_ToInt32(ctx, &value, argv[0]);

Expand Down
10 changes: 6 additions & 4 deletions src/render/native/components/switch/switch_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ WRAPPED_JS_CLOSE_COMPONENT(Switch, "Switch")

static JSValue NativeCompRemoveChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsObject(argv[0])) {
COMP_REF* child = (COMP_REF*)JS_GetOpaque3(argv[0]);
JSClassID _class_id;
COMP_REF* child = (COMP_REF*)JS_GetAnyOpaque(argv[0], &_class_id);
COMP_REF* parent = (COMP_REF*)JS_GetOpaque(this_val, SwitchClassID);

((Switch*)(parent->comp))->removeChild((void*)(child->comp));
Expand All @@ -26,7 +27,8 @@ static JSValue NativeCompRemoveChild(JSContext *ctx, JSValueConst this_val, int

static JSValue NativeCompAppendChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsObject(argv[0])) {
COMP_REF* child = (COMP_REF*)JS_GetOpaque3(argv[0]);
JSClassID _class_id;
COMP_REF* child = (COMP_REF*)JS_GetAnyOpaque(argv[0], &_class_id);
COMP_REF* parent = (COMP_REF*)JS_GetOpaque(this_val, SwitchClassID);

((Switch*)(parent->comp))->appendChild((void*)(child->comp));
Expand All @@ -37,7 +39,7 @@ static JSValue NativeCompAppendChild(JSContext *ctx, JSValueConst this_val, int

static JSValue NativeCompSetChecked(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsBool(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, SwitchClassID);
bool value;
value = JS_ToBool(ctx, argv[0]);

Expand All @@ -49,7 +51,7 @@ static JSValue NativeCompSetChecked(JSContext *ctx, JSValueConst this_val, int a

static JSValue NativeCompSetDisabled(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsBool(argv[0])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, SwitchClassID);
bool value;
value = JS_ToBool(ctx, argv[0]);

Expand Down
9 changes: 4 additions & 5 deletions src/render/native/components/tabview/tabview_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ WRAPPED_JS_CLOSE_COMPONENT(TabView, "TabView")

static JSValue NativeCompSetTab(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 2 && JS_IsString(argv[0]) && JS_IsObject(argv[1])) {
COMP_REF* ref = (COMP_REF*)JS_GetOpaque3(this_val);

COMP_REF* ref_content;
size_t str_len;
COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, TabViewClassID);

ref_content = (COMP_REF*)JS_GetOpaque3(argv[1]);
JSClassID _class_id;
COMP_REF* ref_content = (COMP_REF*)JS_GetAnyOpaque(argv[1], &_class_id);

size_t str_len;
const char* str_ori = JS_ToCStringLen(ctx, &str_len, argv[0]);
std::string str = str_ori;
str.resize(str_len);
Expand Down
3 changes: 2 additions & 1 deletion src/render/native/core/event/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ static std::map<lv_event_code_t, EventWrapFunc> WrapEventDict {

#define WRAPPED_STOPPROPAGATION \
static JSValue NativeEventStopPropagation(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { \
lv_event_t* ref = static_cast<lv_event_t*>(JS_GetOpaque3(this_val)); \
JSClassID _class_id; \
lv_event_t* ref = static_cast<lv_event_t*>(JS_GetAnyOpaque(this_val, &_class_id)); \
if (ref) { \
ref->stop_bubbling = 1; \
} \
Expand Down

0 comments on commit 25f835d

Please sign in to comment.