objc-js 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Release/nobjc_native.node +0 -0
- package/dist/index.js +14 -2
- package/package.json +1 -1
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LoadLibrary, GetClassObject, ObjcObject, GetPointer, FromPointer, CreateProtocolImplementation } from "./native.js";
|
|
2
|
+
const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
2
3
|
const NATIVE_OBJC_OBJECT = Symbol("nativeObjcObject");
|
|
3
4
|
class NobjcLibrary {
|
|
4
5
|
constructor(library) {
|
|
@@ -24,6 +25,7 @@ function ObjcSelectorToNobjcMethodName(selector) {
|
|
|
24
25
|
}
|
|
25
26
|
class NobjcObject {
|
|
26
27
|
constructor(object) {
|
|
28
|
+
// Create the proxy handler
|
|
27
29
|
const handler = {
|
|
28
30
|
has(target, p) {
|
|
29
31
|
// Return true for the special Symbol to enable unwrapping
|
|
@@ -54,7 +56,12 @@ class NobjcObject {
|
|
|
54
56
|
}
|
|
55
57
|
// handle toString separately
|
|
56
58
|
if (methodName === "toString") {
|
|
57
|
-
|
|
59
|
+
// if the receiver has a UTF8String method, use it to get the string representation
|
|
60
|
+
if ("UTF8String" in receiver) {
|
|
61
|
+
return () => String(object.$msgSend("UTF8String"));
|
|
62
|
+
}
|
|
63
|
+
// Otherwise, use the description method
|
|
64
|
+
return () => String(wrapObjCObjectIfNeeded(object.$msgSend("description")));
|
|
58
65
|
}
|
|
59
66
|
// handle other built-in Object.prototype properties
|
|
60
67
|
const builtInProps = [
|
|
@@ -79,7 +86,12 @@ class NobjcObject {
|
|
|
79
86
|
return NobjcMethod(object, methodName);
|
|
80
87
|
}
|
|
81
88
|
};
|
|
82
|
-
|
|
89
|
+
// Create the proxy
|
|
90
|
+
const proxy = new Proxy(object, handler);
|
|
91
|
+
// This is used to override the default inspect behavior for the object. (console.log)
|
|
92
|
+
object[customInspectSymbol] = () => proxy.toString();
|
|
93
|
+
// Return the proxy
|
|
94
|
+
return proxy;
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
function unwrapArg(arg) {
|
package/package.json
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"format": "prettier --write \"**/*.{ts,js,json,md}\"",
|
|
37
37
|
"preinstall-disabled": "npm run build-scripts && npm run make-clangd-config"
|
|
38
38
|
},
|
|
39
|
-
"version": "0.0.
|
|
39
|
+
"version": "0.0.8",
|
|
40
40
|
"description": "Objective-C bridge for Node.js",
|
|
41
41
|
"main": "dist/index.js",
|
|
42
42
|
"devDependencies": {
|