diff --git a/binding.gyp b/binding.gyp index 8b2c19d..029006f 100644 --- a/binding.gyp +++ b/binding.gyp @@ -41,6 +41,7 @@ "deps/milsko/src/widget/button.c", "deps/milsko/src/widget/separator.c", "deps/milsko/src/widget/numberentry.c", + "deps/milsko/src/widget/tab.c", "deps/milsko/src/widget/subwindow.c", "deps/milsko/src/widget/image.c", "deps/milsko/src/widget/submenu.c", @@ -56,6 +57,7 @@ "deps/milsko/src/widget/combobox.c", "deps/milsko/src/widget/checkbox.c", "deps/milsko/src/widget/entry.c", + "deps/milsko/src/widget/calendar.c", "deps/milsko/src/widget/window.c", "deps/milsko/src/cursor/default.c", "deps/milsko/src/cursor/arrow.c", @@ -97,6 +99,24 @@ "deps/milsko/src/icon/back.c", "deps/milsko/src/icon/computer.c", "deps/milsko/src/color.c", + "deps/milsko/external/stb_truetype.c", + "deps/milsko/external/stb_image.c", + "deps/milsko/external/stb_ds.c", + "deps/milsko/external/libz/src/inflate.c", + "deps/milsko/external/libz/src/compress.c", + "deps/milsko/external/libz/src/deflate.c", + "deps/milsko/external/libz/src/gzread.c", + "deps/milsko/external/libz/src/crc32.c", + "deps/milsko/external/libz/src/infback.c", + "deps/milsko/external/libz/src/zutil.c", + "deps/milsko/external/libz/src/gzlib.c", + "deps/milsko/external/libz/src/inftrees.c", + "deps/milsko/external/libz/src/uncompr.c", + "deps/milsko/external/libz/src/gzwrite.c", + "deps/milsko/external/libz/src/trees.c", + "deps/milsko/external/libz/src/gzclose.c", + "deps/milsko/external/libz/src/inffast.c", + "deps/milsko/external/libz/src/adler32.c", ], "include_dirs": [ "deps/milsko/include", diff --git a/deps/milsko b/deps/milsko index 49294dc..37c3f9c 160000 --- a/deps/milsko +++ b/deps/milsko @@ -1 +1 @@ -Subproject commit 49294dc975ea17a33726069e4d9803ba228e66ff +Subproject commit 37c3f9cbdc32618abb64209232d81dcc4bb432b8 diff --git a/lib/milsko.ts b/lib/milsko.ts index a56b6f4..68bdf23 100644 --- a/lib/milsko.ts +++ b/lib/milsko.ts @@ -1,14 +1,14 @@ // @ts-ignore -import binding from "node-gyp-build"; +import addon from "node-gyp-build"; import { join } from "node:path"; -import { +import type { BaseWidgetConstructor, MwNativeClasses, PixmapConstructor } from "./types"; -export const BaseWidget: BaseWidgetConstructor = binding.BaseWidget; -export const NativeClasses: MwNativeClasses = binding.Classes; -export const Pixmap: PixmapConstructor = binding.Pixmap; +const binding = addon(join(__dirname, "..")); -export default binding(join(__dirname, "..")); +export const BaseWidget: BaseWidgetConstructor = binding.BaseWidget; +export const NativeClasses: MwNativeClasses = binding.NativeClasses; +export const Pixmap: PixmapConstructor = binding.Pixmap; diff --git a/lib/types.ts b/lib/types.ts index 1b84dd9..67e7b88 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -5,7 +5,7 @@ export type MwClass = object & { __brand: "MwClass" }; /** * `BaseWidget` represents the lowest level form of widgets before the native layer. - * This class contains the fundamental native methods shared by all widgets. + * This class contains the native methods shared by all widgets. */ export interface BaseWidget { area: MwRect; @@ -153,6 +153,7 @@ export interface BaseWidgetConstructor { export interface MwNativeClasses { Box: MwClass; Button: MwClass; + Calendar: MwClass; CheckBox: MwClass; Entry: MwClass; Frame: MwClass; @@ -164,6 +165,7 @@ export interface MwNativeClasses { ScrollBar: MwClass; SubMenu: MwClass; SubWindow: MwClass; + Tab: MwClass; Viewport: MwClass; Window: MwClass; ProgressBar: MwClass; @@ -194,13 +196,12 @@ export interface PixmapOptions { } export interface PixmapConstructor { - new (cls: BaseWidget, options?: PixmapOptions): Pixmap; + new (widget: BaseWidget, options?: PixmapOptions): Pixmap; } export interface WidgetOptions { name?: string; parent?: BaseWidget; - children?: BaseWidget[]; x?: number; y?: number; width?: number; diff --git a/lib/widget.ts b/lib/widget.ts index 0257ec9..5b52ee8 100644 --- a/lib/widget.ts +++ b/lib/widget.ts @@ -1,5 +1,5 @@ import { BaseWidget } from "./milsko"; -import { Pixmap } from "./types"; +import type { Pixmap } from "./types"; export class Widget extends BaseWidget { public setX(value: number): this { diff --git a/lib/widgets/box.ts b/lib/widgets/box.ts index f5afa67..6173cfd 100644 --- a/lib/widgets/box.ts +++ b/lib/widgets/box.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class Box extends Widget { constructor(options: WidgetOptions) { @@ -66,4 +66,16 @@ export class Box extends Widget { set inverted(value: boolean) { this.setInteger("Iinverted", +value); } + + public setWaitLayout(value: number): this { + return this.setInteger("IwaitLayout", value); + } + + get waitLayout(): number { + return this.getInteger("IwaitLayout"); + } + + set waitLayout(value: number) { + this.setInteger("IwaitLayout", value); + } } diff --git a/lib/widgets/button.ts b/lib/widgets/button.ts index 8fbe2f6..5cad5f2 100644 --- a/lib/widgets/button.ts +++ b/lib/widgets/button.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions, Pixmap } from "../types"; +import type { WidgetOptions, Pixmap } from "../types"; export class Button extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/calendar.ts b/lib/widgets/calendar.ts new file mode 100644 index 0000000..9fc217c --- /dev/null +++ b/lib/widgets/calendar.ts @@ -0,0 +1,69 @@ +import { NativeClasses } from "../milsko"; +import { Widget } from "../widget"; +import type { WidgetOptions } from "../types"; + +export class Calendar extends Widget { + constructor(options: WidgetOptions) { + super(NativeClasses.Calendar, options); + } + + public setYear(value: number): this { + return this.setInteger("Iyear", value); + } + + get year(): number { + return this.getInteger("Iyear"); + } + + set year(value: number) { + this.setInteger("Iyear", value); + } + + public setMonth(value: number): this { + return this.setInteger("Imonth", value); + } + + get month(): number { + return this.getInteger("Imonth"); + } + + set month(value: number) { + this.setInteger("Imonth", value); + } + + public setDate(value: number): this { + return this.setInteger("Idate", value); + } + + get date(): number { + return this.getInteger("Idate"); + } + + set date(value: number) { + this.setInteger("Idate", value); + } + + public setDay(value: number): this { + return this.setInteger("Iday", value); + } + + get day(): number { + return this.getInteger("Iday"); + } + + set day(value: number) { + this.setInteger("Iday", value); + } + + public setScale(value: number): this { + return this.setInteger("Iscale", value); + } + + get scale(): number { + return this.getInteger("Iscale"); + } + + set scale(value: number) { + this.setInteger("Iscale", value); + } +} diff --git a/lib/widgets/checkbox.ts b/lib/widgets/checkbox.ts index fc61f43..9fd57f6 100644 --- a/lib/widgets/checkbox.ts +++ b/lib/widgets/checkbox.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class CheckBox extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/combobox.ts b/lib/widgets/combobox.ts index 754cc5d..21dd84e 100644 --- a/lib/widgets/combobox.ts +++ b/lib/widgets/combobox.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class ComboBox extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/entry.ts b/lib/widgets/entry.ts index 099883b..9aa6dcb 100644 --- a/lib/widgets/entry.ts +++ b/lib/widgets/entry.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class Entry extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/frame.ts b/lib/widgets/frame.ts index 18baa67..4952532 100644 --- a/lib/widgets/frame.ts +++ b/lib/widgets/frame.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class Frame extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/image.ts b/lib/widgets/image.ts index fb8ad31..38d4926 100644 --- a/lib/widgets/image.ts +++ b/lib/widgets/image.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions, Pixmap } from "../types"; +import type { WidgetOptions, Pixmap } from "../types"; export class Image extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/index.ts b/lib/widgets/index.ts index e844d7e..aa5d031 100644 --- a/lib/widgets/index.ts +++ b/lib/widgets/index.ts @@ -1,5 +1,6 @@ export { Box } from "./box"; export { Button } from "./button"; +export { Calendar } from "./calendar"; export { CheckBox } from "./checkbox"; export { Entry } from "./entry"; export { Frame } from "./frame"; @@ -17,3 +18,4 @@ export { RadioBox } from "./radiobox"; export { ComboBox } from "./combobox"; export { TreeView } from "./treeview"; export { SubWindow } from "./subwindow"; +export { Tab } from "./tab"; diff --git a/lib/widgets/label.ts b/lib/widgets/label.ts index b5c423e..64e89cf 100644 --- a/lib/widgets/label.ts +++ b/lib/widgets/label.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class Label extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/listbox.ts b/lib/widgets/listbox.ts index f629b0f..15e1622 100644 --- a/lib/widgets/listbox.ts +++ b/lib/widgets/listbox.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class ListBox extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/menu.ts b/lib/widgets/menu.ts index 20c58f8..62208c6 100644 --- a/lib/widgets/menu.ts +++ b/lib/widgets/menu.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class Menu extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/numberentry.ts b/lib/widgets/numberentry.ts index d268de9..252c651 100644 --- a/lib/widgets/numberentry.ts +++ b/lib/widgets/numberentry.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class NumberEntry extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/progressbar.ts b/lib/widgets/progressbar.ts index f99ea4e..dbff0de 100644 --- a/lib/widgets/progressbar.ts +++ b/lib/widgets/progressbar.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class ProgressBar extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/radiobox.ts b/lib/widgets/radiobox.ts index be75a2d..1f5b0dc 100644 --- a/lib/widgets/radiobox.ts +++ b/lib/widgets/radiobox.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class RadioBox extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/scrollbar.ts b/lib/widgets/scrollbar.ts index 94bc34b..25fcffa 100644 --- a/lib/widgets/scrollbar.ts +++ b/lib/widgets/scrollbar.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class ScrollBar extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/submenu.ts b/lib/widgets/submenu.ts index ce8c796..f627b36 100644 --- a/lib/widgets/submenu.ts +++ b/lib/widgets/submenu.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class SubMenu extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/subwindow.ts b/lib/widgets/subwindow.ts index 412d1f7..cee9747 100644 --- a/lib/widgets/subwindow.ts +++ b/lib/widgets/subwindow.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions, Pixmap } from "../types"; +import type { WidgetOptions, Pixmap } from "../types"; export class SubWindow extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/tab.ts b/lib/widgets/tab.ts new file mode 100644 index 0000000..d8bad1b --- /dev/null +++ b/lib/widgets/tab.ts @@ -0,0 +1,21 @@ +import { NativeClasses } from "../milsko"; +import { Widget } from "../widget"; +import type { WidgetOptions } from "../types"; + +export class Tab extends Widget { + constructor(options: WidgetOptions) { + super(NativeClasses.Tab, options); + } + + public setValue(value: number): this { + return this.setInteger("Ivalue", value); + } + + get value(): number { + return this.getInteger("Ivalue"); + } + + set value(value: number) { + this.setInteger("Ivalue", value); + } +} diff --git a/lib/widgets/treeview.ts b/lib/widgets/treeview.ts index 9a4ce57..7e3ee6a 100644 --- a/lib/widgets/treeview.ts +++ b/lib/widgets/treeview.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class TreeView extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/viewport.ts b/lib/widgets/viewport.ts index 214edf4..097606b 100644 --- a/lib/widgets/viewport.ts +++ b/lib/widgets/viewport.ts @@ -1,6 +1,6 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { WidgetOptions } from "../types"; +import type { WidgetOptions } from "../types"; export class Viewport extends Widget { constructor(options: WidgetOptions) { diff --git a/lib/widgets/window.ts b/lib/widgets/window.ts index 6da7f00..ccc03df 100644 --- a/lib/widgets/window.ts +++ b/lib/widgets/window.ts @@ -1,7 +1,7 @@ import { NativeClasses } from "../milsko"; import { Widget } from "../widget"; -import { MwSizeHints } from "../structs"; -import { WidgetOptions, Pixmap } from "../types"; +import type { MwSizeHints } from "../structs"; +import type { WidgetOptions, Pixmap } from "../types"; export class Window extends Widget { constructor(options: WidgetOptions) { diff --git a/package.json b/package.json index 91b08fc..b266d65 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "milsko", - "version": "1.0.1", + "version": "1.2", "description": "Lightweight and cross-platform native GUI toolkit", - "upstream": "ea20a31694", + "upstream": "v1.2", "main": "dist/index.js", "scripts": { "install": "node-gyp-build", diff --git a/scripts/bindgen.js b/scripts/bindgen.js index af0f391..0f09096 100644 --- a/scripts/bindgen.js +++ b/scripts/bindgen.js @@ -218,7 +218,7 @@ function scanProperties(root) { widgetOut.write( "import { BaseWidget } from \"./milsko\"\n" + - "import { Pixmap } from \"./types\"\n\n" + + "import type { Pixmap } from \"./types\"\n\n" + "export class Widget extends BaseWidget {\n" ); @@ -287,13 +287,13 @@ function scanWidgets(root) { if (structImports.length) { widgetFile.write( - "import { " + structImports.join(", ") + + "import type { " + structImports.join(", ") + " } from \"../structs\"\n" ); } widgetFile.write( - "import { " + typeImports.join(", ") + + "import type { " + typeImports.join(", ") + " } from \"../types\"\n" ); diff --git a/src/classes.cpp b/src/classes.cpp index 9553c4e..60a1337 100644 --- a/src/classes.cpp +++ b/src/classes.cpp @@ -9,6 +9,7 @@ Napi::Object ClassesInit(Napi::Env env, Napi::Object exports) { classes.Set("Box", NAPI_MWCLASS(env, MwBoxClass)); classes.Set("Button", NAPI_MWCLASS(env, MwButtonClass)); + classes.Set("Calendar", NAPI_MWCLASS(env, MwCalendarClass)); classes.Set("CheckBox", NAPI_MWCLASS(env, MwCheckBoxClass)); classes.Set("Entry", NAPI_MWCLASS(env, MwEntryClass)); classes.Set("Frame", NAPI_MWCLASS(env, MwFrameClass)); @@ -20,6 +21,7 @@ Napi::Object ClassesInit(Napi::Env env, Napi::Object exports) { classes.Set("ScrollBar", NAPI_MWCLASS(env, MwScrollBarClass)); classes.Set("SubMenu", NAPI_MWCLASS(env, MwSubMenuClass)); classes.Set("SubWindow", NAPI_MWCLASS(env, MwSubWindowClass)); + classes.Set("Tab", NAPI_MWCLASS(env, MwTabClass)); classes.Set("Viewport", NAPI_MWCLASS(env, MwViewportClass)); classes.Set("Window", NAPI_MWCLASS(env, MwWindowClass)); classes.Set("ProgressBar", NAPI_MWCLASS(env, MwProgressBarClass)); diff --git a/src/utils.hpp b/src/utils.hpp deleted file mode 100644 index ab35dff..0000000 --- a/src/utils.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#include - diff --git a/src/widget.cpp b/src/widget.cpp index e11d807..30af918 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -18,7 +18,7 @@ Napi::Object MwBaseWidget::Init(Napi::Env env, Napi::Object exports) { InstanceMethod("addTickList", &MwBaseWidget::AddTickList), InstanceMethod("forceRender", &MwBaseWidget::ForceRender), InstanceMethod("reparent", &MwBaseWidget::Reparent), - InstanceMethod("add", &MwBaseWidget::AddChild), + InstanceMethod("addChild", &MwBaseWidget::AddChild), InstanceMethod("destroy", &MwBaseWidget::Destroy), InstanceMethod("getClipboard", &MwBaseWidget::GetClipboard), @@ -52,17 +52,138 @@ Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - handle = MwCreateWidget(MwWindowClass, "window", nullptr, 0, 0, 300, 300); + if (info.Length() < 1 || !info[0].IsExternal()) { + Napi::TypeError::New(env, "Expected a MwClass as first argument") + .ThrowAsJavaScriptException(); + return; + } + + MwClass cls = info[0].As>().Data(); + std::string name = "widget"; // name is unused anyways + MwBaseWidget *parent = nullptr; + int xPos = 0; + int yPos = 0; + unsigned int width = 0; + unsigned int height = 0; + + if (info.Length() > 1 && info[1].IsObject()) { + Napi::Object params = info[1].As(); + + if (params.Has("name")) { + Napi::Value nameParam = params.Get("name"); + + if (nameParam.IsString()) { + name = nameParam.As().Utf8Value(); + } else { + Napi::TypeError::New(env, "The name parameter must be a string") + .ThrowAsJavaScriptException(); + return; + } + } + + if (params.Has("parent")) { + Napi::Value parentParam = params.Get("parent"); + + if (parentParam.IsObject()) { + Napi::Object parentObj = parentParam.As(); + bool isInstance = parentObj.InstanceOf(constructor.Value()); + + if (isInstance) { + parent = Unwrap(parentObj); + } else { + Napi::TypeError::New(env, "The parent parameter is not an instance of a widget") + .ThrowAsJavaScriptException(); + return; + } + } else { + Napi::TypeError::New(env, "The parent parameter must be an instance of a widget") + .ThrowAsJavaScriptException(); + return; + } + } + + if (params.Has("x")) { + Napi::Value xParam = params.Get("x"); + if (xParam.IsNumber()) { + xPos = xParam.As().Int32Value(); + } else { + Napi::TypeError::New(env, "The x parameter must be a number") + .ThrowAsJavaScriptException(); + return; + } + } + + if (params.Has("y")) { + Napi::Value yParam = params.Get("y"); + if (yParam.IsNumber()) { + yPos = yParam.As().Int32Value(); + } else { + Napi::TypeError::New(env, "The y parameter must be a number") + .ThrowAsJavaScriptException(); + return; + } + } + + if (params.Has("width")) { + Napi::Value widthParam = params.Get("width"); + if (widthParam.IsNumber()) { + width = widthParam.As().Uint32Value(); + } else { + Napi::TypeError::New(env, "The width parameter must be a number") + .ThrowAsJavaScriptException(); + return; + } + } + + if (params.Has("height")) { + Napi::Value heightParam = params.Get("height"); + if (heightParam.IsNumber()) { + height = heightParam.As().Uint32Value(); + } else { + Napi::TypeError::New(env, "The height parameter must be a number") + .ThrowAsJavaScriptException(); + return; + } + } + } + + handle = MwCreateWidget( + cls, + name.c_str(), + parent ? parent->handle : nullptr, + xPos, yPos, + width, height + ); + + if (!handle) { + Napi::Error::New(env, "A native exception occured when creating the widget") + .ThrowAsJavaScriptException(); + return; + } + + if (parent) { + parent->children.push_back(this); + this->parent = parent; + } }; MwBaseWidget::~MwBaseWidget() { // call destructors for each children if (children.size() > 0) { - for (const auto &child : children) { - delete child; + for (size_t i = 0; i < children.size(); i++) { + delete children[i]; } } + if (parent) { + for (size_t i = 0; i < parent->children.size(); i++) { + if (parent->children[i] == this) { + parent->children.erase(parent->children.begin() + i); + break; + } + } + } + if (handle) MwDestroyWidget(handle); }; @@ -249,26 +370,24 @@ Napi::Value MwBaseWidget::Reparent(const Napi::CallbackInfo &info) { Napi::Value MwBaseWidget::AddChild(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); - if (info.Length() < 1 || !info[0].IsArray()) { - Napi::TypeError::New(env, "Expected an instance of a widget class as argument") + if (info.Length() < 1) { + Napi::TypeError::New(env, "Expected at least one instance of a widget class as argument") .ThrowAsJavaScriptException(); return env.Undefined(); } - Napi::Array widgets = info[0].As(); - - for (uint32_t i = 0; i < widgets.Length(); i++) { - const Napi::Value value = widgets.Get(i); + for (size_t i = 0; i < info.Length(); i++) { + const Napi::Value value = info[i]; if (!value.IsObject()) { Napi::TypeError::New(env, - "Expected argument " + std::to_string(i) + "to be instance of a widget" + "Expected argument " + std::to_string(i) + "to be an instance of a widget" ) .ThrowAsJavaScriptException(); return env.Null(); } - const Napi::Object wrapped = widgets.As(); + const Napi::Object wrapped = value.As(); const bool isInstance = wrapped.InstanceOf(constructor.Value()); if (isInstance) {