Skip to content

Commit

Permalink
deps: V8: cherry-pick be91c6c50818
Browse files Browse the repository at this point in the history
Original commit message:

    [compiler][cleanup] Move Make(String|Name) helper methods to cctest.h

    Several tests were using them and we can dedup code.

    Change-Id: I4ef5ae5772856d1f36e965b6b62ff5895b4e04fb
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2215173
    Reviewed-by: Maya Lekova <mslekova@chromium.org>
    Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#67974}

Refs: v8/v8@be91c6c

PR-URL: #38275
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
  • Loading branch information
targos committed Apr 30, 2021
1 parent 16a005c commit bda1514
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 138 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.58',
'v8_embedder_string': '-node.59',

##### V8 defaults for Node.js #####

Expand Down
12 changes: 12 additions & 0 deletions deps/v8/test/cctest/cctest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ void CcTest::PreciseCollectAllGarbage(i::Isolate* isolate) {
i::GarbageCollectionReason::kTesting);
}

i::Handle<i::String> CcTest::MakeString(const char* str) {
i::Isolate* isolate = CcTest::i_isolate();
i::Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}

i::Handle<i::String> CcTest::MakeName(const char* str, int suffix) {
i::EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return CcTest::MakeString(buffer.begin());
}

v8::base::RandomNumberGenerator* CcTest::random_number_generator() {
return InitIsolateOnce()->random_number_generator();
}
Expand Down
3 changes: 3 additions & 0 deletions deps/v8/test/cctest/cctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class CcTest {
static void CollectAllAvailableGarbage(i::Isolate* isolate = nullptr);
static void PreciseCollectAllGarbage(i::Isolate* isolate = nullptr);

static i::Handle<i::String> MakeString(const char* str);
static i::Handle<i::String> MakeName(const char* str, int suffix);

static v8::base::RandomNumberGenerator* random_number_generator();

static v8::Local<v8::Object> global();
Expand Down
22 changes: 5 additions & 17 deletions deps/v8/test/cctest/test-code-stub-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ template <class T>
using TVariable = TypedCodeAssemblerVariable<T>;
using PromiseResolvingFunctions = TorqueStructPromiseResolvingFunctions;

Handle<String> MakeString(const char* str) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}

Handle<String> MakeName(const char* str, int suffix) {
EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return MakeString(buffer.begin());
}

intptr_t sum10(intptr_t a0, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4,
intptr_t a5, intptr_t a6, intptr_t a7, intptr_t a8,
intptr_t a9) {
Expand Down Expand Up @@ -1091,7 +1079,7 @@ TEST(TransitionLookup) {
name = factory->NewSymbol();
} else {
int random_key = rand_gen.NextInt(Smi::kMaxValue);
name = MakeName("p", random_key);
name = CcTest::MakeName("p", random_key);
}
keys[i] = name;

Expand Down Expand Up @@ -3646,8 +3634,8 @@ TEST(TestCallBuiltinInlineTrampoline) {
options.use_pc_relative_calls_and_jumps = false;
options.isolate_independent_code = false;
FunctionTester ft(asm_tester.GenerateCode(options), kNumParams);
MaybeHandle<Object> result = ft.Call(MakeString("abcdef"));
CHECK(String::Equals(isolate, MakeString("abcdefabcdef"),
MaybeHandle<Object> result = ft.Call(CcTest::MakeString("abcdef"));
CHECK(String::Equals(isolate, CcTest::MakeString("abcdefabcdef"),
Handle<String>::cast(result.ToHandleChecked())));
}

Expand All @@ -3672,8 +3660,8 @@ DISABLED_TEST(TestCallBuiltinIndirectLoad) {
options.use_pc_relative_calls_and_jumps = false;
options.isolate_independent_code = true;
FunctionTester ft(asm_tester.GenerateCode(options), kNumParams);
MaybeHandle<Object> result = ft.Call(MakeString("abcdef"));
CHECK(String::Equals(isolate, MakeString("abcdefabcdef"),
MaybeHandle<Object> result = ft.Call(CcTest::MakeString("abcdef"));
CHECK(String::Equals(isolate, CcTest::MakeString("abcdefabcdef"),
Handle<String>::cast(result.ToHandleChecked())));
}

Expand Down
73 changes: 30 additions & 43 deletions deps/v8/test/cctest/test-elements-kind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ namespace test_elements_kind {

namespace {

Handle<String> MakeString(const char* str) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}


Handle<String> MakeName(const char* str, int suffix) {
EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return MakeString(buffer.begin());
}

template <typename T, typename M>
bool EQUALS(Isolate* isolate, Handle<T> left, Handle<M> right) {
if (*left == *right) return true;
Expand Down Expand Up @@ -127,7 +114,7 @@ TEST(JSObjectAddingProperties) {

// for the default constructor function no in-object properties are reserved
// hence adding a single property will initialize the property-array
Handle<String> name = MakeName("property", 0);
Handle<String> name = CcTest::MakeName("property", 0);
JSObject::DefinePropertyOrElementIgnoreAttributes(object, name, value, NONE)
.Check();
CHECK_NE(object->map(), *previous_map);
Expand Down Expand Up @@ -162,7 +149,7 @@ TEST(JSObjectInObjectAddingProperties) {
// we have reserved space for in-object properties, hence adding up to
// |nof_inobject_properties| will not create a property store
for (int i = 0; i < nof_inobject_properties; i++) {
Handle<String> name = MakeName("property", i);
Handle<String> name = CcTest::MakeName("property", i);
JSObject::DefinePropertyOrElementIgnoreAttributes(object, name, value, NONE)
.Check();
}
Expand All @@ -174,7 +161,7 @@ TEST(JSObjectInObjectAddingProperties) {
// adding one more property will not fit in the in-object properties, thus
// creating a property store
int index = nof_inobject_properties + 1;
Handle<String> name = MakeName("property", index);
Handle<String> name = CcTest::MakeName("property", index);
JSObject::DefinePropertyOrElementIgnoreAttributes(object, name, value, NONE)
.Check();
CHECK_NE(object->map(), *previous_map);
Expand Down Expand Up @@ -205,7 +192,7 @@ TEST(JSObjectAddingElements) {
CHECK(EQUALS(isolate, object->elements(), empty_fixed_array));

// Adding an indexed element initializes the elements array
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(object, name, value, NONE)
.Check();
// no change in elements_kind => no map transition
Expand All @@ -217,7 +204,7 @@ TEST(JSObjectAddingElements) {
// Adding more consecutive elements without a change in the backing store
int non_dict_backing_store_limit = 100;
for (int i = 1; i < non_dict_backing_store_limit; i++) {
name = MakeName("", i);
name = CcTest::MakeName("", i);
JSObject::DefinePropertyOrElementIgnoreAttributes(object, name, value, NONE)
.Check();
}
Expand All @@ -229,7 +216,7 @@ TEST(JSObjectAddingElements) {

// Adding an element at an very large index causes a change to
// DICTIONARY_ELEMENTS
name = MakeString("100000000");
name = CcTest::MakeString("100000000");
JSObject::DefinePropertyOrElementIgnoreAttributes(object, name, value, NONE)
.Check();
// change in elements_kind => map transition
Expand Down Expand Up @@ -260,7 +247,7 @@ TEST(JSArrayAddingProperties) {

// for the default constructor function no in-object properties are reserved
// hence adding a single property will initialize the property-array
Handle<String> name = MakeName("property", 0);
Handle<String> name = CcTest::MakeName("property", 0);
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value, NONE)
.Check();
// No change in elements_kind but added property => new map
Expand Down Expand Up @@ -292,7 +279,7 @@ TEST(JSArrayAddingElements) {
CHECK_EQ(0, Smi::ToInt(array->length()));

// Adding an indexed element initializes the elements array
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value, NONE)
.Check();
// no change in elements_kind => no map transition
Expand All @@ -305,7 +292,7 @@ TEST(JSArrayAddingElements) {
// Adding more consecutive elements without a change in the backing store
int non_dict_backing_store_limit = 100;
for (int i = 1; i < non_dict_backing_store_limit; i++) {
name = MakeName("", i);
name = CcTest::MakeName("", i);
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value, NONE)
.Check();
}
Expand All @@ -319,7 +306,7 @@ TEST(JSArrayAddingElements) {
// Adding an element at an very large index causes a change to
// DICTIONARY_ELEMENTS
int index = 100000000;
name = MakeName("", index);
name = CcTest::MakeName("", index);
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value, NONE)
.Check();
// change in elements_kind => map transition
Expand All @@ -340,7 +327,7 @@ TEST(JSArrayAddingElementsGeneralizingiFastSmiElements) {

Handle<String> name;
Handle<Object> value_smi(Smi::FromInt(42), isolate);
Handle<Object> value_string(MakeString("value"));
Handle<Object> value_string(CcTest::MakeString("value"));
Handle<Object> value_double = factory->NewNumber(3.1415);

Handle<JSArray> array =
Expand All @@ -350,7 +337,7 @@ TEST(JSArrayAddingElementsGeneralizingiFastSmiElements) {
CHECK_EQ(0, Smi::ToInt(array->length()));

// `array[0] = smi_value` doesn't change the elements_kind
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
Expand All @@ -360,19 +347,19 @@ TEST(JSArrayAddingElementsGeneralizingiFastSmiElements) {
CHECK_EQ(1, Smi::ToInt(array->length()));

// `delete array[0]` does not alter length, but changes the elments_kind
name = MakeString("0");
name = CcTest::MakeString("0");
CHECK(JSReceiver::DeletePropertyOrElement(array, name).FromMaybe(false));
CHECK_NE(array->map(), *previous_map);
CHECK_EQ(HOLEY_SMI_ELEMENTS, array->map().elements_kind());
CHECK_EQ(1, Smi::ToInt(array->length()));
previous_map = handle(array->map(), isolate);

// add a couple of elements again
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
name = MakeString("1");
name = CcTest::MakeString("1");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
Expand All @@ -381,7 +368,7 @@ TEST(JSArrayAddingElementsGeneralizingiFastSmiElements) {
CHECK_EQ(2, Smi::ToInt(array->length()));

// Adding a string to the array changes from FAST_HOLEY_SMI to FAST_HOLEY
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_string,
NONE)
.Check();
Expand All @@ -391,14 +378,14 @@ TEST(JSArrayAddingElementsGeneralizingiFastSmiElements) {
previous_map = handle(array->map(), isolate);

// We don't transition back to FAST_SMI even if we remove the string
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
CHECK_EQ(array->map(), *previous_map);

// Adding a double doesn't change the map either
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_double,
NONE)
.Check();
Expand All @@ -414,7 +401,7 @@ TEST(JSArrayAddingElementsGeneralizingFastElements) {

Handle<String> name;
Handle<Object> value_smi(Smi::FromInt(42), isolate);
Handle<Object> value_string(MakeString("value"));
Handle<Object> value_string(CcTest::MakeString("value"));

Handle<JSArray> array =
factory->NewJSArray(ElementsKind::PACKED_ELEMENTS, 0, 0);
Expand All @@ -423,7 +410,7 @@ TEST(JSArrayAddingElementsGeneralizingFastElements) {
CHECK_EQ(0, Smi::ToInt(array->length()));

// `array[0] = smi_value` doesn't change the elements_kind
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
Expand All @@ -433,19 +420,19 @@ TEST(JSArrayAddingElementsGeneralizingFastElements) {
CHECK_EQ(1, Smi::ToInt(array->length()));

// `delete array[0]` does not alter length, but changes the elments_kind
name = MakeString("0");
name = CcTest::MakeString("0");
CHECK(JSReceiver::DeletePropertyOrElement(array, name).FromMaybe(false));
CHECK_NE(array->map(), *previous_map);
CHECK_EQ(HOLEY_ELEMENTS, array->map().elements_kind());
CHECK_EQ(1, Smi::ToInt(array->length()));
previous_map = handle(array->map(), isolate);

// add a couple of elements, elements_kind stays HOLEY
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_string,
NONE)
.Check();
name = MakeString("1");
name = CcTest::MakeString("1");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
Expand All @@ -463,15 +450,15 @@ TEST(JSArrayAddingElementsGeneralizingiFastDoubleElements) {

Handle<String> name;
Handle<Object> value_smi(Smi::FromInt(42), isolate);
Handle<Object> value_string(MakeString("value"));
Handle<Object> value_string(CcTest::MakeString("value"));
Handle<Object> value_double = factory->NewNumber(3.1415);

Handle<JSArray> array =
factory->NewJSArray(ElementsKind::PACKED_SMI_ELEMENTS, 0, 0);
Handle<Map> previous_map(array->map(), isolate);

// `array[0] = value_double` changes |elements_kind| to PACKED_DOUBLE_ELEMENTS
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_double,
NONE)
.Check();
Expand All @@ -481,7 +468,7 @@ TEST(JSArrayAddingElementsGeneralizingiFastDoubleElements) {
previous_map = handle(array->map(), isolate);

// `array[1] = value_smi` doesn't alter the |elements_kind|
name = MakeString("1");
name = CcTest::MakeString("1");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_smi,
NONE)
.Check();
Expand All @@ -490,15 +477,15 @@ TEST(JSArrayAddingElementsGeneralizingiFastDoubleElements) {
CHECK_EQ(2, Smi::ToInt(array->length()));

// `delete array[0]` does not alter length, but changes the elments_kind
name = MakeString("0");
name = CcTest::MakeString("0");
CHECK(JSReceiver::DeletePropertyOrElement(array, name).FromMaybe(false));
CHECK_NE(array->map(), *previous_map);
CHECK_EQ(HOLEY_DOUBLE_ELEMENTS, array->map().elements_kind());
CHECK_EQ(2, Smi::ToInt(array->length()));
previous_map = handle(array->map(), isolate);

// filling the hole `array[0] = value_smi` again doesn't transition back
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_double,
NONE)
.Check();
Expand All @@ -507,7 +494,7 @@ TEST(JSArrayAddingElementsGeneralizingiFastDoubleElements) {
CHECK_EQ(2, Smi::ToInt(array->length()));

// Adding a string to the array changes to elements_kind PACKED_ELEMENTS
name = MakeString("1");
name = CcTest::MakeString("1");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_string,
NONE)
.Check();
Expand All @@ -517,7 +504,7 @@ TEST(JSArrayAddingElementsGeneralizingiFastDoubleElements) {
previous_map = handle(array->map(), isolate);

// Adding a double doesn't change the map
name = MakeString("0");
name = CcTest::MakeString("0");
JSObject::DefinePropertyOrElementIgnoreAttributes(array, name, value_double,
NONE)
.Check();
Expand Down
Loading

0 comments on commit bda1514

Please sign in to comment.