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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1412953007: [Interpreter] Fill out function prologue support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 3059 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 3070 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
3071 }; 3071 };
3072 3072
3073 for (size_t i = 0; i < arraysize(snippets); i++) { 3073 for (size_t i = 0; i < arraysize(snippets); i++) {
3074 Handle<BytecodeArray> bytecode_array = 3074 Handle<BytecodeArray> bytecode_array =
3075 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 3075 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
3076 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3076 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3077 } 3077 }
3078 } 3078 }
3079 3079
3080
3081 TEST(CreateArguments) {
3082 InitializedHandleScope handle_scope;
3083 BytecodeGeneratorHelper helper;
3084 Zone zone;
3085
3086 int closure = Register::function_closure().index();
3087 int first_context_slot = Context::MIN_CONTEXT_SLOTS;
3088
3089 FeedbackVectorSpec feedback_spec(&zone);
3090 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot();
3091
3092 Handle<i::TypeFeedbackVector> vector =
3093 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
3094
3095 ExpectedSnippet<const char*> snippets[] = {
3096 {"function f() { return arguments; }",
3097 1 * kPointerSize,
3098 1,
3099 6,
3100 {
3101 B(CreateArgumentsSloppy), //
3102 B(Star), R(0), //
3103 B(Ldar), R(0), //
3104 B(Return), //
3105 }},
3106 {"function f() { return arguments[0]; }",
3107 2 * kPointerSize,
3108 1,
3109 12,
3110 {
3111 B(CreateArgumentsSloppy), //
3112 B(Star), R(0), //
3113 B(Ldar), R(0), //
3114 B(Star), R(1), //
3115 B(LdaZero), //
3116 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot)), //
3117 B(Return), //
3118 }},
3119 {"function f() { 'use strict'; return arguments; }",
3120 1 * kPointerSize,
3121 1,
3122 8,
3123 {
3124 B(CreateArgumentsStrict), //
3125 B(Star), R(0), //
3126 B(LdaConstant), U8(0), //
3127 B(Ldar), R(0), //
3128 B(Return), //
3129 },
3130 1,
3131 {"use strict"}},
3132 {"function f(a) { return arguments[0]; }",
3133 3 * kPointerSize,
3134 2,
3135 24,
3136 {
3137 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
3138 U8(1), //
3139 B(PushContext), R(1), //
3140 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), //
3141 B(StaContextSlot), R(1), U8(first_context_slot), //
3142 B(CreateArgumentsSloppy), //
3143 B(Star), R(0), //
3144 B(Ldar), R(0), //
3145 B(Star), R(2), //
3146 B(LdaZero), //
3147 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), //
3148 B(Return), //
3149 }},
3150 {"function f(a, b, c) { return arguments; }",
3151 2 * kPointerSize,
3152 4,
3153 28,
3154 {
3155 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
3156 U8(1), //
3157 B(PushContext), R(1), //
3158 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 2), //
3159 B(StaContextSlot), R(1), U8(first_context_slot + 2), //
3160 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 1), //
3161 B(StaContextSlot), R(1), U8(first_context_slot + 1), //
3162 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), //
3163 B(StaContextSlot), R(1), U8(first_context_slot), //
3164 B(CreateArgumentsSloppy), //
3165 B(Star), R(0), //
3166 B(Ldar), R(0), //
3167 B(Return), //
3168 }},
3169 {"function f(a, b, c) { 'use strict'; return arguments; }",
3170 1 * kPointerSize,
3171 4,
3172 8,
3173 {
3174 B(CreateArgumentsStrict), //
3175 B(Star), R(0), //
3176 B(LdaConstant), U8(0), //
3177 B(Ldar), R(0), //
3178 B(Return), //
3179 },
3180 1,
3181 {"use strict"}},
3182 };
3183
3184 for (size_t i = 0; i < arraysize(snippets); i++) {
3185 Handle<BytecodeArray> bytecode_array =
3186 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
3187 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3188 }
3189 }
3190
3191
3192 TEST(IllegalRedeclaration) {
3193 InitializedHandleScope handle_scope;
3194 BytecodeGeneratorHelper helper;
3195
3196 ExpectedSnippet<const char*> snippets[] = {
3197 {"const a = 1; { var a = 2; }",
3198 3 * kPointerSize,
3199 1,
3200 14,
3201 {
3202 B(LdaSmi8), U8(MessageTemplate::kVarRedeclaration), //
3203 B(Star), R(1), //
3204 B(LdaConstant), U8(0), //
3205 B(Star), R(2), //
3206 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), //
3207 B(Throw), //
3208 },
3209 1,
3210 {"a"}},
3211 };
3212
3213 for (size_t i = 0; i < arraysize(snippets); i++) {
3214 Handle<BytecodeArray> bytecode_array =
3215 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3216 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3217 }
3218 }
3219
3080 } // namespace interpreter 3220 } // namespace interpreter
3081 } // namespace internal 3221 } // namespace internal
3082 } // namespace v8 3222 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698