Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/builtins.h" | 5 #include "src/builtins.h" |
| 6 | 6 |
| 7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| 11 #include "src/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
| 12 #include "src/char-predicates-inl.h" | |
| 12 #include "src/code-factory.h" | 13 #include "src/code-factory.h" |
| 13 #include "src/code-stub-assembler.h" | 14 #include "src/code-stub-assembler.h" |
| 14 #include "src/dateparser-inl.h" | 15 #include "src/dateparser-inl.h" |
| 15 #include "src/elements.h" | 16 #include "src/elements.h" |
| 16 #include "src/frames-inl.h" | 17 #include "src/frames-inl.h" |
| 17 #include "src/gdb-jit.h" | 18 #include "src/gdb-jit.h" |
| 18 #include "src/ic/handler-compiler.h" | 19 #include "src/ic/handler-compiler.h" |
| 19 #include "src/ic/ic.h" | 20 #include "src/ic/ic.h" |
| 20 #include "src/isolate-inl.h" | 21 #include "src/isolate-inl.h" |
| 21 #include "src/messages.h" | 22 #include "src/messages.h" |
| (...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2099 HandleScope scope(isolate); | 2100 HandleScope scope(isolate); |
| 2100 Handle<Object> object = args.atOrUndefined(isolate, 1); | 2101 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 2101 if (object->IsJSReceiver()) { | 2102 if (object->IsJSReceiver()) { |
| 2102 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), | 2103 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), |
| 2103 SEALED, Object::THROW_ON_ERROR), | 2104 SEALED, Object::THROW_ON_ERROR), |
| 2104 isolate->heap()->exception()); | 2105 isolate->heap()->exception()); |
| 2105 } | 2106 } |
| 2106 return *object; | 2107 return *object; |
| 2107 } | 2108 } |
| 2108 | 2109 |
| 2110 // anonymous namespace for URIEncode helper functions | |
| 2111 namespace { | |
| 2112 | |
| 2113 bool IsUnescapePredicateInUriComponent(uc16 c) { | |
| 2114 if (IsAlphaNumeric(c)) { | |
| 2115 return true; | |
| 2116 } | |
| 2117 | |
| 2118 switch (c) { | |
| 2119 case '!': | |
| 2120 case '\'': | |
| 2121 case '(': | |
| 2122 case ')': | |
| 2123 case '*': | |
| 2124 case '-': | |
| 2125 case '.': | |
| 2126 case '_': | |
| 2127 case '~': | |
| 2128 return true; | |
| 2129 default: | |
| 2130 return false; | |
| 2131 } | |
| 2132 } | |
| 2133 | |
| 2134 bool IsUriSeparator(uc16 c) { | |
| 2135 switch (c) { | |
| 2136 case '#': | |
| 2137 case ':': | |
| 2138 case ';': | |
| 2139 case '/': | |
| 2140 case '?': | |
| 2141 case '$': | |
| 2142 case '&': | |
| 2143 case '+': | |
| 2144 case ',': | |
| 2145 case '@': | |
| 2146 case '=': | |
| 2147 return true; | |
| 2148 default: | |
| 2149 return false; | |
| 2150 } | |
| 2151 } | |
| 2152 | |
| 2153 void AddHexEncodedToBuffer(uint8_t octet, List<uint8_t>* buffer) { | |
| 2154 buffer->Add('%'); | |
| 2155 buffer->Add(HexCharOfValue(octet >> 4)); | |
| 2156 buffer->Add(HexCharOfValue(octet & 0x0F)); | |
| 2157 } | |
| 2158 | |
| 2159 void EncodeSingle(uc16 c, List<uint8_t>* buffer) { | |
| 2160 uint8_t x = (c >> 12) & 0xF; | |
| 2161 uint8_t y = (c >> 6) & 63; | |
| 2162 uint8_t z = c & 63; | |
| 2163 if (c <= 0x007F) { | |
| 2164 AddHexEncodedToBuffer(c, buffer); | |
| 2165 } else if (c <= 0x07FF) { | |
| 2166 AddHexEncodedToBuffer(y + 192, buffer); | |
| 2167 AddHexEncodedToBuffer(z + 128, buffer); | |
| 2168 } else { | |
| 2169 AddHexEncodedToBuffer(x + 224, buffer); | |
| 2170 AddHexEncodedToBuffer(y + 128, buffer); | |
| 2171 AddHexEncodedToBuffer(z + 128, buffer); | |
| 2172 } | |
| 2173 } | |
| 2174 | |
| 2175 void EncodePair(uc16 cc1, uc16 cc2, List<uint8_t>* buffer) { | |
| 2176 uint8_t u = ((cc1 >> 6) & 0xF) + 1; | |
| 2177 uint8_t w = (cc1 >> 2) & 0xF; | |
| 2178 uint8_t x = cc1 & 3; | |
| 2179 uint8_t y = (cc2 >> 6) & 0xF; | |
| 2180 uint8_t z = cc2 & 63; | |
| 2181 AddHexEncodedToBuffer((u >> 2) + 240, buffer); | |
| 2182 AddHexEncodedToBuffer((((u & 3) << 4) | w) + 128, buffer); | |
| 2183 AddHexEncodedToBuffer(((x << 4) | y) + 128, buffer); | |
| 2184 AddHexEncodedToBuffer(z + 128, buffer); | |
| 2185 } | |
| 2186 | |
| 2187 Object* EncodeUri(Isolate* isolate, Handle<String> uri, bool is_uri) { | |
| 2188 uri = String::Flatten(uri); | |
| 2189 int uri_length = uri->length(); | |
| 2190 List<uint8_t> buffer(uri_length); | |
| 2191 | |
| 2192 { | |
| 2193 DisallowHeapAllocation no_gc; | |
| 2194 String::FlatContent uri_content = uri->GetFlatContent(); | |
| 2195 | |
| 2196 for (int k = 0; k < uri_length; k++) { | |
| 2197 uc16 cc1 = uri_content.Get(k); | |
| 2198 if (unibrow::Utf16::IsLeadSurrogate(cc1)) { | |
| 2199 k++; | |
| 2200 if (k < uri_length) { | |
| 2201 uc16 cc2 = uri->Get(k); | |
| 2202 if (unibrow::Utf16::IsTrailSurrogate(cc2)) { | |
| 2203 EncodePair(cc1, cc2, &buffer); | |
| 2204 continue; | |
| 2205 } | |
| 2206 } | |
| 2207 } else if (!unibrow::Utf16::IsTrailSurrogate(cc1)) { | |
| 2208 if (IsUnescapePredicateInUriComponent(cc1) || | |
| 2209 (is_uri && IsUriSeparator(cc1))) { | |
| 2210 buffer.Add(cc1); | |
| 2211 } else { | |
| 2212 EncodeSingle(cc1, &buffer); | |
| 2213 } | |
| 2214 continue; | |
| 2215 } | |
| 2216 | |
| 2217 AllowHeapAllocation allocate_error_and_return; | |
| 2218 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewURIError()); | |
| 2219 } | |
| 2220 } | |
| 2221 | |
| 2222 Handle<String> result; | |
| 2223 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 2224 isolate, result, | |
| 2225 isolate->factory()->NewStringFromOneByte(buffer.ToConstVector())); | |
| 2226 return *result; | |
| 2227 } | |
| 2228 | |
| 2229 } // namespace | |
| 2230 | |
| 2231 // ES6 section 18.2.6.4 encodeURI (uri) | |
| 2232 BUILTIN(GlobalEncodeURI) { | |
| 2233 HandleScope scope(isolate); | |
| 2234 Handle<String> uri; | |
| 2235 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 2236 isolate, uri, Object::ToString(isolate, args.atOrUndefined(isolate, 1))); | |
| 2237 | |
| 2238 return EncodeUri(isolate, uri, true); | |
|
Yang
2016/05/17 05:15:38
builtins.cc is already bloated from all sorts of t
Franzi
2016/05/17 10:25:31
Moved into src/uri.h
| |
| 2239 } | |
| 2240 | |
| 2241 // ES6 section 18.2.6.5 encodeURIComponenet (uriComponent) | |
| 2242 BUILTIN(GlobalEncodeURIComponent) { | |
| 2243 HandleScope scope(isolate); | |
| 2244 Handle<String> uriComponent; | |
| 2245 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 2246 isolate, uriComponent, | |
| 2247 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); | |
| 2248 | |
| 2249 return EncodeUri(isolate, uriComponent, false); | |
| 2250 } | |
| 2109 | 2251 |
| 2110 namespace { | 2252 namespace { |
| 2111 | 2253 |
| 2112 bool CodeGenerationFromStringsAllowed(Isolate* isolate, | 2254 bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
| 2113 Handle<Context> context) { | 2255 Handle<Context> context) { |
| 2114 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); | 2256 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); |
| 2115 // Check with callback if set. | 2257 // Check with callback if set. |
| 2116 AllowCodeGenerationFromStringsCallback callback = | 2258 AllowCodeGenerationFromStringsCallback callback = |
| 2117 isolate->allow_code_gen_callback(); | 2259 isolate->allow_code_gen_callback(); |
| 2118 if (callback == NULL) { | 2260 if (callback == NULL) { |
| (...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5478 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5620 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
| 5479 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5621 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 5480 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5622 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 5481 #undef DEFINE_BUILTIN_ACCESSOR_C | 5623 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 5482 #undef DEFINE_BUILTIN_ACCESSOR_A | 5624 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 5483 #undef DEFINE_BUILTIN_ACCESSOR_T | 5625 #undef DEFINE_BUILTIN_ACCESSOR_T |
| 5484 #undef DEFINE_BUILTIN_ACCESSOR_H | 5626 #undef DEFINE_BUILTIN_ACCESSOR_H |
| 5485 | 5627 |
| 5486 } // namespace internal | 5628 } // namespace internal |
| 5487 } // namespace v8 | 5629 } // namespace v8 |
| OLD | NEW |