OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.h" |
6 #include "src/builtins/builtins-promise.h" | 6 #include "src/builtins/builtins-promise.h" |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 | 2040 |
2041 FunctionTester ft(code, kNumParams); | 2041 FunctionTester ft(code, kNumParams); |
2042 Handle<Object> result_obj = | 2042 Handle<Object> result_obj = |
2043 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); | 2043 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
2044 CHECK(result_obj->IsFixedArray()); | 2044 CHECK(result_obj->IsFixedArray()); |
2045 Handle<FixedArray> result_arr = Handle<FixedArray>::cast(result_obj); | 2045 Handle<FixedArray> result_arr = Handle<FixedArray>::cast(result_obj); |
2046 CHECK(result_arr->get(0)->IsJSFunction()); | 2046 CHECK(result_arr->get(0)->IsJSFunction()); |
2047 CHECK(result_arr->get(1)->IsJSFunction()); | 2047 CHECK(result_arr->get(1)->IsJSFunction()); |
2048 } | 2048 } |
2049 | 2049 |
| 2050 TEST(NewElementsCapacity) { |
| 2051 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 2052 CodeAssemblerTester data(isolate, 1); |
| 2053 CodeStubAssembler m(data.state()); |
| 2054 m.Return(m.SmiTag(m.CalculateNewElementsCapacity( |
| 2055 m.SmiUntag(m.Parameter(0)), CodeStubAssembler::INTPTR_PARAMETERS))); |
| 2056 Handle<Code> code = data.GenerateCode(); |
| 2057 CHECK(!code.is_null()); |
| 2058 FunctionTester ft(code, 1); |
| 2059 Handle<Smi> test_value = Handle<Smi>(Smi::FromInt(0), isolate); |
| 2060 Handle<Smi> result_obj = |
| 2061 Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2062 CHECK_EQ( |
| 2063 result_obj->value(), |
| 2064 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2065 test_value = Handle<Smi>(Smi::FromInt(1), isolate); |
| 2066 result_obj = Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2067 CHECK_EQ( |
| 2068 result_obj->value(), |
| 2069 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2070 test_value = Handle<Smi>(Smi::FromInt(2), isolate); |
| 2071 result_obj = Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2072 CHECK_EQ( |
| 2073 result_obj->value(), |
| 2074 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2075 test_value = Handle<Smi>(Smi::FromInt(1025), isolate); |
| 2076 result_obj = Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2077 CHECK_EQ( |
| 2078 result_obj->value(), |
| 2079 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2080 } |
| 2081 |
| 2082 TEST(NewElementsCapacitySmi) { |
| 2083 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 2084 CodeAssemblerTester data(isolate, 1); |
| 2085 CodeStubAssembler m(data.state()); |
| 2086 m.Return(m.CalculateNewElementsCapacity(m.Parameter(0), |
| 2087 CodeStubAssembler::SMI_PARAMETERS)); |
| 2088 Handle<Code> code = data.GenerateCode(); |
| 2089 code->Print(); |
| 2090 CHECK(!code.is_null()); |
| 2091 FunctionTester ft(code, 1); |
| 2092 Handle<Smi> test_value = Handle<Smi>(Smi::FromInt(0), isolate); |
| 2093 Handle<Smi> result_obj = |
| 2094 Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2095 CHECK_EQ( |
| 2096 result_obj->value(), |
| 2097 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2098 test_value = Handle<Smi>(Smi::FromInt(1), isolate); |
| 2099 result_obj = Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2100 CHECK_EQ( |
| 2101 result_obj->value(), |
| 2102 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2103 test_value = Handle<Smi>(Smi::FromInt(2), isolate); |
| 2104 result_obj = Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2105 CHECK_EQ( |
| 2106 result_obj->value(), |
| 2107 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2108 test_value = Handle<Smi>(Smi::FromInt(1025), isolate); |
| 2109 result_obj = Handle<Smi>::cast(ft.Call(test_value).ToHandleChecked()); |
| 2110 CHECK_EQ( |
| 2111 result_obj->value(), |
| 2112 static_cast<int>(JSObject::NewElementsCapacity(test_value->value()))); |
| 2113 } |
| 2114 |
2050 TEST(AllocateFunctionWithMapAndContext) { | 2115 TEST(AllocateFunctionWithMapAndContext) { |
2051 Isolate* isolate(CcTest::InitIsolateOnce()); | 2116 Isolate* isolate(CcTest::InitIsolateOnce()); |
2052 | 2117 |
2053 const int kNumParams = 1; | 2118 const int kNumParams = 1; |
2054 CodeAssemblerTester data(isolate, kNumParams); | 2119 CodeAssemblerTester data(isolate, kNumParams); |
2055 PromiseBuiltinsAssembler m(data.state()); | 2120 PromiseBuiltinsAssembler m(data.state()); |
2056 | 2121 |
2057 Node* const context = m.Parameter(kNumParams + 2); | 2122 Node* const context = m.Parameter(kNumParams + 2); |
2058 Node* const native_context = m.LoadNativeContext(context); | 2123 Node* const native_context = m.LoadNativeContext(context); |
2059 Node* const promise = | 2124 Node* const promise = |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 .ToHandleChecked(); | 2294 .ToHandleChecked(); |
2230 Handle<Object> prop2 = | 2295 Handle<Object> prop2 = |
2231 JSReceiver::GetProperty(isolate, promise, "rejectedReason") | 2296 JSReceiver::GetProperty(isolate, promise, "rejectedReason") |
2232 .ToHandleChecked(); | 2297 .ToHandleChecked(); |
2233 CHECK_EQ(*rejected_str, *prop2); | 2298 CHECK_EQ(*rejected_str, *prop2); |
2234 } | 2299 } |
2235 } | 2300 } |
2236 | 2301 |
2237 } // namespace internal | 2302 } // namespace internal |
2238 } // namespace v8 | 2303 } // namespace v8 |
OLD | NEW |