| 533 | } |
| 534 | |
| 535 | Valdi::JSValueRef QuickJSJavaScriptContext::newArrayBuffer(const Valdi::BytesView& buffer, |
| 536 | Valdi::JSExceptionTracker& exceptionTracker) { |
| 537 | auto guard = _threadAccessChecker.guard(); |
| 538 | if (buffer.empty()) { |
| 539 | return toRetainedJSValueRef(JS_DupValue(_context, _emptyArrayBuffer)); |
| 540 | } else { |
| 541 | JSFreeArrayBufferDataFunc* freeFunction; |
| 542 | auto* byteBuffer = dynamic_cast<Valdi::ByteBuffer*>(buffer.getSource().get()); |
| 543 | |
| 544 | // For byte buffers that we are transferring to JS, we notify the JS engine about the memory |
| 545 | // usage from them, to increase the likely of a future GC pass. |
| 546 | if (byteBuffer != nullptr && byteBuffer->retainCount() == 1) { |
| 547 | freeFunction = &freeByteBuffer; |
| 548 | JS_IncreaseExternallyAllocatedMemory(_runtime, byteBuffer->capacity()); |
| 549 | } else { |
| 550 | freeFunction = &freeArrayBuffer; |
| 551 | } |
| 552 | |
| 553 | return checkCallAndGetValue(exceptionTracker, |
| 554 | JS_NewArrayBuffer(_context, |
| 555 | const_cast<Valdi::Byte*>(buffer.data()), |
| 556 | buffer.size(), |
| 557 | freeFunction, |
| 558 | Valdi::unsafeBridgeRetain(buffer.getSource().get()), |
| 559 | 0)); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | Valdi::JSValueRef QuickJSJavaScriptContext::newTypedArrayFromArrayBuffer(const Valdi::TypedArrayType& type, |
| 564 | const Valdi::JSValue& arrayBuffer, |
nothing calls this directly
no test coverage detected