From 07c7e94b0ee0995f67120afaffe4caadefee7b9e Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 19 Sep 2023 16:46:11 +0300 Subject: [PATCH] Fix using runtime.NewArrayBuffer After the templating changes calling `NewArrayBuffer` will make an object but will set it's prototype to nil. This change uses the new function call that will create the prototype if not created yet. It also changes in two other places where it seemed like it was missed. --- builtin_typedarrays.go | 4 ++-- typedarrays.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin_typedarrays.go b/builtin_typedarrays.go index e867da83..1fd672c1 100644 --- a/builtin_typedarrays.go +++ b/builtin_typedarrays.go @@ -510,7 +510,7 @@ func (r *Runtime) typedArrayProto_filter(call FunctionCall) Value { } } c := r.speciesConstructorObj(o, ta.defaultCtor) - ab := r._newArrayBuffer(r.global.ArrayBufferPrototype, nil) + ab := r._newArrayBuffer(r.getArrayBufferPrototype(), nil) ab.data = buf kept := r.toConstructor(ta.defaultCtor)([]Value{ab.val}, ta.defaultCtor) if c == ta.defaultCtor { @@ -1215,7 +1215,7 @@ func (r *Runtime) typedArray_of(call FunctionCall) Value { } func (r *Runtime) allocateTypedArray(newTarget *Object, length int, taCtor typedArrayObjectCtor, proto *Object) *typedArrayObject { - buf := r._newArrayBuffer(r.global.ArrayBufferPrototype, nil) + buf := r._newArrayBuffer(r.getArrayBufferPrototype(), nil) ta := taCtor(buf, 0, length, r.getPrototypeFromCtor(newTarget, nil, proto)) if length > 0 { buf.data = allocByteSlice(length * ta.elemSize) diff --git a/typedarrays.go b/typedarrays.go index 132cbf45..9af03503 100644 --- a/typedarrays.go +++ b/typedarrays.go @@ -117,7 +117,7 @@ func (a ArrayBuffer) Detached() bool { // using this typed array will result in unaligned access which may cause performance degradation or runtime panics // on some architectures or configurations. func (r *Runtime) NewArrayBuffer(data []byte) ArrayBuffer { - buf := r._newArrayBuffer(r.global.ArrayBufferPrototype, nil) + buf := r._newArrayBuffer(r.getArrayBufferPrototype(), nil) buf.data = data return ArrayBuffer{ buf: buf,