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/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "test/cctest/compiler/code-assembler-tester.h" | 10 #include "test/cctest/compiler/code-assembler-tester.h" |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 | 1992 |
1993 isolate->EnablePromiseHook(); | 1993 isolate->EnablePromiseHook(); |
1994 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); | 1994 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
1995 CHECK_EQ(isolate->heap()->true_value(), *result); | 1995 CHECK_EQ(isolate->heap()->true_value(), *result); |
1996 | 1996 |
1997 isolate->DisablePromiseHook(); | 1997 isolate->DisablePromiseHook(); |
1998 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); | 1998 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
1999 CHECK_EQ(isolate->heap()->false_value(), *result); | 1999 CHECK_EQ(isolate->heap()->false_value(), *result); |
2000 } | 2000 } |
2001 | 2001 |
| 2002 TEST(AllocateJSPromise) { |
| 2003 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 2004 |
| 2005 const int kNumParams = 1; |
| 2006 CodeAssemblerTester data(isolate, kNumParams); |
| 2007 CodeStubAssembler m(data.state()); |
| 2008 |
| 2009 Node* const context = m.Parameter(kNumParams + 2); |
| 2010 Node* const promise = m.AllocateJSPromise(context); |
| 2011 m.Return(promise); |
| 2012 |
| 2013 Handle<Code> code = data.GenerateCode(); |
| 2014 CHECK(!code.is_null()); |
| 2015 |
| 2016 FunctionTester ft(code, kNumParams); |
| 2017 Handle<Object> result = |
| 2018 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
| 2019 CHECK(result->IsJSPromise()); |
| 2020 } |
| 2021 |
| 2022 TEST(PromiseInit) { |
| 2023 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 2024 |
| 2025 const int kNumParams = 1; |
| 2026 CodeAssemblerTester data(isolate, kNumParams); |
| 2027 CodeStubAssembler m(data.state()); |
| 2028 |
| 2029 Node* const context = m.Parameter(kNumParams + 2); |
| 2030 Node* const promise = m.AllocateJSPromise(context); |
| 2031 m.PromiseInit(promise); |
| 2032 m.Return(promise); |
| 2033 |
| 2034 Handle<Code> code = data.GenerateCode(); |
| 2035 CHECK(!code.is_null()); |
| 2036 |
| 2037 FunctionTester ft(code, kNumParams); |
| 2038 Handle<Object> result = |
| 2039 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
| 2040 CHECK(result->IsJSPromise()); |
| 2041 Handle<JSPromise> js_promise = Handle<JSPromise>::cast(result); |
| 2042 CHECK_EQ(kPromisePending, js_promise->status()); |
| 2043 CHECK_EQ(isolate->heap()->undefined_value(), js_promise->result()); |
| 2044 CHECK(!js_promise->has_handler()); |
| 2045 } |
| 2046 |
| 2047 TEST(PromiseSet) { |
| 2048 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 2049 |
| 2050 const int kNumParams = 1; |
| 2051 CodeAssemblerTester data(isolate, kNumParams); |
| 2052 CodeStubAssembler m(data.state()); |
| 2053 |
| 2054 Node* const context = m.Parameter(kNumParams + 2); |
| 2055 Node* const promise = m.AllocateJSPromise(context); |
| 2056 m.PromiseSet(promise, m.SmiConstant(kPromisePending), m.SmiConstant(1)); |
| 2057 m.Return(promise); |
| 2058 |
| 2059 Handle<Code> code = data.GenerateCode(); |
| 2060 CHECK(!code.is_null()); |
| 2061 |
| 2062 FunctionTester ft(code, kNumParams); |
| 2063 Handle<Object> result = |
| 2064 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
| 2065 CHECK(result->IsJSPromise()); |
| 2066 Handle<JSPromise> js_promise = Handle<JSPromise>::cast(result); |
| 2067 CHECK_EQ(kPromisePending, js_promise->status()); |
| 2068 CHECK_EQ(Smi::FromInt(1), js_promise->result()); |
| 2069 CHECK(!js_promise->has_handler()); |
| 2070 } |
| 2071 |
2002 } // namespace internal | 2072 } // namespace internal |
2003 } // namespace v8 | 2073 } // namespace v8 |
OLD | NEW |