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

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

Issue 1386313005: [Interpreter] Adds Object literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_literal_2
Patch Set: Rebase and review comments Created 5 years, 2 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/interpreter/interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | 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/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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 // Structure for containing expected bytecode snippets. 89 // Structure for containing expected bytecode snippets.
90 template<typename T> 90 template<typename T>
91 struct ExpectedSnippet { 91 struct ExpectedSnippet {
92 const char* code_snippet; 92 const char* code_snippet;
93 int frame_size; 93 int frame_size;
94 int parameter_count; 94 int parameter_count;
95 int bytecode_length; 95 int bytecode_length;
96 const uint8_t bytecode[512]; 96 const uint8_t bytecode[512];
97 int constant_count; 97 int constant_count;
98 T constants[4]; 98 T constants[6];
99 }; 99 };
100 100
101 101
102 static void CheckConstant(int expected, Object* actual) { 102 static void CheckConstant(int expected, Object* actual) {
103 CHECK_EQ(expected, Smi::cast(actual)->value()); 103 CHECK_EQ(expected, Smi::cast(actual)->value());
104 } 104 }
105 105
106 106
107 static void CheckConstant(double expected, Object* actual) { 107 static void CheckConstant(double expected, Object* actual) {
108 CHECK_EQ(expected, HeapNumber::cast(actual)->value()); 108 CHECK_EQ(expected, HeapNumber::cast(actual)->value());
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 B(ToBoolean), // 1231 B(ToBoolean), //
1232 B(JumpIfFalse), U8(7), // 1232 B(JumpIfFalse), U8(7), //
1233 B(LdaSmi8), U8(1), // 1233 B(LdaSmi8), U8(1), //
1234 B(Return), // 1234 B(Return), //
1235 B(Jump), U8(5), // 1235 B(Jump), U8(5), //
1236 B(LdaSmi8), U8(-1), // 1236 B(LdaSmi8), U8(-1), //
1237 B(Return), // 1237 B(Return), //
1238 B(LdaUndefined), // 1238 B(LdaUndefined), //
1239 B(Return)}, // 1239 B(Return)}, //
1240 0, 1240 0,
1241 {unused, unused, unused, unused}}, 1241 {unused, unused, unused, unused, unused, unused}},
1242 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();", 1242 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();",
1243 0, 1243 0,
1244 1, 1244 1,
1245 15, 1245 15,
1246 {B(LdaConstant), U8(0), // 1246 {B(LdaConstant), U8(0), //
1247 B(ToBoolean), // 1247 B(ToBoolean), //
1248 B(JumpIfFalse), U8(7), // 1248 B(JumpIfFalse), U8(7), //
1249 B(LdaSmi8), U8(1), // 1249 B(LdaSmi8), U8(1), //
1250 B(Return), // 1250 B(Return), //
1251 B(Jump), U8(5), // 1251 B(Jump), U8(5), //
1252 B(LdaSmi8), U8(-1), // 1252 B(LdaSmi8), U8(-1), //
1253 B(Return), // 1253 B(Return), //
1254 B(LdaUndefined), // 1254 B(LdaUndefined), //
1255 B(Return)}, // 1255 B(Return)}, //
1256 1, 1256 1,
1257 {helper.factory()->NewStringFromStaticChars("lucky"), unused, unused, 1257 {helper.factory()->NewStringFromStaticChars("lucky"), unused, unused,
1258 unused}}, 1258 unused, unused, unused}},
1259 {"function f() { if (false) { return 1; } else { return -1; } } f();", 1259 {"function f() { if (false) { return 1; } else { return -1; } } f();",
1260 0, 1260 0,
1261 1, 1261 1,
1262 13, 1262 13,
1263 {B(LdaFalse), // 1263 {B(LdaFalse), //
1264 B(JumpIfFalse), U8(7), // 1264 B(JumpIfFalse), U8(7), //
1265 B(LdaSmi8), U8(1), // 1265 B(LdaSmi8), U8(1), //
1266 B(Return), // 1266 B(Return), //
1267 B(Jump), U8(5), // 1267 B(Jump), U8(5), //
1268 B(LdaSmi8), U8(-1), // 1268 B(LdaSmi8), U8(-1), //
1269 B(Return), // 1269 B(Return), //
1270 B(LdaUndefined), // 1270 B(LdaUndefined), //
1271 B(Return)}, // 1271 B(Return)}, //
1272 0, 1272 0,
1273 {unused, unused, unused, unused}}, 1273 {unused, unused, unused, unused, unused, unused}},
1274 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" 1274 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }"
1275 "f(99);", 1275 "f(99);",
1276 kPointerSize, 1276 kPointerSize,
1277 2, 1277 2,
1278 19, 1278 19,
1279 {B(Ldar), R(helper.kLastParamIndex), // 1279 {B(Ldar), R(helper.kLastParamIndex), //
1280 B(Star), R(0), // 1280 B(Star), R(0), //
1281 B(LdaZero), // 1281 B(LdaZero), //
1282 B(TestLessThanOrEqual), R(0), // 1282 B(TestLessThanOrEqual), R(0), //
1283 B(JumpIfFalse), U8(7), // 1283 B(JumpIfFalse), U8(7), //
1284 B(LdaConstant), U8(0), // 1284 B(LdaConstant), U8(0), //
1285 B(Return), // 1285 B(Return), //
1286 B(Jump), U8(5), // 1286 B(Jump), U8(5), //
1287 B(LdaConstant), U8(1), // 1287 B(LdaConstant), U8(1), //
1288 B(Return), // 1288 B(Return), //
1289 B(LdaUndefined), // 1289 B(LdaUndefined), //
1290 B(Return)}, // 1290 B(Return)}, //
1291 2, 1291 2,
1292 {helper.factory()->NewNumberFromInt(200), 1292 {helper.factory()->NewNumberFromInt(200),
1293 helper.factory()->NewNumberFromInt(-200), unused, unused}}, 1293 helper.factory()->NewNumberFromInt(-200), unused, unused, unused,
1294 unused}},
1294 {"function f(a, b) { if (a in b) { return 200; } }" 1295 {"function f(a, b) { if (a in b) { return 200; } }"
1295 "f('prop', { prop: 'yes'});", 1296 "f('prop', { prop: 'yes'});",
1296 kPointerSize, 1297 kPointerSize,
1297 3, 1298 3,
1298 15, 1299 15,
1299 {B(Ldar), R(helper.kLastParamIndex - 1), // 1300 {B(Ldar), R(helper.kLastParamIndex - 1), //
1300 B(Star), R(0), // 1301 B(Star), R(0), //
1301 B(Ldar), R(helper.kLastParamIndex), // 1302 B(Ldar), R(helper.kLastParamIndex), //
1302 B(TestIn), R(0), // 1303 B(TestIn), R(0), //
1303 B(JumpIfFalse), U8(5), // 1304 B(JumpIfFalse), U8(5), //
1304 B(LdaConstant), U8(0), // 1305 B(LdaConstant), U8(0), //
1305 B(Return), // 1306 B(Return), //
1306 B(LdaUndefined), // 1307 B(LdaUndefined), //
1307 B(Return)}, // 1308 B(Return)}, //
1308 1, 1309 1,
1309 {helper.factory()->NewNumberFromInt(200), unused, unused, unused}}, 1310 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused,
1311 unused}},
1310 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " 1312 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { "
1311 #define X "b = a; a = b; " 1313 #define X "b = a; a = b; "
1312 X X X X X X X X X X X X X X X X X X X X X X X X 1314 X X X X X X X X X X X X X X X X X X X X X X X X
1313 #undef X 1315 #undef X
1314 " return 200; } else { return -200; } } f(0.001)", 1316 " return 200; } else { return -200; } } f(0.001)",
1315 3 * kPointerSize, 1317 3 * kPointerSize,
1316 2, 1318 2,
1317 218, 1319 218,
1318 {B(LdaZero), // 1320 {B(LdaZero), //
1319 B(Star), R(0), // 1321 B(Star), R(0), //
(...skipping 11 matching lines...) Expand all
1331 B(Return), // 1333 B(Return), //
1332 B(Jump), U8(5), // 1334 B(Jump), U8(5), //
1333 B(LdaConstant), U8(3), // 1335 B(LdaConstant), U8(3), //
1334 B(Return), // 1336 B(Return), //
1335 B(LdaUndefined), // 1337 B(LdaUndefined), //
1336 B(Return)}, // 1338 B(Return)}, //
1337 4, 1339 4,
1338 {helper.factory()->NewHeapNumber(0.01), 1340 {helper.factory()->NewHeapNumber(0.01),
1339 helper.factory()->NewNumberFromInt(200), 1341 helper.factory()->NewNumberFromInt(200),
1340 helper.factory()->NewNumberFromInt(199), 1342 helper.factory()->NewNumberFromInt(199),
1341 helper.factory()->NewNumberFromInt(-200)}}, 1343 helper.factory()->NewNumberFromInt(-200),
1344 unused, unused}},
1342 {"function f(a, b) {\n" 1345 {"function f(a, b) {\n"
1343 " if (a == b) { return 1; }\n" 1346 " if (a == b) { return 1; }\n"
1344 " if (a === b) { return 1; }\n" 1347 " if (a === b) { return 1; }\n"
1345 " if (a < b) { return 1; }\n" 1348 " if (a < b) { return 1; }\n"
1346 " if (a > b) { return 1; }\n" 1349 " if (a > b) { return 1; }\n"
1347 " if (a <= b) { return 1; }\n" 1350 " if (a <= b) { return 1; }\n"
1348 " if (a >= b) { return 1; }\n" 1351 " if (a >= b) { return 1; }\n"
1349 " if (a in b) { return 1; }\n" 1352 " if (a in b) { return 1; }\n"
1350 " if (a instanceof b) { return 1; }\n" 1353 " if (a instanceof b) { return 1; }\n"
1351 " /* if (a != b) { return 1; } */" // TODO(oth) Ast visitor yields 1354 " /* if (a != b) { return 1; } */" // TODO(oth) Ast visitor yields
(...skipping 17 matching lines...) Expand all
1369 IF_CONDITION_RETURN(TestLessThan) // 1372 IF_CONDITION_RETURN(TestLessThan) //
1370 IF_CONDITION_RETURN(TestGreaterThan) // 1373 IF_CONDITION_RETURN(TestGreaterThan) //
1371 IF_CONDITION_RETURN(TestLessThanOrEqual) // 1374 IF_CONDITION_RETURN(TestLessThanOrEqual) //
1372 IF_CONDITION_RETURN(TestGreaterThanOrEqual) // 1375 IF_CONDITION_RETURN(TestGreaterThanOrEqual) //
1373 IF_CONDITION_RETURN(TestIn) // 1376 IF_CONDITION_RETURN(TestIn) //
1374 IF_CONDITION_RETURN(TestInstanceOf) // 1377 IF_CONDITION_RETURN(TestInstanceOf) //
1375 #undef IF_CONDITION_RETURN 1378 #undef IF_CONDITION_RETURN
1376 B(LdaZero), // 1379 B(LdaZero), //
1377 B(Return)}, // 1380 B(Return)}, //
1378 0, 1381 0,
1379 {unused, unused, unused, unused}}, 1382 {unused, unused, unused, unused, unused, unused}},
1380 }; 1383 };
1381 1384
1382 for (size_t i = 0; i < arraysize(snippets); i++) { 1385 for (size_t i = 0; i < arraysize(snippets); i++) {
1383 Handle<BytecodeArray> bytecode_array = 1386 Handle<BytecodeArray> bytecode_array =
1384 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 1387 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
1385 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1388 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1386 } 1389 }
1387 } 1390 }
1388 1391
1389 1392
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 InstanceType::FIXED_ARRAY_TYPE}}, 2047 InstanceType::FIXED_ARRAY_TYPE}},
2045 }; 2048 };
2046 2049
2047 for (size_t i = 0; i < arraysize(snippets); i++) { 2050 for (size_t i = 0; i < arraysize(snippets); i++) {
2048 Handle<BytecodeArray> bytecode_array = 2051 Handle<BytecodeArray> bytecode_array =
2049 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2052 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2050 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2053 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2051 } 2054 }
2052 } 2055 }
2053 2056
2057
2058 TEST(ObjectLiterals) {
2059 InitializedHandleScope handle_scope;
2060 BytecodeGeneratorHelper helper;
2061
2062 int simple_flags = ObjectLiteral::kFastElements |
2063 ObjectLiteral::kShallowProperties |
2064 ObjectLiteral::kDisableMementos;
2065 int deep_elements_flags =
2066 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
2067 ExpectedSnippet<InstanceType> snippets[] = {
2068 {"return { };",
2069 0,
2070 1,
2071 6,
2072 {
2073 B(LdaConstant), U8(0), //
2074 B(CreateObjectLiteral), U8(0), U8(simple_flags), //
2075 B(Return) //
2076 },
2077 1,
2078 {InstanceType::FIXED_ARRAY_TYPE}},
2079 {"return { name: 'string', val: 9.2 };",
2080 0,
2081 1,
2082 6,
2083 {
2084 B(LdaConstant), U8(0), //
2085 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2086 B(Return) //
2087 },
2088 1,
2089 {InstanceType::FIXED_ARRAY_TYPE}},
2090 {"var a = 1; return { name: 'string', val: a };",
2091 3 * kPointerSize,
2092 1,
2093 24,
2094 {
2095 B(LdaSmi8), U8(1), //
2096 B(Star), R(0), //
2097 B(LdaConstant), U8(0), //
2098 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2099 B(Star), R(1), //
2100 B(LdaConstant), U8(1), //
2101 B(Star), R(2), //
2102 B(Ldar), R(0), //
2103 B(StoreICSloppy), R(1), R(2), U8(3), //
2104 B(Ldar), R(1), //
2105 B(Return), //
2106 },
2107 2,
2108 {InstanceType::FIXED_ARRAY_TYPE,
2109 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2110 {"var a = 1; return { val: a, val: a + 1 };",
2111 4 * kPointerSize,
2112 1,
2113 32,
2114 {
2115 B(LdaSmi8), U8(1), //
2116 B(Star), R(0), //
2117 B(LdaConstant), U8(0), //
2118 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2119 B(Star), R(1), //
2120 B(Ldar), R(0), //
2121 B(LdaConstant), U8(1), //
2122 B(Star), R(2), //
2123 B(Ldar), R(0), //
2124 B(Star), R(3), //
2125 B(LdaSmi8), U8(1), //
2126 B(Add), R(3), //
2127 B(StoreICSloppy), R(1), R(2), U8(3), //
2128 B(Ldar), R(1), //
2129 B(Return), //
2130 },
2131 2,
2132 {InstanceType::FIXED_ARRAY_TYPE,
2133 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2134 {"return { func: function() { } };",
2135 2 * kPointerSize,
2136 1,
2137 22,
2138 {
2139 B(LdaConstant), U8(0), //
2140 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2141 B(Star), R(0), //
2142 B(LdaConstant), U8(1), //
2143 B(Star), R(1), //
2144 B(LdaConstant), U8(2), //
2145 B(CreateClosure), U8(0), //
2146 B(StoreICSloppy), R(0), R(1), U8(3), //
2147 B(Ldar), R(0), //
2148 B(Return), //
2149 },
2150 3,
2151 {InstanceType::FIXED_ARRAY_TYPE,
2152 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2153 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2154 {"return { func(a) { return a; } };",
2155 2 * kPointerSize,
2156 1,
2157 22,
2158 {
2159 B(LdaConstant), U8(0), //
2160 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2161 B(Star), R(0), //
2162 B(LdaConstant), U8(1), //
2163 B(Star), R(1), //
2164 B(LdaConstant), U8(2), //
2165 B(CreateClosure), U8(0), //
2166 B(StoreICSloppy), R(0), R(1), U8(3), //
2167 B(Ldar), R(0), //
2168 B(Return), //
2169 },
2170 3,
2171 {InstanceType::FIXED_ARRAY_TYPE,
2172 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2173 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2174 {"return { get a() { return 2; } };",
2175 5 * kPointerSize,
2176 1,
2177 31,
2178 {
2179 B(LdaConstant), U8(0), //
2180 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2181 B(Star), R(0), //
2182 B(LdaConstant), U8(1), //
2183 B(Star), R(1), //
2184 B(LdaConstant), U8(2), //
2185 B(CreateClosure), U8(0), //
2186 B(Star), R(2), //
2187 B(LdaNull), //
2188 B(Star), R(3), //
2189 B(LdaZero), //
2190 B(Star), R(4), //
2191 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2192 R(0), U8(5), //
2193 B(Ldar), R(0), //
2194 B(Return), //
2195 },
2196 3,
2197 {InstanceType::FIXED_ARRAY_TYPE,
2198 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2199 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2200 {"return { get a() { return this.x; }, set a(val) { this.x = val } };",
2201 5 * kPointerSize,
2202 1,
2203 34,
2204 {
2205 B(LdaConstant), U8(0), //
2206 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2207 B(Star), R(0), //
2208 B(LdaConstant), U8(1), //
2209 B(Star), R(1), //
2210 B(LdaConstant), U8(2), //
2211 B(CreateClosure), U8(0), //
2212 B(Star), R(2), //
2213 B(LdaConstant), U8(3), //
2214 B(CreateClosure), U8(0), //
2215 B(Star), R(3), //
2216 B(LdaZero), //
2217 B(Star), R(4), //
2218 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2219 R(0), U8(5), //
2220 B(Ldar), R(0), //
2221 B(Return), //
2222 },
2223 4,
2224 {InstanceType::FIXED_ARRAY_TYPE,
2225 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2226 InstanceType::SHARED_FUNCTION_INFO_TYPE,
2227 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2228 {"return { get a() { return this.x; }, set b(val) { this.y = val } };",
2229 5 * kPointerSize,
2230 1,
2231 52,
2232 {
2233 B(LdaConstant), U8(0), //
2234 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2235 B(Star), R(0), //
2236 B(LdaConstant), U8(1), //
2237 B(Star), R(1), //
2238 B(LdaConstant), U8(2), //
2239 B(CreateClosure), U8(0), //
2240 B(Star), R(2), //
2241 B(LdaNull), //
2242 B(Star), R(3), //
2243 B(LdaZero), //
2244 B(Star), R(4), //
2245 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2246 R(0), U8(5), //
2247 B(LdaConstant), U8(3), //
2248 B(Star), R(1), //
2249 B(LdaNull), //
2250 B(Star), R(2), //
2251 B(LdaConstant), U8(4), //
2252 B(CreateClosure), U8(0), //
2253 B(Star), R(3), //
2254 B(LdaZero), //
2255 B(Star), R(4), //
2256 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2257 R(0), U8(5), //
2258 B(Ldar), R(0), //
2259 B(Return), //
2260 },
2261 5,
2262 {InstanceType::FIXED_ARRAY_TYPE,
2263 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2264 InstanceType::SHARED_FUNCTION_INFO_TYPE,
2265 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2266 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2267 {"var a = 1; return { 1: a };",
2268 5 * kPointerSize,
2269 1,
2270 30,
2271 {
2272 B(LdaSmi8), U8(1), //
2273 B(Star), R(0), //
2274 B(LdaConstant), U8(0), //
2275 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2276 B(Star), R(1), //
2277 B(LdaSmi8), U8(1), //
2278 B(Star), R(2), //
2279 B(Ldar), R(0), //
2280 B(Star), R(3), //
2281 B(LdaZero), //
2282 B(Star), R(4), //
2283 B(CallRuntime), U16(Runtime::kSetProperty), R(1), U8(4), //
2284 B(Ldar), R(1), //
2285 B(Return), //
2286 },
2287 1,
2288 {InstanceType::FIXED_ARRAY_TYPE}},
2289 {"return { __proto__: null }",
2290 2 * kPointerSize,
2291 1,
2292 18,
2293 {
2294 B(LdaConstant), U8(0), //
2295 B(CreateObjectLiteral), U8(0), U8(simple_flags), //
2296 B(Star), R(0), //
2297 B(LdaNull), B(Star), R(1), //
2298 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(0), U8(2), //
2299 B(Ldar), R(0), //
2300 B(Return), //
2301 },
2302 1,
2303 {InstanceType::FIXED_ARRAY_TYPE}},
2304 {"var a = 'test'; return { [a]: 1 }",
2305 5 * kPointerSize,
2306 1,
2307 31,
2308 {
2309 B(LdaConstant), U8(0), //
2310 B(Star), R(0), //
2311 B(LdaConstant), U8(1), //
2312 B(CreateObjectLiteral), U8(0), U8(simple_flags), //
2313 B(Star), R(1), //
2314 B(Ldar), R(0), //
2315 B(ToName), //
2316 B(Star), R(2), //
2317 B(LdaSmi8), U8(1), //
2318 B(Star), R(3), //
2319 B(LdaZero), //
2320 B(Star), R(4), //
2321 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2322 U8(4), //
2323 B(Ldar), R(1), //
2324 B(Return), //
2325 },
2326 2,
2327 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2328 InstanceType::FIXED_ARRAY_TYPE}},
2329 {"var a = 'test'; return { val: a, [a]: 1 }",
2330 5 * kPointerSize,
2331 1,
2332 41,
2333 {
2334 B(LdaConstant), U8(0), //
2335 B(Star), R(0), //
2336 B(LdaConstant), U8(1), //
2337 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2338 B(Star), R(1), //
2339 B(LdaConstant), U8(2), //
2340 B(Star), R(2), //
2341 B(Ldar), R(0), //
2342 B(StoreICSloppy), R(1), R(2), U8(3), //
2343 B(Ldar), R(0), //
2344 B(ToName), //
2345 B(Star), R(2), //
2346 B(LdaSmi8), U8(1), //
2347 B(Star), R(3), //
2348 B(LdaZero), //
2349 B(Star), R(4), //
2350 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2351 U8(4), //
2352 B(Ldar), R(1), //
2353 B(Return), //
2354 },
2355 3,
2356 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2357 InstanceType::FIXED_ARRAY_TYPE,
2358 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2359 {"var a = 'test'; return { [a]: 1, __proto__: {} }",
2360 5 * kPointerSize,
2361 1,
2362 43,
2363 {
2364 B(LdaConstant), U8(0), //
2365 B(Star), R(0), //
2366 B(LdaConstant), U8(1), //
2367 B(CreateObjectLiteral), U8(1), U8(simple_flags), //
2368 B(Star), R(1), //
2369 B(Ldar), R(0), //
2370 B(ToName), //
2371 B(Star), R(2), //
2372 B(LdaSmi8), U8(1), //
2373 B(Star), R(3), //
2374 B(LdaZero), //
2375 B(Star), R(4), //
2376 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2377 U8(4), //
2378 B(LdaConstant), U8(1), //
2379 B(CreateObjectLiteral), U8(0), U8(13), //
2380 B(Star), R(2), //
2381 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(1), U8(2), //
2382 B(Ldar), R(1), //
2383 B(Return), //
2384 },
2385 2,
2386 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2387 InstanceType::FIXED_ARRAY_TYPE}},
2388 {"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };",
2389 5 * kPointerSize,
2390 1,
2391 69,
2392 {
2393 B(LdaConstant), U8(0), //
2394 B(Star), R(0), //
2395 B(LdaConstant), U8(1), //
2396 B(CreateObjectLiteral), U8(0), U8(simple_flags), //
2397 B(Star), R(1), //
2398 B(Ldar), R(0), //
2399 B(ToName), //
2400 B(Star), R(2), //
2401 B(LdaConstant), U8(2), //
2402 B(Star), R(3), //
2403 B(LdaZero), //
2404 B(Star), R(4), //
2405 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2406 U8(4), //
2407 B(LdaConstant), U8(3), //
2408 B(ToName), //
2409 B(Star), R(2), //
2410 B(LdaConstant), U8(4), //
2411 B(CreateClosure), U8(0), //
2412 B(Star), R(3), //
2413 B(LdaZero), //
2414 B(Star), R(4), //
2415 B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), //
2416 R(1), U8(4), //
2417 B(LdaConstant), U8(3), //
2418 B(ToName), //
2419 B(Star), R(2), //
2420 B(LdaConstant), U8(5), //
2421 B(CreateClosure), U8(0), //
2422 B(Star), R(3), //
2423 B(LdaZero), //
2424 B(Star), R(4), //
2425 B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), //
2426 R(1), U8(4), //
2427 B(Ldar), R(1), //
2428 B(Return), //
2429 },
2430 6,
2431 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2432 InstanceType::FIXED_ARRAY_TYPE,
2433 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2434 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2435 InstanceType::SHARED_FUNCTION_INFO_TYPE,
2436 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2437 };
2438
2439 for (size_t i = 0; i < arraysize(snippets); i++) {
2440 Handle<BytecodeArray> bytecode_array =
2441 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2442 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2443 }
2444 }
2445
2446
2447 TEST(TopLevelObjectLiterals) {
2448 InitializedHandleScope handle_scope;
2449 BytecodeGeneratorHelper helper;
2450
2451 int has_function_flags = ObjectLiteral::kFastElements |
2452 ObjectLiteral::kHasFunction |
2453 ObjectLiteral::kDisableMementos;
2454 ExpectedSnippet<InstanceType> snippets[] = {
2455 {"var a = { func: function() { } };",
2456 7 * kPointerSize,
2457 1,
2458 69,
2459 {
2460 B(Ldar), R(Register::function_closure().index()), //
2461 B(Star), R(2), //
2462 B(LdaConstant), U8(0), //
2463 B(Star), R(3), //
2464 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), //
2465 B(PushContext), R(1), //
2466 B(LdaConstant), U8(1), //
2467 B(Star), R(2), //
2468 B(LdaZero), //
2469 B(Star), R(3), //
2470 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), //
2471 B(LdaConstant), U8(2), //
2472 B(Star), R(2), //
2473 B(LdaZero), //
2474 B(Star), R(3), //
2475 B(LdaConstant), U8(3), //
2476 B(CreateObjectLiteral), U8(0), U8(has_function_flags), //
2477 B(Star), R(5), //
2478 B(LdaConstant), U8(4), //
2479 B(Star), R(6), //
2480 B(LdaConstant), U8(5), //
2481 B(CreateClosure), U8(1), //
2482 B(StoreICSloppy), R(5), R(6), U8(3), //
2483 B(CallRuntime), U16(Runtime::kToFastProperties), R(5), U8(1), //
2484 B(Ldar), R(5), //
2485 B(Star), R(4), //
2486 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), U8(3), //
2487 B(LdaUndefined), //
2488 B(Return), //
2489 },
2490 6,
2491 {InstanceType::FIXED_ARRAY_TYPE,
2492 InstanceType::FIXED_ARRAY_TYPE,
2493 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2494 InstanceType::FIXED_ARRAY_TYPE,
2495 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2496 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2497 };
2498
2499 for (size_t i = 0; i < arraysize(snippets); i++) {
2500 Handle<BytecodeArray> bytecode_array =
2501 helper.MakeTopLevelBytecode(snippets[i].code_snippet);
2502 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2503 }
2504 }
2505
2054 } // namespace interpreter 2506 } // namespace interpreter
2055 } // namespace internal 2507 } // namespace internal
2056 } // namespace v8 2508 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698