Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2604273003: [csa] Refactor promises API (Closed)
Patch Set: comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/code-stub-assembler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 1782
1783 isolate->SetPromiseHook(CustomPromiseHook); 1783 isolate->SetPromiseHook(CustomPromiseHook);
1784 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1784 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1785 CHECK_EQ(isolate->heap()->true_value(), *result); 1785 CHECK_EQ(isolate->heap()->true_value(), *result);
1786 1786
1787 isolate->SetPromiseHook(nullptr); 1787 isolate->SetPromiseHook(nullptr);
1788 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1788 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1789 CHECK_EQ(isolate->heap()->false_value(), *result); 1789 CHECK_EQ(isolate->heap()->false_value(), *result);
1790 } 1790 }
1791 1791
1792 TEST(AllocateJSPromise) { 1792 TEST(AllocateAndInitJSPromise) {
1793 Isolate* isolate(CcTest::InitIsolateOnce()); 1793 Isolate* isolate(CcTest::InitIsolateOnce());
1794 1794
1795 const int kNumParams = 1; 1795 const int kNumParams = 1;
1796 CodeAssemblerTester data(isolate, kNumParams); 1796 CodeAssemblerTester data(isolate, kNumParams);
1797 CodeStubAssembler m(data.state()); 1797 PromiseBuiltinsAssembler m(data.state());
1798 1798
1799 Node* const context = m.Parameter(kNumParams + 2); 1799 Node* const context = m.Parameter(kNumParams + 2);
1800 Node* const promise = m.AllocateJSPromise(context); 1800 Node* const promise = m.AllocateAndInitJSPromise(context);
1801 m.PromiseInit(promise);
1802 m.Return(promise); 1801 m.Return(promise);
1803 1802
1804 Handle<Code> code = data.GenerateCode(); 1803 Handle<Code> code = data.GenerateCode();
1805 CHECK(!code.is_null());
1806
1807 FunctionTester ft(code, kNumParams);
1808 Handle<Object> result =
1809 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1810 CHECK(result->IsJSPromise());
1811 }
1812
1813 TEST(PromiseInit) {
1814 Isolate* isolate(CcTest::InitIsolateOnce());
1815
1816 const int kNumParams = 1;
1817 CodeAssemblerTester data(isolate, kNumParams);
1818 CodeStubAssembler m(data.state());
1819
1820 Node* const context = m.Parameter(kNumParams + 2);
1821 Node* const promise = m.AllocateJSPromise(context);
1822 m.PromiseInit(promise);
1823 m.Return(promise);
1824
1825 Handle<Code> code = data.GenerateCode();
1826 CHECK(!code.is_null()); 1804 CHECK(!code.is_null());
1827 1805
1828 FunctionTester ft(code, kNumParams); 1806 FunctionTester ft(code, kNumParams);
1829 Handle<Object> result = 1807 Handle<Object> result =
1830 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1808 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1831 CHECK(result->IsJSPromise()); 1809 CHECK(result->IsJSPromise());
1832 Handle<JSPromise> js_promise = Handle<JSPromise>::cast(result);
1833 CHECK_EQ(v8::Promise::kPending, js_promise->status());
1834 CHECK_EQ(isolate->heap()->undefined_value(), js_promise->result());
1835 CHECK(!js_promise->has_handler());
1836 } 1810 }
1837 1811
1838 TEST(PromiseSet) { 1812 TEST(AllocateAndSetJSPromise) {
1839 Isolate* isolate(CcTest::InitIsolateOnce()); 1813 Isolate* isolate(CcTest::InitIsolateOnce());
1840 1814
1841 const int kNumParams = 1; 1815 const int kNumParams = 1;
1842 CodeAssemblerTester data(isolate, kNumParams); 1816 CodeAssemblerTester data(isolate, kNumParams);
1843 CodeStubAssembler m(data.state()); 1817 PromiseBuiltinsAssembler m(data.state());
1844 1818
1845 Node* const context = m.Parameter(kNumParams + 2); 1819 Node* const context = m.Parameter(kNumParams + 2);
1846 Node* const promise = m.AllocateJSPromise(context); 1820 Node* const promise = m.AllocateAndSetJSPromise(
1847 m.PromiseSet(promise, m.SmiConstant(v8::Promise::kPending), m.SmiConstant(1)); 1821 context, m.SmiConstant(v8::Promise::kPending), m.SmiConstant(1));
1848 m.Return(promise); 1822 m.Return(promise);
1849 1823
1850 Handle<Code> code = data.GenerateCode(); 1824 Handle<Code> code = data.GenerateCode();
1851 CHECK(!code.is_null()); 1825 CHECK(!code.is_null());
1852 1826
1853 FunctionTester ft(code, kNumParams); 1827 FunctionTester ft(code, kNumParams);
1854 Handle<Object> result = 1828 Handle<Object> result =
1855 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1829 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1856 CHECK(result->IsJSPromise()); 1830 CHECK(result->IsJSPromise());
1857 Handle<JSPromise> js_promise = Handle<JSPromise>::cast(result); 1831 Handle<JSPromise> js_promise = Handle<JSPromise>::cast(result);
1858 CHECK_EQ(v8::Promise::kPending, js_promise->status()); 1832 CHECK_EQ(v8::Promise::kPending, js_promise->status());
1859 CHECK_EQ(Smi::FromInt(1), js_promise->result()); 1833 CHECK_EQ(Smi::FromInt(1), js_promise->result());
1860 CHECK(!js_promise->has_handler()); 1834 CHECK(!js_promise->has_handler());
1861 } 1835 }
1862 1836
1863 TEST(AllocatePromiseReactionJobInfo) { 1837 TEST(AllocatePromiseReactionJobInfo) {
1864 Isolate* isolate(CcTest::InitIsolateOnce()); 1838 Isolate* isolate(CcTest::InitIsolateOnce());
1865 1839
1866 const int kNumParams = 1; 1840 const int kNumParams = 1;
1867 CodeAssemblerTester data(isolate, kNumParams); 1841 CodeAssemblerTester data(isolate, kNumParams);
1868 CodeStubAssembler m(data.state()); 1842 CodeStubAssembler m(data.state());
1843 PromiseBuiltinsAssembler p(data.state());
1869 1844
1870 Node* const context = m.Parameter(kNumParams + 2); 1845 Node* const context = m.Parameter(kNumParams + 2);
1871 Node* const promise = m.AllocateJSPromise(context); 1846 Node* const promise = p.AllocateAndInitJSPromise(context);
1872 m.PromiseInit(promise);
1873 Node* const tasks = m.AllocateFixedArray(FAST_ELEMENTS, m.IntPtrConstant(1)); 1847 Node* const tasks = m.AllocateFixedArray(FAST_ELEMENTS, m.IntPtrConstant(1));
1874 m.StoreFixedArrayElement(tasks, 0, m.UndefinedConstant()); 1848 m.StoreFixedArrayElement(tasks, 0, m.UndefinedConstant());
1875 Node* const deferred_promise = 1849 Node* const deferred_promise =
1876 m.AllocateFixedArray(FAST_ELEMENTS, m.IntPtrConstant(1)); 1850 m.AllocateFixedArray(FAST_ELEMENTS, m.IntPtrConstant(1));
1877 m.StoreFixedArrayElement(deferred_promise, 0, m.UndefinedConstant()); 1851 m.StoreFixedArrayElement(deferred_promise, 0, m.UndefinedConstant());
1878 Node* const info = m.AllocatePromiseReactionJobInfo( 1852 Node* const info = m.AllocatePromiseReactionJobInfo(
1879 promise, m.SmiConstant(1), tasks, deferred_promise, m.UndefinedConstant(), 1853 promise, m.SmiConstant(1), tasks, deferred_promise, m.UndefinedConstant(),
1880 m.UndefinedConstant(), context); 1854 m.UndefinedConstant(), context);
1881 m.Return(info); 1855 m.Return(info);
1882 1856
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1948 } 1922 }
1949 1923
1950 TEST(PromiseHasHandler) { 1924 TEST(PromiseHasHandler) {
1951 Isolate* isolate(CcTest::InitIsolateOnce()); 1925 Isolate* isolate(CcTest::InitIsolateOnce());
1952 1926
1953 const int kNumParams = 1; 1927 const int kNumParams = 1;
1954 CodeAssemblerTester data(isolate, kNumParams); 1928 CodeAssemblerTester data(isolate, kNumParams);
1955 PromiseBuiltinsAssembler m(data.state()); 1929 PromiseBuiltinsAssembler m(data.state());
1956 1930
1957 Node* const context = m.Parameter(kNumParams + 2); 1931 Node* const context = m.Parameter(kNumParams + 2);
1958 Node* const promise = m.AllocateJSPromise(context); 1932 Node* const promise =
1959 m.PromiseInit(promise); 1933 m.AllocateAndInitJSPromise(context, m.UndefinedConstant());
1960 m.Return(m.SelectBooleanConstant(m.PromiseHasHandler(promise))); 1934 m.Return(m.SelectBooleanConstant(m.PromiseHasHandler(promise)));
1961 1935
1962 Handle<Code> code = data.GenerateCode(); 1936 Handle<Code> code = data.GenerateCode();
1963 CHECK(!code.is_null()); 1937 CHECK(!code.is_null());
1964 1938
1965 FunctionTester ft(code, kNumParams); 1939 FunctionTester ft(code, kNumParams);
1966 Handle<Object> result = 1940 Handle<Object> result =
1967 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1941 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1968 CHECK_EQ(isolate->heap()->false_value(), *result); 1942 CHECK_EQ(isolate->heap()->false_value(), *result);
1969 } 1943 }
1970 1944
1971 TEST(CreatePromiseResolvingFunctionsContext) { 1945 TEST(CreatePromiseResolvingFunctionsContext) {
1972 Isolate* isolate(CcTest::InitIsolateOnce()); 1946 Isolate* isolate(CcTest::InitIsolateOnce());
1973 1947
1974 const int kNumParams = 1; 1948 const int kNumParams = 1;
1975 CodeAssemblerTester data(isolate, kNumParams); 1949 CodeAssemblerTester data(isolate, kNumParams);
1976 PromiseBuiltinsAssembler m(data.state()); 1950 PromiseBuiltinsAssembler m(data.state());
1977 1951
1978 Node* const context = m.Parameter(kNumParams + 2); 1952 Node* const context = m.Parameter(kNumParams + 2);
1979 Node* const native_context = m.LoadNativeContext(context); 1953 Node* const native_context = m.LoadNativeContext(context);
1980 Node* const promise = m.AllocateJSPromise(context); 1954 Node* const promise =
1981 m.PromiseSet(promise, m.SmiConstant(v8::Promise::kPending), m.SmiConstant(1)); 1955 m.AllocateAndInitJSPromise(context, m.UndefinedConstant());
1982 Node* const promise_context = m.CreatePromiseResolvingFunctionsContext( 1956 Node* const promise_context = m.CreatePromiseResolvingFunctionsContext(
1983 promise, m.BooleanConstant(false), native_context); 1957 promise, m.BooleanConstant(false), native_context);
1984 m.Return(promise_context); 1958 m.Return(promise_context);
1985 1959
1986 Handle<Code> code = data.GenerateCode(); 1960 Handle<Code> code = data.GenerateCode();
1987 CHECK(!code.is_null()); 1961 CHECK(!code.is_null());
1988 1962
1989 FunctionTester ft(code, kNumParams); 1963 FunctionTester ft(code, kNumParams);
1990 Handle<Object> result = 1964 Handle<Object> result =
1991 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1965 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
(...skipping 10 matching lines...) Expand all
2002 1976
2003 TEST(CreatePromiseResolvingFunctions) { 1977 TEST(CreatePromiseResolvingFunctions) {
2004 Isolate* isolate(CcTest::InitIsolateOnce()); 1978 Isolate* isolate(CcTest::InitIsolateOnce());
2005 1979
2006 const int kNumParams = 1; 1980 const int kNumParams = 1;
2007 CodeAssemblerTester data(isolate, kNumParams); 1981 CodeAssemblerTester data(isolate, kNumParams);
2008 PromiseBuiltinsAssembler m(data.state()); 1982 PromiseBuiltinsAssembler m(data.state());
2009 1983
2010 Node* const context = m.Parameter(kNumParams + 2); 1984 Node* const context = m.Parameter(kNumParams + 2);
2011 Node* const native_context = m.LoadNativeContext(context); 1985 Node* const native_context = m.LoadNativeContext(context);
2012 Node* const promise = m.AllocateJSPromise(context); 1986 Node* const promise =
2013 m.PromiseSet(promise, m.SmiConstant(v8::Promise::kPending), m.SmiConstant(1)); 1987 m.AllocateAndInitJSPromise(context, m.UndefinedConstant());
2014 Node *resolve, *reject; 1988 Node *resolve, *reject;
2015 std::tie(resolve, reject) = m.CreatePromiseResolvingFunctions( 1989 std::tie(resolve, reject) = m.CreatePromiseResolvingFunctions(
2016 promise, m.BooleanConstant(false), native_context); 1990 promise, m.BooleanConstant(false), native_context);
2017 Node* const kSize = m.IntPtrConstant(2); 1991 Node* const kSize = m.IntPtrConstant(2);
2018 Node* const arr = m.AllocateFixedArray(FAST_ELEMENTS, kSize); 1992 Node* const arr = m.AllocateFixedArray(FAST_ELEMENTS, kSize);
2019 m.StoreFixedArrayElement(arr, 0, resolve); 1993 m.StoreFixedArrayElement(arr, 0, resolve);
2020 m.StoreFixedArrayElement(arr, 1, reject); 1994 m.StoreFixedArrayElement(arr, 1, reject);
2021 m.Return(arr); 1995 m.Return(arr);
2022 1996
2023 Handle<Code> code = data.GenerateCode(); 1997 Handle<Code> code = data.GenerateCode();
(...skipping 10 matching lines...) Expand all
2034 2008
2035 TEST(AllocateFunctionWithMapAndContext) { 2009 TEST(AllocateFunctionWithMapAndContext) {
2036 Isolate* isolate(CcTest::InitIsolateOnce()); 2010 Isolate* isolate(CcTest::InitIsolateOnce());
2037 2011
2038 const int kNumParams = 1; 2012 const int kNumParams = 1;
2039 CodeAssemblerTester data(isolate, kNumParams); 2013 CodeAssemblerTester data(isolate, kNumParams);
2040 PromiseBuiltinsAssembler m(data.state()); 2014 PromiseBuiltinsAssembler m(data.state());
2041 2015
2042 Node* const context = m.Parameter(kNumParams + 2); 2016 Node* const context = m.Parameter(kNumParams + 2);
2043 Node* const native_context = m.LoadNativeContext(context); 2017 Node* const native_context = m.LoadNativeContext(context);
2044 Node* const promise = m.AllocateJSPromise(context); 2018 Node* const promise =
2045 m.PromiseSet(promise, m.SmiConstant(v8::Promise::kPending), m.SmiConstant(1)); 2019 m.AllocateAndInitJSPromise(context, m.UndefinedConstant());
2046 Node* promise_context = m.CreatePromiseResolvingFunctionsContext( 2020 Node* promise_context = m.CreatePromiseResolvingFunctionsContext(
2047 promise, m.BooleanConstant(false), native_context); 2021 promise, m.BooleanConstant(false), native_context);
2048 Node* resolve_info = 2022 Node* resolve_info =
2049 m.LoadContextElement(native_context, Context::PROMISE_RESOLVE_SHARED_FUN); 2023 m.LoadContextElement(native_context, Context::PROMISE_RESOLVE_SHARED_FUN);
2050 Node* const map = m.LoadContextElement( 2024 Node* const map = m.LoadContextElement(
2051 native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); 2025 native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
2052 Node* const resolve = 2026 Node* const resolve =
2053 m.AllocateFunctionWithMapAndContext(map, resolve_info, promise_context); 2027 m.AllocateFunctionWithMapAndContext(map, resolve_info, promise_context);
2054 m.Return(resolve); 2028 m.Return(resolve);
2055 2029
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 .ToHandleChecked(); 2188 .ToHandleChecked();
2215 Handle<Object> prop2 = 2189 Handle<Object> prop2 =
2216 JSReceiver::GetProperty(isolate, promise, "rejectedReason") 2190 JSReceiver::GetProperty(isolate, promise, "rejectedReason")
2217 .ToHandleChecked(); 2191 .ToHandleChecked();
2218 CHECK_EQ(*rejected_str, *prop2); 2192 CHECK_EQ(*rejected_str, *prop2);
2219 } 2193 }
2220 } 2194 }
2221 2195
2222 } // namespace internal 2196 } // namespace internal
2223 } // namespace v8 2197 } // namespace v8
OLDNEW
« no previous file with comments | « src/code-stub-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698