Skip to content

Commit fbaef86

Browse files
committed
🔧
1 parent b8580f2 commit fbaef86

2 files changed

Lines changed: 0 additions & 182 deletions

File tree

packages/webgpu/cpp/jsi/NativeObject.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -432,43 +432,6 @@ class NativeObject : public jsi::NativeState,
432432
return obj.getNativeState<Derived>(runtime);
433433
}
434434

435-
/**
436-
* Box a NativeObject into a HostObject for Worklets serialization.
437-
*
438-
* This is used with registerCustomSerializable to transfer WebGPU objects
439-
* between runtimes. The boxed object is a HostObject (which Worklets can
440-
* serialize), and calling unbox() on it recreates the full NativeObject
441-
* with its prototype.
442-
*
443-
* Usage:
444-
* pack: (value) => { 'worklet'; return RNWebGPU.box(value); }
445-
* unpack: (boxed) => { 'worklet'; return boxed.unbox(); }
446-
*/
447-
static jsi::Value box(jsi::Runtime &runtime, const jsi::Value &value) {
448-
if (!value.isObject()) {
449-
throw jsi::JSError(runtime, "box() requires an object");
450-
}
451-
auto obj = value.getObject(runtime);
452-
if (!obj.hasNativeState(runtime)) {
453-
throw jsi::JSError(runtime, "Object has no native state");
454-
}
455-
auto nativeState = obj.getNativeState(runtime);
456-
auto boxed =
457-
std::make_shared<BoxedWebGPUObject>(nativeState, Derived::CLASS_NAME);
458-
return jsi::Object::createFromHostObject(runtime, boxed);
459-
}
460-
461-
/**
462-
* Check if a value is a WebGPU NativeObject (has the right NativeState)
463-
*/
464-
static bool isNativeObject(jsi::Runtime &runtime, const jsi::Value &value) {
465-
if (!value.isObject()) {
466-
return false;
467-
}
468-
jsi::Object obj = value.getObject(runtime);
469-
return obj.hasNativeState<Derived>(runtime);
470-
}
471-
472435
/**
473436
* Memory pressure for GC hints. Override in derived classes.
474437
*/

packages/webgpu/cpp/rnwgpu/api/RNWebGPU.h

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -34,121 +34,6 @@ class RNWebGPU : public NativeObject<RNWebGPU> {
3434

3535
std::shared_ptr<GPU> getGPU() { return _gpu; }
3636

37-
/**
38-
* Box any WebGPU NativeObject into a HostObject for Worklets serialization.
39-
*
40-
* This function checks if the object has native state and a prototype with
41-
* Symbol.toStringTag (which identifies the WebGPU class name), then creates
42-
* a BoxedWebGPUObject that can be serialized by Worklets.
43-
*
44-
* Usage with registerCustomSerializable:
45-
* pack: (value) => { 'worklet'; return RNWebGPU.box(value); }
46-
* unpack: (boxed) => { 'worklet'; return boxed.unbox(); }
47-
*/
48-
jsi::Value box(jsi::Runtime &runtime, const jsi::Value &thisVal,
49-
const jsi::Value *args, size_t count) {
50-
if (count < 1 || !args[0].isObject()) {
51-
throw jsi::JSError(runtime, "box() requires a WebGPU object argument");
52-
}
53-
54-
auto obj = args[0].getObject(runtime);
55-
56-
// Check if it has native state
57-
if (!obj.hasNativeState(runtime)) {
58-
throw jsi::JSError(runtime, "Object has no native state - not a WebGPU object");
59-
}
60-
61-
// Get the brand name from Symbol.toStringTag on the prototype
62-
auto objectCtor = runtime.global().getPropertyAsObject(runtime, "Object");
63-
auto getPrototypeOf =
64-
objectCtor.getPropertyAsFunction(runtime, "getPrototypeOf");
65-
auto proto = getPrototypeOf.call(runtime, obj);
66-
67-
std::string brand;
68-
if (proto.isObject()) {
69-
auto protoObj = proto.getObject(runtime);
70-
auto symbolCtor = runtime.global().getPropertyAsObject(runtime, "Symbol");
71-
auto toStringTag = symbolCtor.getProperty(runtime, "toStringTag");
72-
if (!toStringTag.isUndefined()) {
73-
// Get the Symbol.toStringTag property value from the prototype
74-
auto getOwnPropertyDescriptor =
75-
objectCtor.getPropertyAsFunction(runtime, "getOwnPropertyDescriptor");
76-
auto desc = getOwnPropertyDescriptor.call(runtime, protoObj, toStringTag);
77-
if (desc.isObject()) {
78-
auto descObj = desc.getObject(runtime);
79-
auto value = descObj.getProperty(runtime, "value");
80-
if (value.isString()) {
81-
brand = value.getString(runtime).utf8(runtime);
82-
}
83-
}
84-
}
85-
}
86-
87-
if (brand.empty()) {
88-
throw jsi::JSError(
89-
runtime, "Cannot determine WebGPU object type - no Symbol.toStringTag found");
90-
}
91-
92-
auto nativeState = obj.getNativeState(runtime);
93-
auto boxed = std::make_shared<BoxedWebGPUObject>(nativeState, brand);
94-
return jsi::Object::createFromHostObject(runtime, boxed);
95-
}
96-
97-
/**
98-
* Check if a value is a boxed WebGPU object (created by box())
99-
*/
100-
jsi::Value isBoxedWebGPUObject(jsi::Runtime &runtime, const jsi::Value &thisVal,
101-
const jsi::Value *args, size_t count) {
102-
if (count < 1 || !args[0].isObject()) {
103-
return jsi::Value(false);
104-
}
105-
auto obj = args[0].getObject(runtime);
106-
if (!obj.isHostObject(runtime)) {
107-
return jsi::Value(false);
108-
}
109-
// Check for __boxedWebGPU marker
110-
auto marker = obj.getProperty(runtime, "__boxedWebGPU");
111-
return jsi::Value(marker.isBool() && marker.getBool());
112-
}
113-
114-
/**
115-
* Check if a value is a WebGPU NativeObject (has native state and WebGPU prototype)
116-
*/
117-
jsi::Value isWebGPUObject(jsi::Runtime &runtime, const jsi::Value &thisVal,
118-
const jsi::Value *args, size_t count) {
119-
if (count < 1 || !args[0].isObject()) {
120-
return jsi::Value(false);
121-
}
122-
auto obj = args[0].getObject(runtime);
123-
124-
// Check if it has native state
125-
if (!obj.hasNativeState(runtime)) {
126-
return jsi::Value(false);
127-
}
128-
129-
// Check if it has Symbol.toStringTag on its prototype (WebGPU objects do)
130-
auto objectCtor = runtime.global().getPropertyAsObject(runtime, "Object");
131-
auto getPrototypeOf =
132-
objectCtor.getPropertyAsFunction(runtime, "getPrototypeOf");
133-
auto proto = getPrototypeOf.call(runtime, obj);
134-
135-
if (!proto.isObject()) {
136-
return jsi::Value(false);
137-
}
138-
139-
auto protoObj = proto.getObject(runtime);
140-
auto symbolCtor = runtime.global().getPropertyAsObject(runtime, "Symbol");
141-
auto toStringTag = symbolCtor.getProperty(runtime, "toStringTag");
142-
if (toStringTag.isUndefined()) {
143-
return jsi::Value(false);
144-
}
145-
146-
auto getOwnPropertyDescriptor =
147-
objectCtor.getPropertyAsFunction(runtime, "getOwnPropertyDescriptor");
148-
auto desc = getOwnPropertyDescriptor.call(runtime, protoObj, toStringTag);
149-
return jsi::Value(desc.isObject());
150-
}
151-
15237
bool getFabric() { return true; }
15338

15439
std::shared_ptr<GPUCanvasContext>
@@ -185,36 +70,6 @@ class RNWebGPU : public NativeObject<RNWebGPU> {
18570
&RNWebGPU::getNativeSurface);
18671
installMethod(runtime, prototype, "MakeWebGPUCanvasContext",
18772
&RNWebGPU::MakeWebGPUCanvasContext);
188-
189-
// Install box() - boxes a WebGPU object for Worklets serialization
190-
auto boxFunc = jsi::Function::createFromHostFunction(
191-
runtime, jsi::PropNameID::forUtf8(runtime, "box"), 1,
192-
[](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
193-
size_t count) -> jsi::Value {
194-
auto native = RNWebGPU::fromValue(rt, thisVal);
195-
return native->box(rt, thisVal, args, count);
196-
});
197-
prototype.setProperty(runtime, "box", boxFunc);
198-
199-
// Install isWebGPUObject() - checks if a value is a WebGPU NativeObject
200-
auto isWebGPUObjectFunc = jsi::Function::createFromHostFunction(
201-
runtime, jsi::PropNameID::forUtf8(runtime, "isWebGPUObject"), 1,
202-
[](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
203-
size_t count) -> jsi::Value {
204-
auto native = RNWebGPU::fromValue(rt, thisVal);
205-
return native->isWebGPUObject(rt, thisVal, args, count);
206-
});
207-
prototype.setProperty(runtime, "isWebGPUObject", isWebGPUObjectFunc);
208-
209-
// Install isBoxedWebGPUObject() - checks if a value is a boxed WebGPU object
210-
auto isBoxedWebGPUObjectFunc = jsi::Function::createFromHostFunction(
211-
runtime, jsi::PropNameID::forUtf8(runtime, "isBoxedWebGPUObject"), 1,
212-
[](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
213-
size_t count) -> jsi::Value {
214-
auto native = RNWebGPU::fromValue(rt, thisVal);
215-
return native->isBoxedWebGPUObject(rt, thisVal, args, count);
216-
});
217-
prototype.setProperty(runtime, "isBoxedWebGPUObject", isBoxedWebGPUObjectFunc);
21873
}
21974

22075
private:

0 commit comments

Comments
 (0)