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

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

Issue 912333002: Fix NewStringRangeError failure due to failing malloc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | 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 21905 matching lines...) Expand 10 before | Expand all | Expand 10 after
21916 } 21916 }
21917 21917
21918 21918
21919 TEST(NewStringRangeError) { 21919 TEST(NewStringRangeError) {
21920 v8::Isolate* isolate = CcTest::isolate(); 21920 v8::Isolate* isolate = CcTest::isolate();
21921 v8::HandleScope handle_scope(isolate); 21921 v8::HandleScope handle_scope(isolate);
21922 LocalContext env; 21922 LocalContext env;
21923 const int length = i::String::kMaxLength + 1; 21923 const int length = i::String::kMaxLength + 1;
21924 const int buffer_size = length * sizeof(uint16_t); 21924 const int buffer_size = length * sizeof(uint16_t);
21925 void* buffer = malloc(buffer_size); 21925 void* buffer = malloc(buffer_size);
21926 if (buffer == NULL) return;
21926 memset(buffer, 'A', buffer_size); 21927 memset(buffer, 'A', buffer_size);
21927 { 21928 {
21928 v8::TryCatch try_catch; 21929 v8::TryCatch try_catch;
21929 char* data = reinterpret_cast<char*>(buffer); 21930 char* data = reinterpret_cast<char*>(buffer);
21930 CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, 21931 CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString,
21931 length).IsEmpty()); 21932 length).IsEmpty());
21932 CHECK(try_catch.HasCaught()); 21933 CHECK(try_catch.HasCaught());
21933 } 21934 }
21934 { 21935 {
21935 v8::TryCatch try_catch; 21936 v8::TryCatch try_catch;
21936 uint8_t* data = reinterpret_cast<uint8_t*>(buffer); 21937 uint8_t* data = reinterpret_cast<uint8_t*>(buffer);
21937 CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString, 21938 CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString,
21938 length).IsEmpty()); 21939 length).IsEmpty());
21939 CHECK(try_catch.HasCaught()); 21940 CHECK(try_catch.HasCaught());
21940 } 21941 }
21941 { 21942 {
21942 v8::TryCatch try_catch; 21943 v8::TryCatch try_catch;
21943 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); 21944 uint16_t* data = reinterpret_cast<uint16_t*>(buffer);
21944 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, 21945 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString,
21945 length).IsEmpty()); 21946 length).IsEmpty());
21946 CHECK(try_catch.HasCaught()); 21947 CHECK(try_catch.HasCaught());
21947 } 21948 }
21948 free(buffer); 21949 free(buffer);
21949 } 21950 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698