Index: test/cctest/interpreter/test-interpreter.cc |
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc |
index 099c84a7955396ea132b963cc90bb4483a5973f3..f935fecef3bc381c8e0174a975ddf2b91b248b95 100644 |
--- a/test/cctest/interpreter/test-interpreter.cc |
+++ b/test/cctest/interpreter/test-interpreter.cc |
@@ -2028,3 +2028,125 @@ TEST(InterpreterTryFinally) { |
Handle<Object> return_val = callable().ToHandleChecked(); |
CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); |
} |
+ |
+ |
+TEST(InterpreterDeleteProperty) { |
+ HandleAndZoneScope handles; |
+ i::Isolate* isolate = handles.main_isolate(); |
+ i::Factory* factory = isolate->factory(); |
+ |
+ std::pair<const char*, Handle<Object>> test_local_delete[] = { |
+ std::make_pair( |
+ "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n", |
+ factory->undefined_value()), |
+ std::make_pair( |
+ "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.y;\n", |
+ factory->NewStringFromStaticChars("abc")), |
+ std::make_pair("var a = { x:10, y:'abc', z:30.2}; var b = a; delete b.x; " |
+ "return a.x;\n", |
+ factory->undefined_value()), |
+ std::make_pair("var a = { x:10, y:'abc', z:30.2}; var b = a; delete b.x; " |
+ "return a.y;\n", |
+ factory->NewStringFromStaticChars("abc"))}; |
+ |
+ for (size_t i = 0; i < arraysize(test_local_delete); i++) { |
+ std::string source( |
+ InterpreterTester::SourceForBody(test_local_delete[i].first)); |
+ InterpreterTester tester(handles.main_isolate(), source.c_str()); |
+ auto callable = tester.GetCallable<>(); |
+ |
+ Handle<i::Object> return_value = callable().ToHandleChecked(); |
+ CHECK(return_value->SameValue(*test_local_delete[i].second)); |
+ } |
+ |
+ for (size_t i = 0; i < arraysize(test_local_delete); i++) { |
+ std::string strict_test = |
+ "'use strict'; " + std::string(test_local_delete[i].first); |
+ std::string source(InterpreterTester::SourceForBody(strict_test.c_str())); |
+ InterpreterTester tester(handles.main_isolate(), source.c_str()); |
+ auto callable = tester.GetCallable<>(); |
+ |
+ Handle<i::Object> return_value = callable().ToHandleChecked(); |
+ CHECK(return_value->SameValue(*test_local_delete[i].second)); |
+ } |
+ |
+ 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.
|
+ std::make_pair("var a = { x:10, y:'abc', z:30.2};\n" |
+ "function f() {\n" |
+ " delete a.x;\n" |
+ " return a.x;}\n" |
+ "f();\n", |
+ factory->undefined_value()), |
+ std::make_pair("var a = { x:10, y:'abc', z:30.2};\n" |
+ "function f() {delete a.y; return a.x;} f();\n", |
+ Handle<Object>(Smi::FromInt(10), isolate)), |
+ std::make_pair("var a = { x:10, y:'abc', z:30.2};\n" |
+ "function f() {var b = a; delete b.y; return b.x;} f();\n", |
+ Handle<Object>(Smi::FromInt(10), isolate)), |
+ std::make_pair("function f() {\n" |
+ "var a = { x:10, y:'abc', z:30.2};\n" |
+ "var b = a;" |
+ "delete b.x;" |
+ "return b.x;} f();\n", |
+ factory->undefined_value())}; |
+ |
+ for (size_t i = 0; i < arraysize(test_global_delete); i++) { |
+ InterpreterTester tester(handles.main_isolate(), |
+ test_global_delete[i].first); |
+ auto callable = tester.GetCallable<>(); |
+ |
+ Handle<i::Object> return_value = callable().ToHandleChecked(); |
+ CHECK(return_value->SameValue(*test_global_delete[i].second)); |
+ } |
+} |
+ |
+ |
+TEST(InterpreterDeleteVariable) { |
+ HandleAndZoneScope handles; |
+ i::Isolate* isolate = handles.main_isolate(); |
+ i::Factory* factory = isolate->factory(); |
+ // TODO(mythria) When try-catch is implemented change the tests to check |
+ // if delete actually deletes |
+ std::pair<const char*, Handle<Object>> test_delete[] = { |
+ std::make_pair("function f() {\n" |
+ " var a = { x:10, y:'abc'};\n" |
+ " var b = delete a;\n" |
+ " a.x = a.x + !b;\n" |
+ " return a.x;}\n" |
+ "f();\n", |
+ Handle<Object>(Smi::FromInt(11), isolate)), |
+ std::make_pair("function f() {\n" |
+ " a = { x:10, y:'abc'};\n" |
+ " var b = delete a;\n" |
+ //" try{return a.x;} catch(e) {return b;}\n" |
+ " return b;};" |
+ "f();\n", |
+ factory->ToBoolean(true)), |
+ std::make_pair("function f() {\n" |
+ " a = { x:10, y:'abc'};\n" |
+ " var b = delete c;\n" |
+ " return b;};" |
+ "f();\n", |
+ factory->ToBoolean(true)), |
+ std::make_pair("var a = { x:10, y:'abc'};\n" |
+ "function f() {\n" |
+ " var b = delete a;\n" |
+ " return b;};" |
+ "f();\n", |
+ factory->ToBoolean(true)), |
+ std::make_pair("var a = { x:10};\n" |
+ "function f() {\n" |
+ " 'use strict';" |
+ " return delete this;\n" |
+ "};" |
+ "f(a);\n", |
+ factory->ToBoolean(true))}; |
+ |
+ for (size_t i = 0; i < arraysize(test_delete); i++) { |
+ InterpreterTester tester(handles.main_isolate(), test_delete[i].first); |
+ auto callable = tester.GetCallable<>(); |
+ |
+ Handle<i::Object> return_value = callable().ToHandleChecked(); |
+ CHECK(return_value->SameValue(*test_delete[i].second)); |
+ } |
+} |