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

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

Issue 66011: Workaround for http://crbug.com/9746:... (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
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 // Check that we can traverse very deep stacks of ConsStrings using 3 // Check that we can traverse very deep stacks of ConsStrings using
4 // StringInputBuffer. Check that Get(int) works on very deep stacks 4 // StringInputBuffer. Check that Get(int) works on very deep stacks
5 // of ConsStrings. These operations may not be very fast, but they 5 // of ConsStrings. These operations may not be very fast, but they
6 // should be possible without getting errors due to too deep recursion. 6 // should be possible without getting errors due to too deep recursion.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "v8.h" 10 #include "v8.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 int written = mixed->WriteUtf8(buffer, i); 380 int written = mixed->WriteUtf8(buffer, i);
381 CHECK_EQ(lengths[i], written); 381 CHECK_EQ(lengths[i], written);
382 // Check that the contents are correct 382 // Check that the contents are correct
383 for (int j = 0; j < lengths[i]; j++) 383 for (int j = 0; j < lengths[i]; j++)
384 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); 384 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j]));
385 // Check that the rest of the buffer hasn't been touched 385 // Check that the rest of the buffer hasn't been touched
386 for (int j = lengths[i]; j < 11; j++) 386 for (int j = lengths[i]; j < 11; j++)
387 CHECK_EQ(kNoChar, buffer[j]); 387 CHECK_EQ(kNoChar, buffer[j]);
388 } 388 }
389 } 389 }
390
391
392 class TwoByteResource: public v8::String::ExternalStringResource {
393 public:
394 explicit TwoByteResource(const uint16_t* data, size_t length)
395 : data_(data), length_(length) { }
396 virtual ~TwoByteResource() { }
397
398 const uint16_t* data() const { return data_; }
399 size_t length() const { return length_; }
400
401 private:
402 const uint16_t* data_;
403 size_t length_;
404 };
405
406
407 TEST(ExternalCrBug9746) {
408 InitializeVM();
409 v8::HandleScope handle_scope;
410
411 // This set of tests verifies that the workaround for Chromium bug 9746
412 // works correctly. In certain situations the external resource of a symbol
413 // is collected while the symbol is still part of the symbol table.
414 static uint16_t two_byte_data[] = {
415 't', 'w', 'o', '-', 'b', 'y', 't', 'e', ' ', 'd', 'a', 't', 'a'
416 };
417 static size_t two_byte_length =
418 sizeof(two_byte_data) / sizeof(two_byte_data[0]);
419 static const char* one_byte_data = "two-byte data";
420
421 // Allocate an external string resource and external string.
422 TwoByteResource* resource = new TwoByteResource(two_byte_data,
423 two_byte_length);
424 Handle<String> string = Factory::NewExternalStringFromTwoByte(resource);
425 Vector<const char> one_byte_vec = CStrVector(one_byte_data);
426 Handle<String> compare = Factory::NewStringFromAscii(one_byte_vec);
427
428 // Verify the correct behaviour before "collecting" the external resource.
429 CHECK(string->IsEqualTo(one_byte_vec));
430 CHECK(string->Equals(*compare));
431
432 // "Collect" the external resource manually by setting the external resource
433 // pointer to NULL. Then redo the comparisons, they should not match AND
434 // not crash.
435 Handle<ExternalTwoByteString> external(ExternalTwoByteString::cast(*string));
436 external->set_resource(NULL);
437 CHECK_EQ(false, string->IsEqualTo(one_byte_vec));
438 #if !defined(DEBUG)
439 // These tests only work in non-debug as there are ASSERTs in the code that
440 // do prevent the ability to even get into the broken code when running the
441 // debug version of V8.
442 CHECK_EQ(false, string->Equals(*compare));
443 CHECK_EQ(false, compare->Equals(*string));
444 CHECK_EQ(false, string->Equals(Heap::empty_string()));
445 #endif // !defined(DEBUG)
446 }
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698