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

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

Issue 2567033003: [promises] Port CreateResolvingFunctions to TF (Closed)
Patch Set: fix nits Created 4 years 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"
11 #include "src/promise-utils.h"
11 #include "test/cctest/compiler/code-assembler-tester.h" 12 #include "test/cctest/compiler/code-assembler-tester.h"
12 #include "test/cctest/compiler/function-tester.h" 13 #include "test/cctest/compiler/function-tester.h"
13 14
14 namespace v8 { 15 namespace v8 {
15 namespace internal { 16 namespace internal {
16 17
17 using compiler::CodeAssemblerTester; 18 using compiler::CodeAssemblerTester;
18 using compiler::FunctionTester; 19 using compiler::FunctionTester;
19 using compiler::Node; 20 using compiler::Node;
20 using compiler::CodeAssemblerLabel; 21 using compiler::CodeAssemblerLabel;
(...skipping 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 1990
1990 Handle<Code> code = data.GenerateCode(); 1991 Handle<Code> code = data.GenerateCode();
1991 CHECK(!code.is_null()); 1992 CHECK(!code.is_null());
1992 1993
1993 FunctionTester ft(code, kNumParams); 1994 FunctionTester ft(code, kNumParams);
1994 Handle<Object> result = 1995 Handle<Object> result =
1995 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); 1996 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
1996 CHECK_EQ(isolate->heap()->false_value(), *result); 1997 CHECK_EQ(isolate->heap()->false_value(), *result);
1997 } 1998 }
1998 1999
2000 TEST(CreatePromiseResolvingFunctionsContext) {
2001 Isolate* isolate(CcTest::InitIsolateOnce());
2002
2003 const int kNumParams = 1;
2004 CodeAssemblerTester data(isolate, kNumParams);
2005 PromiseBuiltinsAssembler m(data.state());
2006
2007 Node* const context = m.Parameter(kNumParams + 2);
2008 Node* const native_context = m.LoadNativeContext(context);
2009 Node* const promise = m.AllocateJSPromise(context);
2010 m.PromiseSet(promise, m.SmiConstant(kPromisePending), m.SmiConstant(1));
2011 Node* const promise_context = m.CreatePromiseResolvingFunctionsContext(
2012 promise, m.BooleanConstant(false), native_context);
2013 m.Return(promise_context);
2014
2015 Handle<Code> code = data.GenerateCode();
2016 CHECK(!code.is_null());
2017
2018 FunctionTester ft(code, kNumParams);
2019 Handle<Object> result =
2020 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
2021 CHECK(result->IsContext());
2022 Handle<Context> context_js = Handle<Context>::cast(result);
2023 CHECK_EQ(isolate->native_context()->closure(), context_js->closure());
2024 CHECK_EQ(isolate->heap()->the_hole_value(), context_js->extension());
2025 CHECK_EQ(*isolate->native_context(), context_js->native_context());
2026 CHECK_EQ(Smi::FromInt(0), context_js->get(PromiseUtils::kAlreadyVisitedSlot));
2027 CHECK(context_js->get(PromiseUtils::kPromiseSlot)->IsJSPromise());
2028 CHECK_EQ(isolate->heap()->false_value(),
2029 context_js->get(PromiseUtils::kDebugEventSlot));
2030 }
2031
2032 TEST(CreatePromiseResolvingFunctions) {
2033 Isolate* isolate(CcTest::InitIsolateOnce());
2034
2035 const int kNumParams = 1;
2036 CodeAssemblerTester data(isolate, kNumParams);
2037 PromiseBuiltinsAssembler m(data.state());
2038
2039 Node* const context = m.Parameter(kNumParams + 2);
2040 Node* const native_context = m.LoadNativeContext(context);
2041 Node* const promise = m.AllocateJSPromise(context);
2042 m.PromiseSet(promise, m.SmiConstant(kPromisePending), m.SmiConstant(1));
2043 Node *resolve, *reject;
2044 std::tie(resolve, reject) = m.CreatePromiseResolvingFunctions(
2045 promise, m.BooleanConstant(false), native_context);
2046 Node* const kSize = m.IntPtrConstant(2);
2047 Node* const arr = m.AllocateFixedArray(FAST_ELEMENTS, kSize);
2048 m.StoreFixedArrayElement(arr, 0, resolve);
2049 m.StoreFixedArrayElement(arr, 1, reject);
2050 m.Return(arr);
2051
2052 Handle<Code> code = data.GenerateCode();
2053 CHECK(!code.is_null());
2054
2055 FunctionTester ft(code, kNumParams);
2056 Handle<Object> result_obj =
2057 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
2058 CHECK(result_obj->IsFixedArray());
2059 Handle<FixedArray> result_arr = Handle<FixedArray>::cast(result_obj);
2060 CHECK(result_arr->get(0)->IsJSFunction());
2061 CHECK(result_arr->get(1)->IsJSFunction());
2062 }
2063
2064 TEST(AllocateFunctionWithMapAndContext) {
2065 Isolate* isolate(CcTest::InitIsolateOnce());
2066
2067 const int kNumParams = 1;
2068 CodeAssemblerTester data(isolate, kNumParams);
2069 PromiseBuiltinsAssembler m(data.state());
2070
2071 Node* const context = m.Parameter(kNumParams + 2);
2072 Node* const native_context = m.LoadNativeContext(context);
2073 Node* const promise = m.AllocateJSPromise(context);
2074 m.PromiseSet(promise, m.SmiConstant(kPromisePending), m.SmiConstant(1));
2075 Node* promise_context = m.CreatePromiseResolvingFunctionsContext(
2076 promise, m.BooleanConstant(false), native_context);
2077 Node* resolve_info =
2078 m.LoadContextElement(native_context, Context::PROMISE_RESOLVE_SHARED_FUN);
2079 Node* const map = m.LoadContextElement(
2080 native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
2081 Node* const resolve =
2082 m.AllocateFunctionWithMapAndContext(map, resolve_info, promise_context);
2083 m.Return(resolve);
2084
2085 Handle<Code> code = data.GenerateCode();
2086 CHECK(!code.is_null());
2087
2088 FunctionTester ft(code, kNumParams);
2089 Handle<Object> result_obj =
2090 ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
2091 CHECK(result_obj->IsJSFunction());
2092 Handle<JSFunction> fun = Handle<JSFunction>::cast(result_obj);
2093 CHECK_EQ(isolate->heap()->empty_fixed_array(), fun->properties());
2094 CHECK_EQ(isolate->heap()->empty_fixed_array(), fun->elements());
2095 CHECK_EQ(isolate->heap()->empty_literals_array(), fun->literals());
2096 CHECK_EQ(isolate->heap()->the_hole_value(), fun->prototype_or_initial_map());
2097 CHECK_EQ(*isolate->promise_resolve_shared_fun(), fun->shared());
2098 CHECK_EQ(isolate->promise_resolve_shared_fun()->code(), fun->code());
2099 CHECK_EQ(isolate->heap()->undefined_value(), fun->next_function_link());
2100 }
2101
1999 } // namespace internal 2102 } // namespace internal
2000 } // namespace v8 2103 } // 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