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

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

Issue 1410953003: [Interpreter] Adds delete operator to interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added more tests for delete and addressed 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
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/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 }; 2257 };
2258 2258
2259 InterpreterTester tester(handles.main_isolate(), create_args[i].first); 2259 InterpreterTester tester(handles.main_isolate(), create_args[i].first);
2260 auto callable = 2260 auto callable =
2261 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); 2261 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>();
2262 Handle<Object> return_val = 2262 Handle<Object> return_val =
2263 callable(args[0], args[1], args[2]).ToHandleChecked(); 2263 callable(args[0], args[1], args[2]).ToHandleChecked();
2264 CHECK(return_val->SameValue(*args[create_args[i].second])); 2264 CHECK(return_val->SameValue(*args[create_args[i].second]));
2265 } 2265 }
2266 } 2266 }
2267
2268
2269 TEST(InterpreterDelete) {
2270 HandleAndZoneScope handles;
2271 i::Isolate* isolate = handles.main_isolate();
2272 i::Factory* factory = isolate->factory();
2273
2274 // Tests for delete for local variables that work both in strict
2275 // and sloppy modes
2276 std::pair<const char*, Handle<Object>> test_delete[] = {
2277 std::make_pair(
2278 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n",
2279 factory->undefined_value()),
2280 std::make_pair(
2281 "var b = { x:10, y:'abc', z:30.2}; delete b.x; return b.y;\n",
2282 factory->NewStringFromStaticChars("abc")),
2283 std::make_pair("var c = { x:10, y:'abc', z:30.2}; var d = c; delete d.x; "
2284 "return c.x;\n",
2285 factory->undefined_value()),
2286 std::make_pair("var e = { x:10, y:'abc', z:30.2}; var g = e; delete g.x; "
2287 "return e.y;\n",
2288 factory->NewStringFromStaticChars("abc")),
2289 std::make_pair("var a = { x:10, y:'abc', z:30.2};\n"
2290 "var b = a;"
2291 "delete b.x;"
2292 "return b.x;\n",
2293 factory->undefined_value()),
2294 std::make_pair("var a = {1:10};\n"
2295 "(function f1() {return a;});"
2296 "return delete a[1];",
2297 factory->ToBoolean(true))};
2298
rmcilroy 2015/10/26 14:31:07 nit - could you add a test for: - return delete t
mythria 2015/10/27 10:50:48 Done.
2299 // Test delete in sloppy mode
2300 for (size_t i = 0; i < arraysize(test_delete); i++) {
2301 std::string source(
2302 InterpreterTester::SourceForBody(test_delete[i].first));
2303 InterpreterTester tester(handles.main_isolate(), source.c_str());
2304 auto callable = tester.GetCallable<>();
2305
2306 Handle<i::Object> return_value = callable().ToHandleChecked();
2307 CHECK(return_value->SameValue(*test_delete[i].second));
2308 }
2309
2310 // Test delete in strict mode
2311 for (size_t i = 0; i < arraysize(test_delete); i++) {
2312 std::string strict_test =
2313 "'use strict'; " + std::string(test_delete[i].first);
2314 std::string source(InterpreterTester::SourceForBody(strict_test.c_str()));
2315 InterpreterTester tester(handles.main_isolate(), source.c_str());
2316 auto callable = tester.GetCallable<>();
2317
2318 Handle<i::Object> return_value = callable().ToHandleChecked();
2319 CHECK(return_value->SameValue(*test_delete[i].second));
2320 }
2321 }
2322
2323
2324 TEST(InterpreterDeleteSloppy) {
rmcilroy 2015/10/26 14:31:07 nit - How about InterpreterDeleteSloppyUnqualified
mythria 2015/10/27 10:50:48 Done.
2325 HandleAndZoneScope handles;
2326 i::Isolate* isolate = handles.main_isolate();
2327 i::Factory* factory = isolate->factory();
2328
2329 // These tests generate a syntax error for strict mode. We don't
2330 // test for it here.
2331 std::pair<const char*, Handle<Object>> test_delete[] = {
2332 std::make_pair("var a = { x:10, y:'abc'};\n"
2333 "var b = delete a;\n"
2334 "a.x = a.x + !b;\n"
rmcilroy 2015/10/26 14:31:07 this is a bit hard to parse, how about: var a = {
mythria 2015/10/27 10:50:48 Done.
2335 "return a.x;\n",
2336 Handle<Object>(Smi::FromInt(11), isolate)),
2337 // TODO(mythria) When try-catch is implemented change the tests to check
2338 // if delete actually deletes
2339 std::make_pair("a = { x:10, y:'abc'};\n"
2340 "var b = delete a;\n"
2341 // "try{return a.x;} catch(e) {return b;}\n"
2342 "return b;",
2343 factory->ToBoolean(true)),
2344 std::make_pair("a = { x:10, y:'abc'};\n"
2345 "var b = delete c;\n"
2346 "return b;",
2347 factory->ToBoolean(true))};
2348
2349
2350 for (size_t i = 0; i < arraysize(test_delete); i++) {
2351 std::string source(
2352 InterpreterTester::SourceForBody(test_delete[i].first));
2353 InterpreterTester tester(handles.main_isolate(), source.c_str());
2354 auto callable = tester.GetCallable<>();
2355
2356 Handle<i::Object> return_value = callable().ToHandleChecked();
2357 CHECK(return_value->SameValue(*test_delete[i].second));
2358 }
2359 }
2360
2361
2362 TEST(InterpreterGlobalDelete) {
2363 HandleAndZoneScope handles;
2364 i::Isolate* isolate = handles.main_isolate();
2365 i::Factory* factory = isolate->factory();
2366
2367 std::pair<const char*, Handle<Object>> test_global_delete[] = {
2368 std::make_pair("var a = { x:10, y:'abc', z:30.2};\n"
2369 "function f() {\n"
2370 " delete a.x;\n"
2371 " return a.x;}\n"
rmcilroy 2015/10/26 14:31:07 nit - '}' on a newline (throughout)
mythria 2015/10/27 10:50:48 Done.
2372 "f();\n",
2373 factory->undefined_value()),
2374 std::make_pair("var b = {1:10, 2:'abc', 3:30.2};\n"
2375 "function f() {delete b[2]; return b[1];} f();\n",
2376 Handle<Object>(Smi::FromInt(10), isolate)),
2377 std::make_pair("var c = { x:10, y:'abc', z:30.2};\n"
2378 "function f() {var d = c; delete d.y; return d.x;} f();\n",
2379 Handle<Object>(Smi::FromInt(10), isolate)),
2380 std::make_pair("e = { x:10, y:'abc'};\n"
rmcilroy 2015/10/26 14:31:07 nit - space after 'abc'
mythria 2015/10/27 10:50:48 Done.
2381 "function f() {\n"
2382 " return delete e;\n"
2383 "}\n"
2384 "f();\n",
2385 factory->ToBoolean(true)),
2386 std::make_pair("var g = { x:10, y:'abc'};\n"
2387 "function f() {\n"
2388 " var b = delete g;\n"
rmcilroy 2015/10/26 14:31:07 nit - just "return delete g;" to match the one abo
mythria 2015/10/27 10:50:48 Done.
2389 " return b;}\n"
2390 "f();\n",
2391 factory->ToBoolean(false)),
2392 std::make_pair("function f() {\n"
2393 " var obj = {h:10, f1() {return delete this;}};\n"
2394 " return obj.f1();\n"
2395 "}\n"
2396 "f();",
2397 factory->ToBoolean(true)),
2398 std::make_pair("function f() {\n"
2399 " var obj = {h:10,\n"
2400 " f1() {\n"
2401 " 'use strict';\n"
2402 " return delete this.h;}};\n"
2403 " return obj.f1();\n"
2404 "}\n"
2405 "f();",
2406 factory->ToBoolean(true))};
2407
2408 for (size_t i = 0; i < arraysize(test_global_delete); i++) {
2409 InterpreterTester tester(handles.main_isolate(),
2410 test_global_delete[i].first);
2411 auto callable = tester.GetCallable<>();
2412
2413 Handle<i::Object> return_value = callable().ToHandleChecked();
2414 CHECK(return_value->SameValue(*test_global_delete[i].second));
2415 }
2416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698