@@ -55,11 +55,29 @@ struct BufferSourceContext: public jsg::Object, public jsg::ContextGlobal {
55
55
return BufferSource (js, BackingStore::alloc<v8::ArrayBuffer>(js, 3 ));
56
56
}
57
57
58
+ bool doTest (jsg::Lock& js, jsg::BufferSource buf) {
59
+ buf.asArrayPtr ()[0 ] = 1 ;
60
+ buf.asArrayPtr ()[1 ] = 2 ;
61
+ buf.asArrayPtr ()[2 ] = 3 ;
62
+ buf.asArrayPtr ()[3 ] = 4 ;
63
+ buf.asArrayPtr ()[4 ] = 5 ;
64
+ buf.asArrayPtr ()[5 ] = 6 ;
65
+ buf.asArrayPtr ()[6 ] = 7 ;
66
+ buf.asArrayPtr ()[7 ] = 8 ;
67
+
68
+ auto ptr = buf.asArrayPtr <uint32_t >();
69
+ KJ_ASSERT (ptr.size () == 2 );
70
+ KJ_ASSERT (ptr[0 ] == 0x04030201 );
71
+ KJ_ASSERT (ptr[1 ] == 0x08070605 );
72
+ return true ;
73
+ }
74
+
58
75
JSG_RESOURCE_TYPE (BufferSourceContext) {
59
76
JSG_METHOD (takeBufferSource);
60
77
JSG_METHOD (takeUint8Array);
61
78
JSG_METHOD (makeBufferSource);
62
79
JSG_METHOD (makeArrayBuffer);
80
+ JSG_METHOD (doTest);
63
81
}
64
82
};
65
83
JSG_DECLARE_ISOLATE_TYPE (BufferSourceIsolate, BufferSourceContext);
@@ -99,6 +117,8 @@ KJ_TEST("BufferSource works") {
99
117
" u8.byteLength === 0 && u2.byteLength === 1 && u2 instanceof Uint8Array && "
100
118
" u2.buffer.byteLength === 4 && u2.byteOffset === 1 && u8 !== u2" ,
101
119
" boolean" , " true" );
120
+
121
+ e.expectEval (" const buf = new Uint8Array(12); doTest(buf.subarray(4))" , " boolean" , " true" );
102
122
}
103
123
104
124
} // namespace
0 commit comments