From 7d6db3f09bb995e8e253aca08fdcf5780722fa41 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 10 Jun 2021 22:42:10 +0300 Subject: [PATCH] LibJS: Throw TypeError on non-object this value in ArrayBuffer methods `1. If Type(O) is not Object, throw a TypeError exception.` --- Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp index db345379ed..6a9dfb80b2 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp @@ -37,14 +37,11 @@ static ArrayBuffer* array_buffer_object_from(VM& vm, GlobalObject& global_object { // ArrayBuffer.prototype.* deliberately don't coerce |this| value to object. auto this_value = vm.this_value(global_object); - if (!this_value.is_object()) - return nullptr; - auto& this_object = this_value.as_object(); - if (!is(this_object)) { + if (!this_value.is_object() || !is(this_value.as_object())) { vm.throw_exception(global_object, ErrorType::NotAn, "ArrayBuffer"); return nullptr; } - return static_cast(&this_object); + return static_cast(&this_value.as_object()); } // 25.1.5.3 ArrayBuffer.prototype.slice, https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice