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

Side by Side Diff: src/api.cc

Issue 14509012: HasOnlyAsciiChars can return incorrect results. Fixup usages and rename. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fixed typo Created 7 years, 7 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 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 4037 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4048 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4049 return Utils::ToLocal(i::Handle<i::Object>(script->id(), func->GetIsolate())); 4049 return Utils::ToLocal(i::Handle<i::Object>(script->id(), func->GetIsolate()));
4050 } 4050 }
4051 4051
4052 int String::Length() const { 4052 int String::Length() const {
4053 i::Handle<i::String> str = Utils::OpenHandle(this); 4053 i::Handle<i::String> str = Utils::OpenHandle(this);
4054 if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0; 4054 if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0;
4055 return str->length(); 4055 return str->length();
4056 } 4056 }
4057 4057
4058 bool String::MayContainNonAscii() const {
4059 i::Handle<i::String> str = Utils::OpenHandle(this);
4060 if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) {
4061 return false;
4062 }
4063 return !str->HasOnlyAsciiChars();
4064 }
4065
4066 4058
4067 bool String::IsOneByte() const { 4059 bool String::IsOneByte() const {
4068 i::Handle<i::String> str = Utils::OpenHandle(this); 4060 i::Handle<i::String> str = Utils::OpenHandle(this);
4069 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) { 4061 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) {
4070 return false; 4062 return false;
4071 } 4063 }
4072 return str->IsOneByteConvertible(); 4064 return str->IsOneByteConvertible();
4073 } 4065 }
4074 4066
4075 4067
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
4509 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; 4501 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0;
4510 LOG_API(isolate, "String::WriteAscii"); 4502 LOG_API(isolate, "String::WriteAscii");
4511 ENTER_V8(isolate); 4503 ENTER_V8(isolate);
4512 ASSERT(start >= 0 && length >= -1); 4504 ASSERT(start >= 0 && length >= -1);
4513 i::Handle<i::String> str = Utils::OpenHandle(this); 4505 i::Handle<i::String> str = Utils::OpenHandle(this);
4514 isolate->string_tracker()->RecordWrite(str); 4506 isolate->string_tracker()->RecordWrite(str);
4515 if (options & HINT_MANY_WRITES_EXPECTED) { 4507 if (options & HINT_MANY_WRITES_EXPECTED) {
4516 FlattenString(str); // Flatten the string for efficiency. 4508 FlattenString(str); // Flatten the string for efficiency.
4517 } 4509 }
4518 4510
4519 if (str->HasOnlyAsciiChars()) {
4520 // WriteToFlat is faster than using the StringCharacterStream.
4521 if (length == -1) length = str->length() + 1;
4522 int len = i::Min(length, str->length() - start);
4523 i::String::WriteToFlat(*str,
4524 reinterpret_cast<uint8_t*>(buffer),
4525 start,
4526 start + len);
4527 if (!(options & PRESERVE_ASCII_NULL)) {
4528 for (int i = 0; i < len; i++) {
4529 if (buffer[i] == '\0') buffer[i] = ' ';
4530 }
4531 }
4532 if (!(options & NO_NULL_TERMINATION) && length > len) {
4533 buffer[len] = '\0';
4534 }
4535 return len;
4536 }
4537
4538 int end = length; 4511 int end = length;
4539 if ((length == -1) || (length > str->length() - start)) { 4512 if ((length == -1) || (length > str->length() - start)) {
4540 end = str->length() - start; 4513 end = str->length() - start;
4541 } 4514 }
4542 if (end < 0) return 0; 4515 if (end < 0) return 0;
4543 i::StringCharacterStream write_stream(*str, isolate->write_iterator(), start); 4516 i::StringCharacterStream write_stream(*str, isolate->write_iterator(), start);
4544 int i; 4517 int i;
4545 for (i = 0; i < end; i++) { 4518 for (i = 0; i < end; i++) {
4546 char c = static_cast<char>(write_stream.GetNext()); 4519 char c = static_cast<char>(write_stream.GetNext());
4547 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; 4520 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' ';
(...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after
7506 7479
7507 v->VisitPointers(blocks_.first(), first_block_limit_); 7480 v->VisitPointers(blocks_.first(), first_block_limit_);
7508 7481
7509 for (int i = 1; i < blocks_.length(); i++) { 7482 for (int i = 1; i < blocks_.length(); i++) {
7510 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); 7483 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
7511 } 7484 }
7512 } 7485 }
7513 7486
7514 7487
7515 } } // namespace v8::internal 7488 } } // namespace v8::internal
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | src/arm/code-stubs-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698