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

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: 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 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 2021
2022 // TODO(rmcilroy): modify tests when we have real try finally support. 2022 // TODO(rmcilroy): modify tests when we have real try finally support.
2023 std::string source(InterpreterTester::SourceForBody( 2023 std::string source(InterpreterTester::SourceForBody(
2024 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); 2024 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;"));
2025 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2025 InterpreterTester tester(handles.main_isolate(), source.c_str());
2026 auto callable = tester.GetCallable<>(); 2026 auto callable = tester.GetCallable<>();
2027 2027
2028 Handle<Object> return_val = callable().ToHandleChecked(); 2028 Handle<Object> return_val = callable().ToHandleChecked();
2029 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); 2029 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4));
2030 } 2030 }
2031
2032
2033 TEST(InterpreterDeleteProperty) {
2034 HandleAndZoneScope handles;
2035 i::Isolate* isolate = handles.main_isolate();
2036 i::Factory* factory = isolate->factory();
2037
2038 std::pair<const char*, Handle<Object>> test_local_delete[] = {
2039 std::make_pair(
2040 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n",
2041 factory->undefined_value()),
2042 std::make_pair(
2043 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.y;\n",
2044 factory->NewStringFromStaticChars("abc")),
2045 std::make_pair("var a = { x:10, y:'abc', z:30.2}; var b = a; delete b.x; "
2046 "return a.x;\n",
2047 factory->undefined_value()),
2048 std::make_pair("var a = { x:10, y:'abc', z:30.2}; var b = a; delete b.x; "
2049 "return a.y;\n",
2050 factory->NewStringFromStaticChars("abc"))};
2051
2052 for (size_t i = 0; i < arraysize(test_local_delete); i++) {
2053 std::string source(
2054 InterpreterTester::SourceForBody(test_local_delete[i].first));
2055 InterpreterTester tester(handles.main_isolate(), source.c_str());
2056 auto callable = tester.GetCallable<>();
2057
2058 Handle<i::Object> return_value = callable().ToHandleChecked();
2059 CHECK(return_value->SameValue(*test_local_delete[i].second));
2060 }
2061
2062 for (size_t i = 0; i < arraysize(test_local_delete); i++) {
2063 std::string strict_test =
2064 "'use strict'; " + std::string(test_local_delete[i].first);
2065 std::string source(InterpreterTester::SourceForBody(strict_test.c_str()));
2066 InterpreterTester tester(handles.main_isolate(), source.c_str());
2067 auto callable = tester.GetCallable<>();
2068
2069 Handle<i::Object> return_value = callable().ToHandleChecked();
2070 CHECK(return_value->SameValue(*test_local_delete[i].second));
2071 }
2072
2073 std::pair<const char*, Handle<Object>> test_global_delete[] = {
rmcilroy 2015/10/21 14:52:54 Globals are variables, not properties. Personally
mythria 2015/10/23 14:48:01 Done.
2074 std::make_pair("var a = { x:10, y:'abc', z:30.2};\n"
2075 "function f() {\n"
2076 " delete a.x;\n"
2077 " return a.x;}\n"
2078 "f();\n",
2079 factory->undefined_value()),
2080 std::make_pair("var a = { x:10, y:'abc', z:30.2};\n"
2081 "function f() {delete a.y; return a.x;} f();\n",
2082 Handle<Object>(Smi::FromInt(10), isolate)),
2083 std::make_pair("var a = { x:10, y:'abc', z:30.2};\n"
2084 "function f() {var b = a; delete b.y; return b.x;} f();\n",
2085 Handle<Object>(Smi::FromInt(10), isolate)),
2086 std::make_pair("function f() {\n"
2087 "var a = { x:10, y:'abc', z:30.2};\n"
2088 "var b = a;"
2089 "delete b.x;"
2090 "return b.x;} f();\n",
2091 factory->undefined_value())};
2092
2093 for (size_t i = 0; i < arraysize(test_global_delete); i++) {
2094 InterpreterTester tester(handles.main_isolate(),
2095 test_global_delete[i].first);
2096 auto callable = tester.GetCallable<>();
2097
2098 Handle<i::Object> return_value = callable().ToHandleChecked();
2099 CHECK(return_value->SameValue(*test_global_delete[i].second));
2100 }
2101 }
2102
2103
2104 TEST(InterpreterDeleteVariable) {
2105 HandleAndZoneScope handles;
2106 i::Isolate* isolate = handles.main_isolate();
2107 i::Factory* factory = isolate->factory();
2108 // TODO(mythria) When try-catch is implemented change the tests to check
2109 // if delete actually deletes
2110 std::pair<const char*, Handle<Object>> test_delete[] = {
2111 std::make_pair("function f() {\n"
2112 " var a = { x:10, y:'abc'};\n"
2113 " var b = delete a;\n"
2114 " a.x = a.x + !b;\n"
2115 " return a.x;}\n"
2116 "f();\n",
2117 Handle<Object>(Smi::FromInt(11), isolate)),
2118 std::make_pair("function f() {\n"
2119 " a = { x:10, y:'abc'};\n"
2120 " var b = delete a;\n"
2121 //" try{return a.x;} catch(e) {return b;}\n"
2122 " return b;};"
2123 "f();\n",
2124 factory->ToBoolean(true)),
2125 std::make_pair("function f() {\n"
2126 " a = { x:10, y:'abc'};\n"
2127 " var b = delete c;\n"
2128 " return b;};"
2129 "f();\n",
2130 factory->ToBoolean(true)),
2131 std::make_pair("var a = { x:10, y:'abc'};\n"
2132 "function f() {\n"
2133 " var b = delete a;\n"
2134 " return b;};"
2135 "f();\n",
2136 factory->ToBoolean(true)),
2137 std::make_pair("var a = { x:10};\n"
2138 "function f() {\n"
2139 " 'use strict';"
2140 " return delete this;\n"
2141 "};"
2142 "f(a);\n",
2143 factory->ToBoolean(true))};
2144
2145 for (size_t i = 0; i < arraysize(test_delete); i++) {
2146 InterpreterTester tester(handles.main_isolate(), test_delete[i].first);
2147 auto callable = tester.GetCallable<>();
2148
2149 Handle<i::Object> return_value = callable().ToHandleChecked();
2150 CHECK(return_value->SameValue(*test_delete[i].second));
2151 }
2152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698