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

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

Issue 6664001: [Isolates] Merge (7083,7111] from bleeding_edge. (Closed)
Patch Set: Created 9 years, 9 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/x64/stub-cache-x64.cc ('k') | test/mjsunit/regress/regress-1236.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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 10557 matching lines...) Expand 10 before | Expand all | Expand 10 after
10568 context->DetachGlobal(); 10568 context->DetachGlobal();
10569 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 10569 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
10570 } 10570 }
10571 10571
10572 10572
10573 THREADED_TEST(PixelArray) { 10573 THREADED_TEST(PixelArray) {
10574 v8::HandleScope scope; 10574 v8::HandleScope scope;
10575 LocalContext context; 10575 LocalContext context;
10576 const int kElementCount = 260; 10576 const int kElementCount = 260;
10577 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 10577 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
10578 i::Handle<i::PixelArray> pixels = FACTORY->NewPixelArray(kElementCount, 10578 i::Handle<i::ExternalPixelArray> pixels =
10579 pixel_data); 10579 i::Handle<i::ExternalPixelArray>::cast(
10580 FACTORY->NewExternalArray(kElementCount,
10581 v8::kExternalPixelArray,
10582 pixel_data));
10580 HEAP->CollectAllGarbage(false); // Force GC to trigger verification. 10583 HEAP->CollectAllGarbage(false); // Force GC to trigger verification.
10581 for (int i = 0; i < kElementCount; i++) { 10584 for (int i = 0; i < kElementCount; i++) {
10582 pixels->set(i, i % 256); 10585 pixels->set(i, i % 256);
10583 } 10586 }
10584 HEAP->CollectAllGarbage(false); // Force GC to trigger verification. 10587 HEAP->CollectAllGarbage(false); // Force GC to trigger verification.
10585 for (int i = 0; i < kElementCount; i++) { 10588 for (int i = 0; i < kElementCount; i++) {
10586 CHECK_EQ(i % 256, pixels->get(i)); 10589 CHECK_EQ(i % 256, pixels->get(i));
10587 CHECK_EQ(i % 256, pixel_data[i]); 10590 CHECK_EQ(i % 256, pixel_data[i]);
10588 } 10591 }
10589 10592
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
10909 10912
10910 // Make sure that pixel array loads are optimized by crankshaft. 10913 // Make sure that pixel array loads are optimized by crankshaft.
10911 result = CompileRun("function pa_load(p) {" 10914 result = CompileRun("function pa_load(p) {"
10912 " var sum = 0;" 10915 " var sum = 0;"
10913 " for (var i=0; i<256; ++i) {" 10916 " for (var i=0; i<256; ++i) {"
10914 " sum += p[i];" 10917 " sum += p[i];"
10915 " }" 10918 " }"
10916 " return sum; " 10919 " return sum; "
10917 "}" 10920 "}"
10918 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" 10921 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10919 "for (var i = 0; i < 10000; ++i) {" 10922 "for (var i = 0; i < 5000; ++i) {"
10920 " result = pa_load(pixels);" 10923 " result = pa_load(pixels);"
10921 "}" 10924 "}"
10922 "result"); 10925 "result");
10923 CHECK_EQ(32640, result->Int32Value()); 10926 CHECK_EQ(32640, result->Int32Value());
10924 10927
10925 // Make sure that pixel array stores are optimized by crankshaft. 10928 // Make sure that pixel array stores are optimized by crankshaft.
10926 result = CompileRun("function pa_init(p) {" 10929 result = CompileRun("function pa_init(p) {"
10927 "for (var i = 0; i < 256; ++i) { p[i] = i; }" 10930 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
10928 "}" 10931 "}"
10929 "function pa_load(p) {" 10932 "function pa_load(p) {"
10930 " var sum = 0;" 10933 " var sum = 0;"
10931 " for (var i=0; i<256; ++i) {" 10934 " for (var i=0; i<256; ++i) {"
10932 " sum += p[i];" 10935 " sum += p[i];"
10933 " }" 10936 " }"
10934 " return sum; " 10937 " return sum; "
10935 "}" 10938 "}"
10936 "for (var i = 0; i < 100000; ++i) {" 10939 "for (var i = 0; i < 5000; ++i) {"
10937 " pa_init(pixels);" 10940 " pa_init(pixels);"
10938 "}" 10941 "}"
10939 "result = pa_load(pixels);" 10942 "result = pa_load(pixels);"
10940 "result"); 10943 "result");
10941 CHECK_EQ(32640, result->Int32Value()); 10944 CHECK_EQ(32640, result->Int32Value());
10942 10945
10943 free(pixel_data); 10946 free(pixel_data);
10944 } 10947 }
10945 10948
10946 10949
(...skipping 27 matching lines...) Expand all
10974 ApiTestFuzzer::Fuzz(); 10977 ApiTestFuzzer::Fuzz();
10975 return v8::Handle<Value>(); 10978 return v8::Handle<Value>();
10976 } 10979 }
10977 10980
10978 10981
10979 THREADED_TEST(PixelArrayWithInterceptor) { 10982 THREADED_TEST(PixelArrayWithInterceptor) {
10980 v8::HandleScope scope; 10983 v8::HandleScope scope;
10981 LocalContext context; 10984 LocalContext context;
10982 const int kElementCount = 260; 10985 const int kElementCount = 260;
10983 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 10986 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
10984 i::Handle<i::PixelArray> pixels = 10987 i::Handle<i::ExternalPixelArray> pixels =
10985 FACTORY->NewPixelArray(kElementCount, pixel_data); 10988 i::Handle<i::ExternalPixelArray>::cast(
10989 FACTORY->NewExternalArray(kElementCount,
10990 v8::kExternalPixelArray,
10991 pixel_data));
10986 for (int i = 0; i < kElementCount; i++) { 10992 for (int i = 0; i < kElementCount; i++) {
10987 pixels->set(i, i % 256); 10993 pixels->set(i, i % 256);
10988 } 10994 }
10989 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 10995 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
10990 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, 10996 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter,
10991 NotHandledIndexedPropertySetter); 10997 NotHandledIndexedPropertySetter);
10992 v8::Handle<v8::Object> obj = templ->NewInstance(); 10998 v8::Handle<v8::Object> obj = templ->NewInstance();
10993 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); 10999 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
10994 context->Global()->Set(v8_str("pixels"), obj); 11000 context->Global()->Set(v8_str("pixels"), obj);
10995 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); 11001 v8::Handle<v8::Value> result = CompileRun("pixels[1]");
10996 CHECK_EQ(1, result->Int32Value()); 11002 CHECK_EQ(1, result->Int32Value());
10997 result = CompileRun("var sum = 0;" 11003 result = CompileRun("var sum = 0;"
10998 "for (var i = 0; i < 8; i++) {" 11004 "for (var i = 0; i < 8; i++) {"
10999 " sum += pixels[i] = pixels[i] = -i;" 11005 " sum += pixels[i] = pixels[i] = -i;"
11000 "}" 11006 "}"
11001 "sum;"); 11007 "sum;");
11002 CHECK_EQ(-28, result->Int32Value()); 11008 CHECK_EQ(-28, result->Int32Value());
11003 result = CompileRun("pixels.hasOwnProperty('1')"); 11009 result = CompileRun("pixels.hasOwnProperty('1')");
11004 CHECK(result->BooleanValue()); 11010 CHECK(result->BooleanValue());
11005 free(pixel_data); 11011 free(pixel_data);
11006 } 11012 }
11007 11013
11008 11014
11009 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { 11015 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) {
11010 switch (array_type) { 11016 switch (array_type) {
11011 case v8::kExternalByteArray: 11017 case v8::kExternalByteArray:
11012 case v8::kExternalUnsignedByteArray: 11018 case v8::kExternalUnsignedByteArray:
11019 case v8::kExternalPixelArray:
11013 return 1; 11020 return 1;
11014 break; 11021 break;
11015 case v8::kExternalShortArray: 11022 case v8::kExternalShortArray:
11016 case v8::kExternalUnsignedShortArray: 11023 case v8::kExternalUnsignedShortArray:
11017 return 2; 11024 return 2;
11018 break; 11025 break;
11019 case v8::kExternalIntArray: 11026 case v8::kExternalIntArray:
11020 case v8::kExternalUnsignedIntArray: 11027 case v8::kExternalUnsignedIntArray:
11021 case v8::kExternalFloatArray: 11028 case v8::kExternalFloatArray:
11022 return 4; 11029 return 4;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
11224 CHECK_EQ(0, 11231 CHECK_EQ(0,
11225 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11232 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11226 11233
11227 result = CompileRun("for (var i = 0; i < 8; i++) {" 11234 result = CompileRun("for (var i = 0; i < 8; i++) {"
11228 " ext_array[i] = 5;" 11235 " ext_array[i] = 5;"
11229 "}" 11236 "}"
11230 "for (var i = 0; i < 8; i++) {" 11237 "for (var i = 0; i < 8; i++) {"
11231 " ext_array[i] = Infinity;" 11238 " ext_array[i] = Infinity;"
11232 "}" 11239 "}"
11233 "ext_array[5];"); 11240 "ext_array[5];");
11234 CHECK_EQ(0, result->Int32Value()); 11241 int expected_value =
11235 CHECK_EQ(0, 11242 (array_type == v8::kExternalPixelArray) ? 255 : 0;
11243 CHECK_EQ(expected_value, result->Int32Value());
11244 CHECK_EQ(expected_value,
11236 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11245 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11237 11246
11238 result = CompileRun("for (var i = 0; i < 8; i++) {" 11247 result = CompileRun("for (var i = 0; i < 8; i++) {"
11239 " ext_array[i] = 5;" 11248 " ext_array[i] = 5;"
11240 "}" 11249 "}"
11241 "for (var i = 0; i < 8; i++) {" 11250 "for (var i = 0; i < 8; i++) {"
11242 " ext_array[i] = -Infinity;" 11251 " ext_array[i] = -Infinity;"
11243 "}" 11252 "}"
11244 "ext_array[5];"); 11253 "ext_array[5];");
11245 CHECK_EQ(0, result->Int32Value()); 11254 CHECK_EQ(0, result->Int32Value());
11246 CHECK_EQ(0, 11255 CHECK_EQ(0,
11247 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11256 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11248 11257
11249 // Check truncation behavior of integral arrays. 11258 // Check truncation behavior of integral arrays.
11250 const char* unsigned_data = 11259 const char* unsigned_data =
11251 "var source_data = [0.6, 10.6];" 11260 "var source_data = [0.6, 10.6];"
11252 "var expected_results = [0, 10];"; 11261 "var expected_results = [0, 10];";
11253 const char* signed_data = 11262 const char* signed_data =
11254 "var source_data = [0.6, 10.6, -0.6, -10.6];" 11263 "var source_data = [0.6, 10.6, -0.6, -10.6];"
11255 "var expected_results = [0, 10, 0, -10];"; 11264 "var expected_results = [0, 10, 0, -10];";
11265 const char* pixel_data =
11266 "var source_data = [0.6, 10.6];"
11267 "var expected_results = [1, 11];";
11256 bool is_unsigned = 11268 bool is_unsigned =
11257 (array_type == v8::kExternalUnsignedByteArray || 11269 (array_type == v8::kExternalUnsignedByteArray ||
11258 array_type == v8::kExternalUnsignedShortArray || 11270 array_type == v8::kExternalUnsignedShortArray ||
11259 array_type == v8::kExternalUnsignedIntArray); 11271 array_type == v8::kExternalUnsignedIntArray);
11272 bool is_pixel_data = array_type == v8::kExternalPixelArray;
11260 11273
11261 i::OS::SNPrintF(test_buf, 11274 i::OS::SNPrintF(test_buf,
11262 "%s" 11275 "%s"
11263 "var all_passed = true;" 11276 "var all_passed = true;"
11264 "for (var i = 0; i < source_data.length; i++) {" 11277 "for (var i = 0; i < source_data.length; i++) {"
11265 " for (var j = 0; j < 8; j++) {" 11278 " for (var j = 0; j < 8; j++) {"
11266 " ext_array[j] = source_data[i];" 11279 " ext_array[j] = source_data[i];"
11267 " }" 11280 " }"
11268 " all_passed = all_passed &&" 11281 " all_passed = all_passed &&"
11269 " (ext_array[5] == expected_results[i]);" 11282 " (ext_array[5] == expected_results[i]);"
11270 "}" 11283 "}"
11271 "all_passed;", 11284 "all_passed;",
11272 (is_unsigned ? unsigned_data : signed_data)); 11285 (is_unsigned ?
11286 unsigned_data :
11287 (is_pixel_data ? pixel_data : signed_data)));
11273 result = CompileRun(test_buf.start()); 11288 result = CompileRun(test_buf.start());
11274 CHECK_EQ(true, result->BooleanValue()); 11289 CHECK_EQ(true, result->BooleanValue());
11275 } 11290 }
11276 11291
11277 result = CompileRun("ext_array[3] = 33;" 11292 result = CompileRun("ext_array[3] = 33;"
11278 "delete ext_array[3];" 11293 "delete ext_array[3];"
11279 "ext_array[3];"); 11294 "ext_array[3];");
11280 CHECK_EQ(33, result->Int32Value()); 11295 CHECK_EQ(33, result->Int32Value());
11281 11296
11282 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" 11297 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
11393 11408
11394 11409
11395 THREADED_TEST(ExternalUnsignedByteArray) { 11410 THREADED_TEST(ExternalUnsignedByteArray) {
11396 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>( 11411 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>(
11397 v8::kExternalUnsignedByteArray, 11412 v8::kExternalUnsignedByteArray,
11398 0, 11413 0,
11399 255); 11414 255);
11400 } 11415 }
11401 11416
11402 11417
11418 THREADED_TEST(ExternalPixelArray) {
11419 ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>(
11420 v8::kExternalPixelArray,
11421 0,
11422 255);
11423 }
11424
11425
11403 THREADED_TEST(ExternalShortArray) { 11426 THREADED_TEST(ExternalShortArray) {
11404 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>( 11427 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>(
11405 v8::kExternalShortArray, 11428 v8::kExternalShortArray,
11406 -32768, 11429 -32768,
11407 32767); 11430 32767);
11408 } 11431 }
11409 11432
11410 11433
11411 THREADED_TEST(ExternalUnsignedShortArray) { 11434 THREADED_TEST(ExternalUnsignedShortArray) {
11412 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>( 11435 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
11470 11493
11471 11494
11472 THREADED_TEST(ExternalArrayInfo) { 11495 THREADED_TEST(ExternalArrayInfo) {
11473 ExternalArrayInfoTestHelper(v8::kExternalByteArray); 11496 ExternalArrayInfoTestHelper(v8::kExternalByteArray);
11474 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); 11497 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray);
11475 ExternalArrayInfoTestHelper(v8::kExternalShortArray); 11498 ExternalArrayInfoTestHelper(v8::kExternalShortArray);
11476 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); 11499 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray);
11477 ExternalArrayInfoTestHelper(v8::kExternalIntArray); 11500 ExternalArrayInfoTestHelper(v8::kExternalIntArray);
11478 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); 11501 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
11479 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); 11502 ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
11503 ExternalArrayInfoTestHelper(v8::kExternalPixelArray);
11480 } 11504 }
11481 11505
11482 11506
11483 THREADED_TEST(ScriptContextDependence) { 11507 THREADED_TEST(ScriptContextDependence) {
11484 v8::HandleScope scope; 11508 v8::HandleScope scope;
11485 LocalContext c1; 11509 LocalContext c1;
11486 const char *source = "foo"; 11510 const char *source = "foo";
11487 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 11511 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source));
11488 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 11512 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source));
11489 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 11513 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100));
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
13189 v8::Handle<v8::Function> define_property = 13213 v8::Handle<v8::Function> define_property =
13190 CompileRun("(function() {" 13214 CompileRun("(function() {"
13191 " Object.defineProperty(" 13215 " Object.defineProperty("
13192 " this," 13216 " this,"
13193 " 1," 13217 " 1,"
13194 " { configurable: true, enumerable: true, value: 3 });" 13218 " { configurable: true, enumerable: true, value: 3 });"
13195 "})").As<Function>(); 13219 "})").As<Function>();
13196 context->DetachGlobal(); 13220 context->DetachGlobal();
13197 define_property->Call(proxy, 0, NULL); 13221 define_property->Call(proxy, 0, NULL);
13198 } 13222 }
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | test/mjsunit/regress/regress-1236.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698