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

Side by Side Diff: src/uri.cc

Issue 2006673002: Reduce boilerplace for common pattern to return MaybeHandle. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase and fix Created 4 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
« no previous file with comments | « src/uri.h ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/uri.h" 5 #include "src/uri.h"
6 6
7 #include "src/char-predicates-inl.h" 7 #include "src/char-predicates-inl.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/list.h" 10 #include "src/list.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 uint8_t y = (cc2 >> 6) & 0xF; 82 uint8_t y = (cc2 >> 6) & 0xF;
83 uint8_t z = cc2 & 63; 83 uint8_t z = cc2 & 63;
84 AddHexEncodedToBuffer((u >> 2) + 240, buffer); 84 AddHexEncodedToBuffer((u >> 2) + 240, buffer);
85 AddHexEncodedToBuffer((((u & 3) << 4) | w) + 128, buffer); 85 AddHexEncodedToBuffer((((u & 3) << 4) | w) + 128, buffer);
86 AddHexEncodedToBuffer(((x << 4) | y) + 128, buffer); 86 AddHexEncodedToBuffer(((x << 4) | y) + 128, buffer);
87 AddHexEncodedToBuffer(z + 128, buffer); 87 AddHexEncodedToBuffer(z + 128, buffer);
88 } 88 }
89 89
90 } // anonymous namespace 90 } // anonymous namespace
91 91
92 Object* Uri::Encode(Isolate* isolate, Handle<String> uri, bool is_uri) { 92 MaybeHandle<String> Uri::Encode(Isolate* isolate, Handle<String> uri,
93 bool is_uri) {
93 uri = String::Flatten(uri); 94 uri = String::Flatten(uri);
94 int uri_length = uri->length(); 95 int uri_length = uri->length();
95 List<uint8_t> buffer(uri_length); 96 List<uint8_t> buffer(uri_length);
96 97
97 { 98 {
98 DisallowHeapAllocation no_gc; 99 DisallowHeapAllocation no_gc;
99 String::FlatContent uri_content = uri->GetFlatContent(); 100 String::FlatContent uri_content = uri->GetFlatContent();
100 101
101 for (int k = 0; k < uri_length; k++) { 102 for (int k = 0; k < uri_length; k++) {
102 uc16 cc1 = uri_content.Get(k); 103 uc16 cc1 = uri_content.Get(k);
(...skipping 10 matching lines...) Expand all
113 if (IsUnescapePredicateInUriComponent(cc1) || 114 if (IsUnescapePredicateInUriComponent(cc1) ||
114 (is_uri && IsUriSeparator(cc1))) { 115 (is_uri && IsUriSeparator(cc1))) {
115 buffer.Add(cc1); 116 buffer.Add(cc1);
116 } else { 117 } else {
117 EncodeSingle(cc1, &buffer); 118 EncodeSingle(cc1, &buffer);
118 } 119 }
119 continue; 120 continue;
120 } 121 }
121 122
122 AllowHeapAllocation allocate_error_and_return; 123 AllowHeapAllocation allocate_error_and_return;
123 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewURIError()); 124 THROW_NEW_ERROR(isolate, NewURIError(), String);
124 } 125 }
125 } 126 }
126 127
127 Handle<String> result; 128 return isolate->factory()->NewStringFromOneByte(buffer.ToConstVector());
128 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
129 isolate, result,
130 isolate->factory()->NewStringFromOneByte(buffer.ToConstVector()));
131 return *result;
132 } 129 }
133 130
134 } // namespace internal 131 } // namespace internal
135 } // namespace v8 132 } // namespace v8
OLDNEW
« no previous file with comments | « src/uri.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698