Bug 1854643 - Fix JS_DeletePropertyById argument type in header file. r=sfink

The changes in testGCStoreBufferRemoval.cpp are to fix "Heap is ambiguous" errors
with unified builds.

Differential Revision: https://phabricator.services.mozilla.com/D188986
This commit is contained in:
Jan de Mooij
2023-09-25 12:12:52 +00:00
parent 353b26530a
commit 296417ee22
4 changed files with 60 additions and 5 deletions

View File

@@ -405,7 +405,7 @@ extern JS_PUBLIC_API bool JS_DeleteElement(JSContext* cx,
*/
extern JS_PUBLIC_API bool JS_DeletePropertyById(JSContext* cx,
JS::Handle<JSObject*> obj,
jsid id);
JS::Handle<jsid> id);
extern JS_PUBLIC_API bool JS_DeleteProperty(JSContext* cx,
JS::Handle<JSObject*> obj,

View File

@@ -38,6 +38,7 @@ UNIFIED_SOURCES += [
"testDefineGetterSetterNonEnumerable.cpp",
"testDefineProperty.cpp",
"testDeflateStringToUTF8Buffer.cpp",
"testDeleteProperty.cpp",
"testDifferentNewTargetInvokeConstructor.cpp",
"testEmptyWindowIsOmitted.cpp",
"testErrorCopying.cpp",

View File

@@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "js/Id.h"
#include "js/PropertyAndElement.h"
#include "jsapi-tests/tests.h"
BEGIN_TEST(testDeleteProperty) {
JS::RootedValue val(cx);
EVAL("var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8}; obj", &val);
CHECK(val.isObject());
JS::RootedObject obj(cx, &val.toObject());
JS::Rooted<JS::PropertyKey> key(cx);
auto createPropertyKey = [](JSContext* cx, const char* s,
JS::MutableHandle<JS::PropertyKey> key) {
JSString* atom = JS_AtomizeString(cx, s);
if (!atom) {
return false;
}
key.set(JS::PropertyKey::NonIntAtom(atom));
return true;
};
// Test delete APIs without an ObjectOpResult argument.
CHECK(JS_DeleteProperty(cx, obj, "b"));
CHECK(createPropertyKey(cx, "d", &key));
CHECK(JS_DeletePropertyById(cx, obj, key));
// Test delete APIs with an ObjectOpResult argument.
JS::ObjectOpResult result;
CHECK(JS_DeleteProperty(cx, obj, "e", result));
CHECK(result);
CHECK(createPropertyKey(cx, "f", &key));
CHECK(JS_DeletePropertyById(cx, obj, key, result));
CHECK(result);
// Check properties were deleted.
EVAL("JSON.stringify(obj)", &val);
CHECK(val.isString());
bool match = false;
CHECK(JS_StringEqualsAscii(cx, val.toString(),
"{\"a\":1,\"c\":3,\"g\":7,\"h\":8}", &match));
CHECK(match);
return true;
}
END_TEST(testDeleteProperty)

View File

@@ -79,21 +79,22 @@ BEGIN_TEST(testGCStoreBufferRemoval) {
// Test removal of store buffer entries added by Heap<T>.
{
JSObject* punnedPtr = nullptr;
Heap<JSObject*>* heapPtr = reinterpret_cast<Heap<JSObject*>*>(&punnedPtr);
new (heapPtr) Heap<JSObject*>;
JS::Heap<JSObject*>* heapPtr =
reinterpret_cast<JS::Heap<JSObject*>*>(&punnedPtr);
new (heapPtr) JS::Heap<JSObject*>;
*heapPtr = NurseryObject();
heapPtr->~Heap<JSObject*>();
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
new (heapPtr) Heap<JSObject*>;
new (heapPtr) JS::Heap<JSObject*>;
*heapPtr = NurseryObject();
*heapPtr = tenuredObject;
heapPtr->~Heap<JSObject*>();
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
new (heapPtr) Heap<JSObject*>;
new (heapPtr) JS::Heap<JSObject*>;
*heapPtr = NurseryObject();
*heapPtr = nullptr;
heapPtr->~Heap<JSObject*>();