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

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

Issue 75035: Change the enumeration order for unsigned integer keys to always be... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 CHECK(v8_compile("delete k[2]")->Run()->IsFalse()); 2918 CHECK(v8_compile("delete k[2]")->Run()->IsFalse());
2919 CHECK(v8_compile("delete k[4]")->Run()->IsTrue()); 2919 CHECK(v8_compile("delete k[4]")->Run()->IsTrue());
2920 2920
2921 CHECK_EQ(v8_compile("k[2]")->Run(), v8_num(2)); 2921 CHECK_EQ(v8_compile("k[2]")->Run(), v8_num(2));
2922 CHECK(v8_compile("k[4]")->Run()->IsUndefined()); 2922 CHECK(v8_compile("k[4]")->Run()->IsUndefined());
2923 } 2923 }
2924 2924
2925 2925
2926 static v8::Handle<Value> GetK(Local<String> name, const AccessorInfo&) { 2926 static v8::Handle<Value> GetK(Local<String> name, const AccessorInfo&) {
2927 ApiTestFuzzer::Fuzz(); 2927 ApiTestFuzzer::Fuzz();
2928 return v8::Undefined(); 2928 if (name->Equals(v8_str("foo")) ||
2929 name->Equals(v8_str("bar")) ||
2930 name->Equals(v8_str("baz"))) {
2931 return v8::Undefined();
2932 }
2933 return v8::Handle<Value>();
2934 }
2935
2936
2937 static v8::Handle<Value> IndexedGetK(uint32_t index, const AccessorInfo&) {
2938 ApiTestFuzzer::Fuzz();
2939 if (index == 0 || index == 1) return v8::Undefined();
2940 return v8::Handle<Value>();
2929 } 2941 }
2930 2942
2931 2943
2932 static v8::Handle<v8::Array> NamedEnum(const AccessorInfo&) { 2944 static v8::Handle<v8::Array> NamedEnum(const AccessorInfo&) {
2933 ApiTestFuzzer::Fuzz(); 2945 ApiTestFuzzer::Fuzz();
2934 v8::Handle<v8::Array> result = v8::Array::New(3); 2946 v8::Handle<v8::Array> result = v8::Array::New(3);
2935 result->Set(v8::Integer::New(0), v8_str("foo")); 2947 result->Set(v8::Integer::New(0), v8_str("foo"));
2936 result->Set(v8::Integer::New(1), v8_str("bar")); 2948 result->Set(v8::Integer::New(1), v8_str("bar"));
2937 result->Set(v8::Integer::New(2), v8_str("baz")); 2949 result->Set(v8::Integer::New(2), v8_str("baz"));
2938 return result; 2950 return result;
2939 } 2951 }
2940 2952
2941 2953
2942 static v8::Handle<v8::Array> IndexedEnum(const AccessorInfo&) { 2954 static v8::Handle<v8::Array> IndexedEnum(const AccessorInfo&) {
2943 ApiTestFuzzer::Fuzz(); 2955 ApiTestFuzzer::Fuzz();
2944 v8::Handle<v8::Array> result = v8::Array::New(2); 2956 v8::Handle<v8::Array> result = v8::Array::New(2);
2945 result->Set(v8::Integer::New(0), v8_str("hat")); 2957 result->Set(v8::Integer::New(0), v8_str("0"));
2946 result->Set(v8::Integer::New(1), v8_str("gyt")); 2958 result->Set(v8::Integer::New(1), v8_str("1"));
2947 return result; 2959 return result;
2948 } 2960 }
2949 2961
2950 2962
2951 THREADED_TEST(Enumerators) { 2963 THREADED_TEST(Enumerators) {
2952 v8::HandleScope scope; 2964 v8::HandleScope scope;
2953 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 2965 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
2954 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 2966 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
2955 obj->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, IndexedEnum); 2967 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum);
2956 LocalContext context; 2968 LocalContext context;
2957 context->Global()->Set(v8_str("k"), obj->NewInstance()); 2969 context->Global()->Set(v8_str("k"), obj->NewInstance());
2958 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 2970 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
2971 "k[10] = 0;"
2972 "k.a = 0;"
2973 "k[5] = 0;"
2974 "k.b = 0;"
2975 "k[4294967295] = 0;"
2976 "k.c = 0;"
2977 "k[4294967296] = 0;"
2978 "k.d = 0;"
2979 "k[140000] = 0;"
2980 "k.e = 0;"
2981 "k[30000000000] = 0;"
2982 "k.f = 0;"
2959 "var result = [];" 2983 "var result = [];"
2960 "for (var prop in k) {" 2984 "for (var prop in k) {"
2961 " result.push(prop);" 2985 " result.push(prop);"
2962 "}" 2986 "}"
2963 "result")); 2987 "result"));
2964 CHECK_EQ(5, result->Length()); 2988 // Check that we get all the property names returned including the
2965 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(0))); 2989 // ones from the enumerators in the right order: indexed properties
2966 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(1))); 2990 // in numerical order, indexed interceptor properties, named
2967 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(2))); 2991 // properties in insertion order, named interceptor properties.
2968 CHECK_EQ(v8_str("hat"), result->Get(v8::Integer::New(3))); 2992 // This order is not mandated by the spec, so this test is just
2969 CHECK_EQ(v8_str("gyt"), result->Get(v8::Integer::New(4))); 2993 // documenting our behavior.
2994 CHECK_EQ(17, result->Length());
2995 // Indexed properties in numerical order.
2996 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(0)));
2997 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(1)));
2998 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(2)));
2999 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(3)));
3000 // Indexed interceptor properties in the order they are returned
3001 // from the enumerator interceptor.
3002 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(4)));
3003 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(5)));
3004 // Named properties in insertion order.
3005 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(6)));
3006 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(7)));
3007 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(8)));
3008 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(9)));
3009 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(10)));
3010 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(11)));
3011 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(12)));
3012 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(13)));
3013 // Named interceptor properties.
3014 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(14)));
3015 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(15)));
3016 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(16)));
2970 } 3017 }
2971 3018
2972 3019
2973 int p_getter_count; 3020 int p_getter_count;
2974 int p_getter_count2; 3021 int p_getter_count2;
2975 3022
2976 3023
2977 static v8::Handle<Value> PGetter(Local<String> name, const AccessorInfo& info) { 3024 static v8::Handle<Value> PGetter(Local<String> name, const AccessorInfo& info) {
2978 ApiTestFuzzer::Fuzz(); 3025 ApiTestFuzzer::Fuzz();
2979 p_getter_count++; 3026 p_getter_count++;
(...skipping 3200 matching lines...) Expand 10 before | Expand all | Expand 10 after
6180 // Check without 'eval' or 'with'. 6227 // Check without 'eval' or 'with'.
6181 v8::Handle<v8::Value> res = 6228 v8::Handle<v8::Value> res =
6182 CompileRun("function f() { x = 42; return x; }; f()"); 6229 CompileRun("function f() { x = 42; return x; }; f()");
6183 // Check with 'eval'. 6230 // Check with 'eval'.
6184 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); 6231 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()");
6185 CHECK_EQ(v8::Integer::New(42), res); 6232 CHECK_EQ(v8::Integer::New(42), res);
6186 // Check with 'with'. 6233 // Check with 'with'.
6187 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); 6234 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()");
6188 CHECK_EQ(v8::Integer::New(42), res); 6235 CHECK_EQ(v8::Integer::New(42), res);
6189 } 6236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698