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

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

Issue 1611313003: Revert of Array length reduction should throw in strict mode if it can't delete an element. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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/x87/code-stubs-x87.cc ('k') | test/mjsunit/regress/regress-4267.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12774 matching lines...) Expand 10 before | Expand all | Expand 10 after
12785 // Check that 'h' cannot be shadowed. 12785 // Check that 'h' cannot be shadowed.
12786 value = v8_compile("o.h = 3; o.h")->Run(context.local()).ToLocalChecked(); 12786 value = v8_compile("o.h = 3; o.h")->Run(context.local()).ToLocalChecked();
12787 CHECK_EQ(1, value->Int32Value(context.local()).FromJust()); 12787 CHECK_EQ(1, value->Int32Value(context.local()).FromJust());
12788 12788
12789 // Check that 'i' cannot be shadowed or changed. 12789 // Check that 'i' cannot be shadowed or changed.
12790 value = v8_compile("o.i = 3; o.i")->Run(context.local()).ToLocalChecked(); 12790 value = v8_compile("o.i = 3; o.i")->Run(context.local()).ToLocalChecked();
12791 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); 12791 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
12792 } 12792 }
12793 12793
12794 12794
12795 static void ShouldThrowOnErrorGetter(
12796 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
12797 ApiTestFuzzer::Fuzz();
12798 v8::Isolate* isolate = info.GetIsolate();
12799 Local<Boolean> should_throw_on_error =
12800 Boolean::New(isolate, info.ShouldThrowOnError());
12801 info.GetReturnValue().Set(should_throw_on_error);
12802 }
12803
12804
12805 template <typename T>
12806 static void ShouldThrowOnErrorSetter(Local<Name> name, Local<v8::Value> value,
12807 const v8::PropertyCallbackInfo<T>& info) {
12808 ApiTestFuzzer::Fuzz();
12809 v8::Isolate* isolate = info.GetIsolate();
12810 auto context = isolate->GetCurrentContext();
12811 Local<Boolean> should_throw_on_error_value =
12812 Boolean::New(isolate, info.ShouldThrowOnError());
12813 CHECK(context->Global()
12814 ->Set(isolate->GetCurrentContext(), v8_str("should_throw_setter"),
12815 should_throw_on_error_value)
12816 .FromJust());
12817 }
12818
12819
12820 THREADED_TEST(AccessorShouldThrowOnError) {
12821 i::FLAG_strong_mode = true;
12822 LocalContext context;
12823 v8::Isolate* isolate = context->GetIsolate();
12824 v8::HandleScope scope(isolate);
12825 Local<Object> global = context->Global();
12826
12827 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
12828 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
12829 instance_templ->SetAccessor(v8_str("f"), ShouldThrowOnErrorGetter,
12830 ShouldThrowOnErrorSetter<void>);
12831
12832 Local<v8::Object> instance = templ->GetFunction(context.local())
12833 .ToLocalChecked()
12834 ->NewInstance(context.local())
12835 .ToLocalChecked();
12836
12837 CHECK(global->Set(context.local(), v8_str("o"), instance).FromJust());
12838
12839 // SLOPPY mode
12840 Local<Value> value = v8_compile("o.f")->Run(context.local()).ToLocalChecked();
12841 CHECK(value->IsFalse());
12842 v8_compile("o.f = 153")->Run(context.local()).ToLocalChecked();
12843 value = global->Get(context.local(), v8_str("should_throw_setter"))
12844 .ToLocalChecked();
12845 CHECK(value->IsFalse());
12846
12847 // STRICT mode
12848 value = v8_compile("'use strict';o.f")->Run(context.local()).ToLocalChecked();
12849 CHECK(value->IsFalse());
12850 v8_compile("'use strict'; o.f = 153")->Run(context.local()).ToLocalChecked();
12851 value = global->Get(context.local(), v8_str("should_throw_setter"))
12852 .ToLocalChecked();
12853 CHECK(value->IsTrue());
12854
12855 // STRONG mode
12856 value = v8_compile("'use strong';o.f")->Run(context.local()).ToLocalChecked();
12857 CHECK(value->IsFalse());
12858 v8_compile("'use strong'; o.f = 153")->Run(context.local()).ToLocalChecked();
12859 value = global->Get(context.local(), v8_str("should_throw_setter"))
12860 .ToLocalChecked();
12861 CHECK(value->IsTrue());
12862 }
12863
12864
12865 static void ShouldThrowOnErrorQuery(
12866 Local<Name> name, const v8::PropertyCallbackInfo<v8::Integer>& info) {
12867 ApiTestFuzzer::Fuzz();
12868 v8::Isolate* isolate = info.GetIsolate();
12869 info.GetReturnValue().Set(v8::None);
12870
12871 auto context = isolate->GetCurrentContext();
12872 Local<Boolean> should_throw_on_error_value =
12873 Boolean::New(isolate, info.ShouldThrowOnError());
12874 CHECK(context->Global()
12875 ->Set(isolate->GetCurrentContext(), v8_str("should_throw_query"),
12876 should_throw_on_error_value)
12877 .FromJust());
12878 }
12879
12880
12881 static void ShouldThrowOnErrorDeleter(
12882 Local<Name> name, const v8::PropertyCallbackInfo<v8::Boolean>& info) {
12883 ApiTestFuzzer::Fuzz();
12884 v8::Isolate* isolate = info.GetIsolate();
12885 info.GetReturnValue().Set(v8::True(isolate));
12886
12887 auto context = isolate->GetCurrentContext();
12888 Local<Boolean> should_throw_on_error_value =
12889 Boolean::New(isolate, info.ShouldThrowOnError());
12890 CHECK(context->Global()
12891 ->Set(isolate->GetCurrentContext(), v8_str("should_throw_deleter"),
12892 should_throw_on_error_value)
12893 .FromJust());
12894 }
12895
12896
12897 static void ShouldThrowOnErrorPropertyEnumerator(
12898 const v8::PropertyCallbackInfo<v8::Array>& info) {
12899 ApiTestFuzzer::Fuzz();
12900 v8::Isolate* isolate = info.GetIsolate();
12901 Local<v8::Array> names = v8::Array::New(isolate, 1);
12902 CHECK(names->Set(isolate->GetCurrentContext(), names, v8_num(1)).FromJust());
12903 info.GetReturnValue().Set(names);
12904
12905 auto context = isolate->GetCurrentContext();
12906 Local<Boolean> should_throw_on_error_value =
12907 Boolean::New(isolate, info.ShouldThrowOnError());
12908 CHECK(context->Global()
12909 ->Set(isolate->GetCurrentContext(),
12910 v8_str("should_throw_enumerator"),
12911 should_throw_on_error_value)
12912 .FromJust());
12913 }
12914
12915
12916 THREADED_TEST(InterceptorShouldThrowOnError) {
12917 i::FLAG_strong_mode = true;
12918 LocalContext context;
12919 v8::Isolate* isolate = context->GetIsolate();
12920 v8::HandleScope scope(isolate);
12921 Local<Object> global = context->Global();
12922
12923 auto interceptor_templ = v8::ObjectTemplate::New(isolate);
12924 v8::NamedPropertyHandlerConfiguration handler(
12925 ShouldThrowOnErrorGetter, ShouldThrowOnErrorSetter<Value>,
12926 ShouldThrowOnErrorQuery, ShouldThrowOnErrorDeleter,
12927 ShouldThrowOnErrorPropertyEnumerator);
12928 interceptor_templ->SetHandler(handler);
12929
12930 Local<v8::Object> instance =
12931 interceptor_templ->NewInstance(context.local()).ToLocalChecked();
12932
12933 CHECK(global->Set(context.local(), v8_str("o"), instance).FromJust());
12934
12935 // SLOPPY mode
12936 Local<Value> value = v8_compile("o.f")->Run(context.local()).ToLocalChecked();
12937 CHECK(value->IsFalse());
12938 v8_compile("o.f = 153")->Run(context.local()).ToLocalChecked();
12939 value = global->Get(context.local(), v8_str("should_throw_setter"))
12940 .ToLocalChecked();
12941 CHECK(value->IsFalse());
12942
12943 v8_compile("delete o.f")->Run(context.local()).ToLocalChecked();
12944 value = global->Get(context.local(), v8_str("should_throw_deleter"))
12945 .ToLocalChecked();
12946 CHECK(value->IsFalse());
12947
12948 v8_compile("Object.getOwnPropertyNames(o)")
12949 ->Run(context.local())
12950 .ToLocalChecked();
12951 value = global->Get(context.local(), v8_str("should_throw_enumerator"))
12952 .ToLocalChecked();
12953 CHECK(value->IsFalse());
12954
12955 // STRICT mode
12956 value = v8_compile("'use strict';o.f")->Run(context.local()).ToLocalChecked();
12957 CHECK(value->IsFalse());
12958 v8_compile("'use strict'; o.f = 153")->Run(context.local()).ToLocalChecked();
12959 value = global->Get(context.local(), v8_str("should_throw_setter"))
12960 .ToLocalChecked();
12961 CHECK(value->IsTrue());
12962
12963 v8_compile("'use strict'; delete o.f")->Run(context.local()).ToLocalChecked();
12964 value = global->Get(context.local(), v8_str("should_throw_deleter"))
12965 .ToLocalChecked();
12966 CHECK(value->IsTrue());
12967
12968 v8_compile("'use strict'; Object.getOwnPropertyNames(o)")
12969 ->Run(context.local())
12970 .ToLocalChecked();
12971 value = global->Get(context.local(), v8_str("should_throw_enumerator"))
12972 .ToLocalChecked();
12973 CHECK(value->IsFalse());
12974
12975 // STRONG mode
12976 value = v8_compile("'use strong';o.f")->Run(context.local()).ToLocalChecked();
12977 CHECK(value->IsFalse());
12978 v8_compile("'use strong'; o.f = 153")->Run(context.local()).ToLocalChecked();
12979 value = global->Get(context.local(), v8_str("should_throw_setter"))
12980 .ToLocalChecked();
12981 CHECK(value->IsTrue());
12982
12983 v8_compile("'use strong'; Object.getOwnPropertyNames(o)")
12984 ->Run(context.local())
12985 .ToLocalChecked();
12986 value = global->Get(context.local(), v8_str("should_throw_enumerator"))
12987 .ToLocalChecked();
12988 CHECK(value->IsFalse());
12989 }
12990
12991
12992 static void IsConstructHandler( 12795 static void IsConstructHandler(
12993 const v8::FunctionCallbackInfo<v8::Value>& args) { 12796 const v8::FunctionCallbackInfo<v8::Value>& args) {
12994 ApiTestFuzzer::Fuzz(); 12797 ApiTestFuzzer::Fuzz();
12995 args.GetReturnValue().Set(args.IsConstructCall()); 12798 args.GetReturnValue().Set(args.IsConstructCall());
12996 } 12799 }
12997 12800
12998 12801
12999 THREADED_TEST(IsConstructCall) { 12802 THREADED_TEST(IsConstructCall) {
13000 v8::Isolate* isolate = CcTest::isolate(); 12803 v8::Isolate* isolate = CcTest::isolate();
13001 v8::HandleScope scope(isolate); 12804 v8::HandleScope scope(isolate);
(...skipping 11637 matching lines...) Expand 10 before | Expand all | Expand 10 after
24639 CHECK(proxy->GetTarget()->SameValue(target)); 24442 CHECK(proxy->GetTarget()->SameValue(target));
24640 CHECK(proxy->GetHandler()->SameValue(handler)); 24443 CHECK(proxy->GetHandler()->SameValue(handler));
24641 24444
24642 proxy->Revoke(); 24445 proxy->Revoke();
24643 CHECK(proxy->IsProxy()); 24446 CHECK(proxy->IsProxy());
24644 CHECK(!target->IsProxy()); 24447 CHECK(!target->IsProxy());
24645 CHECK(proxy->IsRevoked()); 24448 CHECK(proxy->IsRevoked());
24646 CHECK(proxy->GetTarget()->SameValue(target)); 24449 CHECK(proxy->GetTarget()->SameValue(target));
24647 CHECK(proxy->GetHandler()->IsNull()); 24450 CHECK(proxy->GetHandler()->IsNull());
24648 } 24451 }
OLDNEW
« no previous file with comments | « src/x87/code-stubs-x87.cc ('k') | test/mjsunit/regress/regress-4267.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698