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

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

Issue 16530003: add function to test whether string contents are definitely one byte (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 6 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
« src/objects.cc ('K') | « 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 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 16861 matching lines...) Expand 10 before | Expand all | Expand 10 after
16872 16872
16873 ExpectObject("str2.indexOf('els');", indexof); 16873 ExpectObject("str2.indexOf('els');", indexof);
16874 16874
16875 ExpectObject("str2.lastIndexOf('dab');", lastindexof); 16875 ExpectObject("str2.lastIndexOf('dab');", lastindexof);
16876 16876
16877 reresult = CompileRun("str2.charCodeAt(2);"); 16877 reresult = CompileRun("str2.charCodeAt(2);");
16878 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); 16878 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value());
16879 } 16879 }
16880 16880
16881 16881
16882 TEST(ContainsOnlyOneByte) {
16883 v8::V8::Initialize();
16884 v8::Isolate* isolate = v8::Isolate::GetCurrent();
16885 v8::HandleScope scope(isolate);
16886 // Make a buffer long enough that it won't automatically be converted.
16887 const int length = 200;
16888 i::SmartArrayPointer<uint16_t> string_contents(new uint16_t[length]);
16889 // Set to contain only one byte.
16890 for (int i = 0; i < length-1; i++) {
16891 string_contents[i] = 0x41;
16892 }
16893 string_contents[length-1] = 0;
16894 // Simple case.
16895 Handle<String> string;
16896 string = String::NewExternal(new TestResource(*string_contents));
16897 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
16898 // Counter example.
16899 string = String::NewFromTwoByte(isolate, *string_contents);
16900 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
16901 // Test left right and balanced cons strings.
16902 Handle<String> base = String::NewFromUtf8(isolate, "a");
16903 Handle<String> left = base;
16904 Handle<String> right = base;
16905 for (int i = 0; i < 1000; i++) {
16906 left = String::Concat(base, left);
16907 right = String::Concat(right, base);
16908 }
16909 Handle<String> balanced = String::Concat(left, base);
16910 balanced = String::Concat(balanced, right);
Yang 2013/06/06 12:57:36 I wouldn't call that quite balanced, but alright :
16911 Handle<String> cons_strings[] = {left, balanced, right};
16912 Handle<String> two_byte =
16913 String::NewExternal(new TestResource(*string_contents));
16914 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) {
16915 // Base assumptions.
16916 string = cons_strings[i];
16917 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
16918 // Test left and right concatentation.
16919 string = String::Concat(two_byte, cons_strings[i]);
16920 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
16921 string = String::Concat(cons_strings[i], two_byte);
16922 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
16923 }
16924 }
16925
16926
16882 // Failed access check callback that performs a GC on each invocation. 16927 // Failed access check callback that performs a GC on each invocation.
16883 void FailedAccessCheckCallbackGC(Local<v8::Object> target, 16928 void FailedAccessCheckCallbackGC(Local<v8::Object> target,
16884 v8::AccessType type, 16929 v8::AccessType type,
16885 Local<v8::Value> data) { 16930 Local<v8::Value> data) {
16886 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16931 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16887 } 16932 }
16888 16933
16889 16934
16890 TEST(GCInFailedAccessCheckCallback) { 16935 TEST(GCInFailedAccessCheckCallback) {
16891 // Install a failed access check callback that performs a GC on each 16936 // Install a failed access check callback that performs a GC on each
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after
19106 i::Semaphore* sem_; 19151 i::Semaphore* sem_;
19107 volatile int sem_value_; 19152 volatile int sem_value_;
19108 }; 19153 };
19109 19154
19110 19155
19111 THREADED_TEST(SemaphoreInterruption) { 19156 THREADED_TEST(SemaphoreInterruption) {
19112 ThreadInterruptTest().RunTest(); 19157 ThreadInterruptTest().RunTest();
19113 } 19158 }
19114 19159
19115 #endif // WIN32 19160 #endif // WIN32
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698