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: src/parser.cc

Issue 745233002: Fix raw TemplateLiteral spans with non-ascii characters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Don't use Utf8Decoder::WriteUtf16 when length is 0 Created 6 years 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 | test/mjsunit/harmony/templates.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 5318 matching lines...) Expand 10 before | Expand all | Expand 10 after
5329 if (ch == '\r') { 5329 if (ch == '\r') {
5330 ch = '\n'; 5330 ch = '\n';
5331 if (from_index + 1 < length && raw_chars[from_index + 1] == '\n') { 5331 if (from_index + 1 < length && raw_chars[from_index + 1] == '\n') {
5332 ++from_index; 5332 ++from_index;
5333 } 5333 }
5334 } 5334 }
5335 hash_string[num_hash_chars++] = ch; 5335 hash_string[num_hash_chars++] = ch;
5336 raw_chars[to_index++] = ch; 5336 raw_chars[to_index++] = ch;
5337 } 5337 }
5338 5338
5339 const AstRawString* raw_str = ast_value_factory()->GetOneByteString( 5339 Access<UnicodeCache::Utf8Decoder>
5340 OneByteVector(raw_chars.get(), to_index)); 5340 decoder(isolate()->unicode_cache()->utf8_decoder());
5341 Literal* raw_lit = factory()->NewStringLiteral(raw_str, span_start - 1); 5341 decoder->Reset(raw_chars.get(), to_index);
marja 2014/12/01 15:53:59 Since we're now doing parsing on a background thre
Dmitry Lomov (no reviews) 2014/12/01 16:09:48 Oops, sorry, forgot about that! Good catch!
5342 int utf16_length = decoder->Utf16Length();
5343 Literal* raw_lit = NULL;
5344 if (utf16_length > 0) {
5345 uc16* utf16_buffer = zone()->NewArray<uc16>(utf16_length);
5346 to_index = decoder->WriteUtf16(utf16_buffer, utf16_length);
5347 const uint16_t* data = reinterpret_cast<const uint16_t*>(utf16_buffer);
5348 const AstRawString* raw_str = ast_value_factory()->GetTwoByteString(
5349 Vector<const uint16_t>(data, to_index));
5350 raw_lit = factory()->NewStringLiteral(raw_str, span_start - 1);
5351 } else {
5352 raw_lit = factory()->NewStringLiteral(
5353 ast_value_factory()->empty_string(), span_start - 1);
5354 }
5355 DCHECK_NOT_NULL(raw_lit);
5342 raw_strings->Add(raw_lit, zone()); 5356 raw_strings->Add(raw_lit, zone());
5343 } 5357 }
5344 5358
5345 hash_string.Truncate(num_hash_chars); 5359 hash_string.Truncate(num_hash_chars);
5346 int utf16_length; 5360 int utf16_length;
5347 *hash = StringHasher::ComputeUtf8Hash(Vector<const char>::cast(hash_string), 5361 *hash = StringHasher::ComputeUtf8Hash(Vector<const char>::cast(hash_string),
5348 num_hash_chars, &utf16_length); 5362 num_hash_chars, &utf16_length);
5349 hash_string.Dispose(); 5363 hash_string.Dispose();
5350 5364
5351 return raw_strings; 5365 return raw_strings;
5352 } 5366 }
5353 } } // namespace v8::internal 5367 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/templates.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698