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

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: rebased the patch 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/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 2317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 2328
2329 for (size_t i = 0; i < arraysize(conditional); i++) { 2329 for (size_t i = 0; i < arraysize(conditional); i++) {
2330 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); 2330 std::string source(InterpreterTester::SourceForBody(conditional[i].first));
2331 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2331 InterpreterTester tester(handles.main_isolate(), source.c_str());
2332 auto callable = tester.GetCallable<>(); 2332 auto callable = tester.GetCallable<>();
2333 2333
2334 Handle<i::Object> return_value = callable().ToHandleChecked(); 2334 Handle<i::Object> return_value = callable().ToHandleChecked();
2335 CHECK(return_value->SameValue(*conditional[i].second)); 2335 CHECK(return_value->SameValue(*conditional[i].second));
2336 } 2336 }
2337 } 2337 }
2338
2339
2340 TEST(InterpreterDelete) {
2341 HandleAndZoneScope handles;
2342 i::Isolate* isolate = handles.main_isolate();
2343 i::Factory* factory = isolate->factory();
2344
2345 // Tests for delete for local variables that work both in strict
2346 // and sloppy modes
2347 std::pair<const char*, Handle<Object>> test_delete[] = {
2348 std::make_pair(
2349 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n",
2350 factory->undefined_value()),
2351 std::make_pair(
2352 "var b = { x:10, y:'abc', z:30.2}; delete b.x; return b.y;\n",
2353 factory->NewStringFromStaticChars("abc")),
2354 std::make_pair("var c = { x:10, y:'abc', z:30.2}; var d = c; delete d.x; "
2355 "return c.x;\n",
2356 factory->undefined_value()),
2357 std::make_pair("var e = { x:10, y:'abc', z:30.2}; var g = e; delete g.x; "
2358 "return e.y;\n",
2359 factory->NewStringFromStaticChars("abc")),
2360 std::make_pair("var a = { x:10, y:'abc', z:30.2};\n"
2361 "var b = a;"
2362 "delete b.x;"
2363 "return b.x;\n",
2364 factory->undefined_value()),
2365 std::make_pair("var a = {1:10};\n"
2366 "(function f1() {return a;});"
2367 "return delete a[1];",
2368 factory->ToBoolean(true)),
2369 std::make_pair("return delete this;", factory->ToBoolean(true)),
2370 std::make_pair("return delete 'test';", factory->ToBoolean(true))};
2371
2372 // Test delete in sloppy mode
2373 for (size_t i = 0; i < arraysize(test_delete); i++) {
2374 std::string source(InterpreterTester::SourceForBody(test_delete[i].first));
2375 InterpreterTester tester(handles.main_isolate(), source.c_str());
2376 auto callable = tester.GetCallable<>();
2377
2378 Handle<i::Object> return_value = callable().ToHandleChecked();
2379 CHECK(return_value->SameValue(*test_delete[i].second));
2380 }
2381
2382 // Test delete in strict mode
2383 for (size_t i = 0; i < arraysize(test_delete); i++) {
2384 std::string strict_test =
2385 "'use strict'; " + std::string(test_delete[i].first);
2386 std::string source(InterpreterTester::SourceForBody(strict_test.c_str()));
2387 InterpreterTester tester(handles.main_isolate(), source.c_str());
2388 auto callable = tester.GetCallable<>();
2389
2390 Handle<i::Object> return_value = callable().ToHandleChecked();
2391 CHECK(return_value->SameValue(*test_delete[i].second));
2392 }
2393 }
2394
2395
2396 TEST(InterpreterDeleteSloppyUnqualifiedIdentifier) {
2397 HandleAndZoneScope handles;
2398 i::Isolate* isolate = handles.main_isolate();
2399 i::Factory* factory = isolate->factory();
2400
2401 // These tests generate a syntax error for strict mode. We don't
2402 // test for it here.
2403 std::pair<const char*, Handle<Object>> test_delete[] = {
2404 std::make_pair("var a = { x:10, y:'abc'};\n"
2405 "var b = delete a;\n"
2406 "if (delete a) {\n"
2407 " return undefined;\n"
2408 "} else {\n"
2409 " return a.x;\n"
2410 "}\n",
2411 Handle<Object>(Smi::FromInt(10), isolate)),
2412 // TODO(mythria) When try-catch is implemented change the tests to check
2413 // if delete actually deletes
2414 std::make_pair("a = { x:10, y:'abc'};\n"
2415 "var b = delete a;\n"
2416 // "try{return a.x;} catch(e) {return b;}\n"
2417 "return b;",
2418 factory->ToBoolean(true)),
2419 std::make_pair("a = { x:10, y:'abc'};\n"
2420 "var b = delete c;\n"
2421 "return b;",
2422 factory->ToBoolean(true))};
2423
2424
2425 for (size_t i = 0; i < arraysize(test_delete); i++) {
2426 std::string source(InterpreterTester::SourceForBody(test_delete[i].first));
2427 InterpreterTester tester(handles.main_isolate(), source.c_str());
2428 auto callable = tester.GetCallable<>();
2429
2430 Handle<i::Object> return_value = callable().ToHandleChecked();
2431 CHECK(return_value->SameValue(*test_delete[i].second));
2432 }
2433 }
2434
2435
2436 TEST(InterpreterGlobalDelete) {
2437 HandleAndZoneScope handles;
2438 i::Isolate* isolate = handles.main_isolate();
2439 i::Factory* factory = isolate->factory();
2440
2441 std::pair<const char*, Handle<Object>> test_global_delete[] = {
2442 std::make_pair("var a = { x:10, y:'abc', z:30.2 };\n"
2443 "function f() {\n"
2444 " delete a.x;\n"
2445 " return a.x;\n"
2446 "}\n"
2447 "f();\n",
2448 factory->undefined_value()),
2449 std::make_pair("var b = {1:10, 2:'abc', 3:30.2 };\n"
2450 "function f() {\n"
2451 " delete b[2];\n"
2452 " return b[1];\n"
2453 " }\n"
2454 "f();\n",
2455 Handle<Object>(Smi::FromInt(10), isolate)),
2456 std::make_pair("var c = { x:10, y:'abc', z:30.2 };\n"
2457 "function f() {\n"
2458 " var d = c;\n"
2459 " delete d.y;\n"
2460 " return d.x;\n"
2461 "}\n"
2462 "f();\n",
2463 Handle<Object>(Smi::FromInt(10), isolate)),
2464 std::make_pair("e = { x:10, y:'abc' };\n"
2465 "function f() {\n"
2466 " return delete e;\n"
2467 "}\n"
2468 "f();\n",
2469 factory->ToBoolean(true)),
2470 std::make_pair("var g = { x:10, y:'abc' };\n"
2471 "function f() {\n"
2472 " return delete g;\n"
2473 "}\n"
2474 "f();\n",
2475 factory->ToBoolean(false)),
2476 std::make_pair("function f() {\n"
2477 " var obj = {h:10, f1() {return delete this;}};\n"
2478 " return obj.f1();\n"
2479 "}\n"
2480 "f();",
2481 factory->ToBoolean(true)),
2482 std::make_pair("function f() {\n"
2483 " var obj = {h:10,\n"
2484 " f1() {\n"
2485 " 'use strict';\n"
2486 " return delete this.h;}};\n"
2487 " return obj.f1();\n"
2488 "}\n"
2489 "f();",
2490 factory->ToBoolean(true))};
2491
2492 for (size_t i = 0; i < arraysize(test_global_delete); i++) {
2493 InterpreterTester tester(handles.main_isolate(),
2494 test_global_delete[i].first);
2495 auto callable = tester.GetCallable<>();
2496
2497 Handle<i::Object> return_value = callable().ToHandleChecked();
2498 CHECK(return_value->SameValue(*test_global_delete[i].second));
2499 }
2500 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698