Changeset 292950 in webkit


Ignore:
Timestamp:
Apr 17, 2022, 2:52:53 PM (3 years ago)
Author:
mark.lam@apple.com
Message:

Harden JSObject::setPrototypeOf.
https://bugs.webkit.org/show_bug.cgi?id=239440

Reviewed by Yusuke Suzuki.

  • runtime/JSObject.cpp:

(JSC::JSObject::setPrototypeDirect):
(JSC::JSObject::setPrototypeWithCycleCheck):

  • runtime/JSObject.h:
  • runtime/ObjectConstructor.cpp:

(JSC::objectConstructorSetPrototypeOf):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r292946 r292950  
     12022-04-16  Mark Lam  <mark.lam@apple.com>
     2
     3        Harden JSObject::setPrototypeOf.
     4        https://bugs.webkit.org/show_bug.cgi?id=239440
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * runtime/JSObject.cpp:
     9        (JSC::JSObject::setPrototypeDirect):
     10        (JSC::JSObject::setPrototypeWithCycleCheck):
     11        * runtime/JSObject.h:
     12        * runtime/ObjectConstructor.cpp:
     13        (JSC::objectConstructorSetPrototypeOf):
     14
    1152022-04-16  Mark Lam  <mark.lam@apple.com>
    216
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r292929 r292950  
    22 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    33 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    4  *  Copyright (C) 2003-2021 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2003-2022 Apple Inc. All rights reserved.
    55 *  Copyright (C) 2007 Eric Seidel (eric@webkit.org)
    66 *
     
    6565const ASCIILiteral UnconfigurablePropertyChangeEnumerabilityError { "Attempting to change enumerable attribute of unconfigurable property."_s };
    6666const ASCIILiteral UnconfigurablePropertyChangeWritabilityError { "Attempting to change writable attribute of unconfigurable property."_s };
     67const ASCIILiteral PrototypeValueCanOnlyBeAnObjectOrNullTypeError { "Prototype value can only be an object or null"_s };
    6768
    6869const ClassInfo JSObject::s_info = { "Object"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSObject) };
     
    18741875void JSObject::setPrototypeDirect(VM& vm, JSValue prototype)
    18751876{
    1876     ASSERT(prototype);
     1877    ASSERT(prototype.isObject() || prototype.isNull());
    18771878    if (prototype.isObject())
    18781879        asObject(prototype)->didBecomePrototype();
     1880    else if (UNLIKELY(!prototype.isNull())) // Conservative hardening.
     1881        return;
    18791882   
    18801883    if (structure()->hasMonoProto()) {
     
    19261929    if (!isExtensible)
    19271930        return typeError(globalObject, scope, shouldThrowIfCantSet, ReadonlyPropertyWriteError);
     1931
     1932    // Some clients would have already done this check because of the order of the check
     1933    // specified in their respective specifications. However, we still do this check here
     1934    // to document and enforce this invariant about the nature of prototype.
     1935    if (UNLIKELY(!prototype.isObject() && !prototype.isNull()))
     1936        return typeError(globalObject, scope, shouldThrowIfCantSet, PrototypeValueCanOnlyBeAnObjectOrNullTypeError);
    19281937
    19291938    JSValue nextPrototype = prototype;
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r292929 r292950  
    22 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    33 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    4  *  Copyright (C) 2003-2021 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2003-2022 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    8484extern JS_EXPORT_PRIVATE const ASCIILiteral UnconfigurablePropertyChangeEnumerabilityError;
    8585extern JS_EXPORT_PRIVATE const ASCIILiteral UnconfigurablePropertyChangeWritabilityError;
     86extern JS_EXPORT_PRIVATE const ASCIILiteral PrototypeValueCanOnlyBeAnObjectOrNullTypeError;
    8687
    8788class JSFinalObject;
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp

    r292929 r292950  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2008-2021 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2008-2022 Apple Inc. All rights reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    161161    JSValue protoValue = callFrame->argument(1);
    162162    if (!protoValue.isObject() && !protoValue.isNull())
    163         return throwVMTypeError(globalObject, scope, "Prototype value can only be an object or null"_s);
     163        return throwVMTypeError(globalObject, scope, PrototypeValueCanOnlyBeAnObjectOrNullTypeError);
    164164
    165165    JSObject* object = objectValue.toObject(globalObject);
Note: See TracChangeset for help on using the changeset viewer.