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/ieee754.h" | 10 #include "src/base/ieee754.h" |
(...skipping 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 HandleScope scope(isolate); | 2236 HandleScope scope(isolate); |
2237 JsonStringifier stringifier(isolate); | 2237 JsonStringifier stringifier(isolate); |
2238 Handle<Object> object = args.atOrUndefined(isolate, 1); | 2238 Handle<Object> object = args.atOrUndefined(isolate, 1); |
2239 Handle<Object> replacer = args.atOrUndefined(isolate, 2); | 2239 Handle<Object> replacer = args.atOrUndefined(isolate, 2); |
2240 Handle<Object> indent = args.atOrUndefined(isolate, 3); | 2240 Handle<Object> indent = args.atOrUndefined(isolate, 3); |
2241 RETURN_RESULT_OR_FAILURE(isolate, | 2241 RETURN_RESULT_OR_FAILURE(isolate, |
2242 stringifier.Stringify(object, replacer, indent)); | 2242 stringifier.Stringify(object, replacer, indent)); |
2243 } | 2243 } |
2244 | 2244 |
2245 // ----------------------------------------------------------------------------- | 2245 // ----------------------------------------------------------------------------- |
| 2246 // ES6 section 20.1 Number Objects |
| 2247 |
| 2248 // ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits ) |
| 2249 BUILTIN(NumberPrototypeToExponential) { |
| 2250 HandleScope scope(isolate); |
| 2251 Handle<Object> value = args.at<Object>(0); |
| 2252 Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); |
| 2253 |
| 2254 // Unwrap the receiver {value}. |
| 2255 if (value->IsJSValue()) { |
| 2256 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
| 2257 } |
| 2258 if (!value->IsNumber()) { |
| 2259 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2260 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 2261 isolate->factory()->NewStringFromAsciiChecked( |
| 2262 "Number.prototype.toExponential"))); |
| 2263 } |
| 2264 double const value_number = value->Number(); |
| 2265 |
| 2266 // Convert the {fraction_digits} to an integer first. |
| 2267 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2268 isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); |
| 2269 double const fraction_digits_number = fraction_digits->Number(); |
| 2270 |
| 2271 if (std::isnan(value_number)) return isolate->heap()->nan_string(); |
| 2272 if (std::isinf(value_number)) { |
| 2273 return (value_number < 0.0) ? isolate->heap()->minus_infinity_string() |
| 2274 : isolate->heap()->infinity_string(); |
| 2275 } |
| 2276 if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) { |
| 2277 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2278 isolate, NewRangeError(MessageTemplate::kNumberFormatRange, |
| 2279 isolate->factory()->NewStringFromAsciiChecked( |
| 2280 "toExponential()"))); |
| 2281 } |
| 2282 int const f = args.atOrUndefined(isolate, 1)->IsUndefined(isolate) |
| 2283 ? -1 |
| 2284 : static_cast<int>(fraction_digits_number); |
| 2285 char* const str = DoubleToExponentialCString(value_number, f); |
| 2286 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
| 2287 DeleteArray(str); |
| 2288 return *result; |
| 2289 } |
| 2290 |
| 2291 // ES6 section 20.1.3.3 Number.prototype.toFixed ( fractionDigits ) |
| 2292 BUILTIN(NumberPrototypeToFixed) { |
| 2293 HandleScope scope(isolate); |
| 2294 Handle<Object> value = args.at<Object>(0); |
| 2295 Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); |
| 2296 |
| 2297 // Unwrap the receiver {value}. |
| 2298 if (value->IsJSValue()) { |
| 2299 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
| 2300 } |
| 2301 if (!value->IsNumber()) { |
| 2302 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2303 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 2304 isolate->factory()->NewStringFromAsciiChecked( |
| 2305 "Number.prototype.toFixed"))); |
| 2306 } |
| 2307 double const value_number = value->Number(); |
| 2308 |
| 2309 // Convert the {fraction_digits} to an integer first. |
| 2310 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2311 isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); |
| 2312 double const fraction_digits_number = fraction_digits->Number(); |
| 2313 |
| 2314 // Check if the {fraction_digits} are in the supported range. |
| 2315 if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) { |
| 2316 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2317 isolate, NewRangeError(MessageTemplate::kNumberFormatRange, |
| 2318 isolate->factory()->NewStringFromAsciiChecked( |
| 2319 "toFixed() digits"))); |
| 2320 } |
| 2321 |
| 2322 if (std::isnan(value_number)) return isolate->heap()->nan_string(); |
| 2323 if (std::isinf(value_number)) { |
| 2324 return (value_number < 0.0) ? isolate->heap()->minus_infinity_string() |
| 2325 : isolate->heap()->infinity_string(); |
| 2326 } |
| 2327 char* const str = DoubleToFixedCString( |
| 2328 value_number, static_cast<int>(fraction_digits_number)); |
| 2329 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
| 2330 DeleteArray(str); |
| 2331 return *result; |
| 2332 } |
| 2333 |
| 2334 // ES6 section 20.1.3.4 Number.prototype.toLocaleString ( [ r1 [ , r2 ] ] ) |
| 2335 BUILTIN(NumberPrototypeToLocaleString) { |
| 2336 HandleScope scope(isolate); |
| 2337 Handle<Object> value = args.at<Object>(0); |
| 2338 |
| 2339 // Unwrap the receiver {value}. |
| 2340 if (value->IsJSValue()) { |
| 2341 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
| 2342 } |
| 2343 if (!value->IsNumber()) { |
| 2344 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2345 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 2346 isolate->factory()->NewStringFromAsciiChecked( |
| 2347 "Number.prototype.toLocaleString"))); |
| 2348 } |
| 2349 |
| 2350 // Turn the {value} into a String. |
| 2351 return *isolate->factory()->NumberToString(value); |
| 2352 } |
| 2353 |
| 2354 // ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision ) |
| 2355 BUILTIN(NumberPrototypeToPrecision) { |
| 2356 HandleScope scope(isolate); |
| 2357 Handle<Object> value = args.at<Object>(0); |
| 2358 Handle<Object> precision = args.atOrUndefined(isolate, 1); |
| 2359 |
| 2360 // Unwrap the receiver {value}. |
| 2361 if (value->IsJSValue()) { |
| 2362 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
| 2363 } |
| 2364 if (!value->IsNumber()) { |
| 2365 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2366 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 2367 isolate->factory()->NewStringFromAsciiChecked( |
| 2368 "Number.prototype.toPrecision"))); |
| 2369 } |
| 2370 double const value_number = value->Number(); |
| 2371 |
| 2372 // If no {precision} was specified, just return ToString of {value}. |
| 2373 if (precision->IsUndefined(isolate)) { |
| 2374 return *isolate->factory()->NumberToString(value); |
| 2375 } |
| 2376 |
| 2377 // Convert the {precision} to an integer first. |
| 2378 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, precision, |
| 2379 Object::ToInteger(isolate, precision)); |
| 2380 double const precision_number = precision->Number(); |
| 2381 |
| 2382 if (std::isnan(value_number)) return isolate->heap()->nan_string(); |
| 2383 if (std::isinf(value_number)) { |
| 2384 return (value_number < 0.0) ? isolate->heap()->minus_infinity_string() |
| 2385 : isolate->heap()->infinity_string(); |
| 2386 } |
| 2387 if (precision_number < 1.0 || precision_number > 21.0) { |
| 2388 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2389 isolate, NewRangeError(MessageTemplate::kToPrecisionFormatRange)); |
| 2390 } |
| 2391 char* const str = DoubleToPrecisionCString( |
| 2392 value_number, static_cast<int>(precision_number)); |
| 2393 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
| 2394 DeleteArray(str); |
| 2395 return *result; |
| 2396 } |
| 2397 |
| 2398 // ES6 section 20.1.3.6 Number.prototype.toString ( [ radix ] ) |
| 2399 BUILTIN(NumberPrototypeToString) { |
| 2400 HandleScope scope(isolate); |
| 2401 Handle<Object> value = args.at<Object>(0); |
| 2402 Handle<Object> radix = args.atOrUndefined(isolate, 1); |
| 2403 |
| 2404 // Unwrap the receiver {value}. |
| 2405 if (value->IsJSValue()) { |
| 2406 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
| 2407 } |
| 2408 if (!value->IsNumber()) { |
| 2409 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2410 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 2411 isolate->factory()->NewStringFromAsciiChecked( |
| 2412 "Number.prototype.toString"))); |
| 2413 } |
| 2414 double const value_number = value->Number(); |
| 2415 |
| 2416 // If no {radix} was specified, just return ToString of {value}. |
| 2417 if (radix->IsUndefined(isolate)) { |
| 2418 return *isolate->factory()->NumberToString(value); |
| 2419 } |
| 2420 |
| 2421 // Convert the {radix} to an integer first. |
| 2422 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, radix, |
| 2423 Object::ToInteger(isolate, radix)); |
| 2424 double const radix_number = radix->Number(); |
| 2425 |
| 2426 // If {radix} is 10, just return ToString of {value}. |
| 2427 if (radix_number == 10.0) return *isolate->factory()->NumberToString(value); |
| 2428 |
| 2429 // Make sure the {radix} is within the valid range. |
| 2430 if (radix_number < 2.0 || radix_number > 36.0) { |
| 2431 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2432 isolate, NewRangeError(MessageTemplate::kToRadixFormatRange)); |
| 2433 } |
| 2434 |
| 2435 // Fast case where the result is a one character string. |
| 2436 if (IsUint32Double(value_number) && value_number < radix_number) { |
| 2437 // Character array used for conversion. |
| 2438 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
| 2439 return *isolate->factory()->LookupSingleCharacterStringFromCode( |
| 2440 kCharTable[static_cast<uint32_t>(value_number)]); |
| 2441 } |
| 2442 |
| 2443 // Slow case. |
| 2444 if (std::isnan(value_number)) return isolate->heap()->nan_string(); |
| 2445 if (std::isinf(value_number)) { |
| 2446 return (value_number < 0.0) ? isolate->heap()->minus_infinity_string() |
| 2447 : isolate->heap()->infinity_string(); |
| 2448 } |
| 2449 char* const str = |
| 2450 DoubleToRadixCString(value_number, static_cast<int>(radix_number)); |
| 2451 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
| 2452 DeleteArray(str); |
| 2453 return *result; |
| 2454 } |
| 2455 |
| 2456 // ES6 section 20.1.3.7 Number.prototype.valueOf ( ) |
| 2457 void Builtins::Generate_NumberPrototypeValueOf(CodeStubAssembler* assembler) { |
| 2458 typedef compiler::Node Node; |
| 2459 |
| 2460 Node* receiver = assembler->Parameter(0); |
| 2461 Node* context = assembler->Parameter(3); |
| 2462 |
| 2463 Node* result = assembler->ToThisValue( |
| 2464 context, receiver, PrimitiveType::kNumber, "Number.prototype.valueOf"); |
| 2465 assembler->Return(result); |
| 2466 } |
| 2467 |
| 2468 // ----------------------------------------------------------------------------- |
2246 // ES6 section 20.2.2 Function Properties of the Math Object | 2469 // ES6 section 20.2.2 Function Properties of the Math Object |
2247 | 2470 |
2248 // ES6 section - 20.2.2.1 Math.abs ( x ) | 2471 // ES6 section - 20.2.2.1 Math.abs ( x ) |
2249 void Builtins::Generate_MathAbs(CodeStubAssembler* assembler) { | 2472 void Builtins::Generate_MathAbs(CodeStubAssembler* assembler) { |
2250 using compiler::Node; | 2473 using compiler::Node; |
2251 Node* x = assembler->Parameter(1); | 2474 Node* x = assembler->Parameter(1); |
2252 Node* context = assembler->Parameter(4); | 2475 Node* context = assembler->Parameter(4); |
2253 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); | 2476 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); |
2254 Node* value = assembler->Float64Abs(x_value); | 2477 Node* value = assembler->Float64Abs(x_value); |
2255 Node* result = assembler->ChangeFloat64ToTagged(value); | 2478 Node* result = assembler->ChangeFloat64ToTagged(value); |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3194 Handle<JSObject> result; | 3417 Handle<JSObject> result; |
3195 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 3418 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
3196 JSObject::New(target, new_target)); | 3419 JSObject::New(target, new_target)); |
3197 Handle<JSValue>::cast(result)->set_value( | 3420 Handle<JSValue>::cast(result)->set_value( |
3198 isolate->heap()->ToBoolean(value->BooleanValue())); | 3421 isolate->heap()->ToBoolean(value->BooleanValue())); |
3199 return *result; | 3422 return *result; |
3200 } | 3423 } |
3201 | 3424 |
3202 | 3425 |
3203 // ES6 section 19.3.3.2 Boolean.prototype.toString ( ) | 3426 // ES6 section 19.3.3.2 Boolean.prototype.toString ( ) |
3204 BUILTIN(BooleanPrototypeToString) { | 3427 void Builtins::Generate_BooleanPrototypeToString(CodeStubAssembler* assembler) { |
3205 HandleScope scope(isolate); | 3428 typedef compiler::Node Node; |
3206 Handle<Object> receiver = args.receiver(); | 3429 |
3207 if (receiver->IsJSValue()) { | 3430 Node* receiver = assembler->Parameter(0); |
3208 receiver = handle(Handle<JSValue>::cast(receiver)->value(), isolate); | 3431 Node* context = assembler->Parameter(3); |
3209 } | 3432 |
3210 if (!receiver->IsBoolean()) { | 3433 Node* value = assembler->ToThisValue( |
3211 THROW_NEW_ERROR_RETURN_FAILURE( | 3434 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.toString"); |
3212 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 3435 Node* result = assembler->LoadObjectField(value, Oddball::kToStringOffset); |
3213 isolate->factory()->NewStringFromAsciiChecked( | 3436 assembler->Return(result); |
3214 "Boolean.prototype.toString"))); | |
3215 } | |
3216 return Handle<Oddball>::cast(receiver)->to_string(); | |
3217 } | 3437 } |
3218 | 3438 |
| 3439 // ES6 section 19.3.3.3 Boolean.prototype.valueOf ( ) |
| 3440 void Builtins::Generate_BooleanPrototypeValueOf(CodeStubAssembler* assembler) { |
| 3441 typedef compiler::Node Node; |
3219 | 3442 |
3220 // ES6 section 19.3.3.3 Boolean.prototype.valueOf ( ) | 3443 Node* receiver = assembler->Parameter(0); |
3221 BUILTIN(BooleanPrototypeValueOf) { | 3444 Node* context = assembler->Parameter(3); |
3222 HandleScope scope(isolate); | 3445 |
3223 Handle<Object> receiver = args.receiver(); | 3446 Node* result = assembler->ToThisValue( |
3224 if (receiver->IsJSValue()) { | 3447 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.valueOf"); |
3225 receiver = handle(Handle<JSValue>::cast(receiver)->value(), isolate); | 3448 assembler->Return(result); |
3226 } | |
3227 if (!receiver->IsBoolean()) { | |
3228 THROW_NEW_ERROR_RETURN_FAILURE( | |
3229 isolate, NewTypeError(MessageTemplate::kNotGeneric, | |
3230 isolate->factory()->NewStringFromAsciiChecked( | |
3231 "Boolean.prototype.valueOf"))); | |
3232 } | |
3233 return *receiver; | |
3234 } | 3449 } |
3235 | 3450 |
3236 | |
3237 // ----------------------------------------------------------------------------- | 3451 // ----------------------------------------------------------------------------- |
3238 // ES6 section 24.2 DataView Objects | 3452 // ES6 section 24.2 DataView Objects |
3239 | 3453 |
3240 | 3454 |
3241 // ES6 section 24.2.2 The DataView Constructor for the [[Call]] case. | 3455 // ES6 section 24.2.2 The DataView Constructor for the [[Call]] case. |
3242 BUILTIN(DataViewConstructor) { | 3456 BUILTIN(DataViewConstructor) { |
3243 HandleScope scope(isolate); | 3457 HandleScope scope(isolate); |
3244 THROW_NEW_ERROR_RETURN_FAILURE( | 3458 THROW_NEW_ERROR_RETURN_FAILURE( |
3245 isolate, | 3459 isolate, |
3246 NewTypeError(MessageTemplate::kConstructorNotFunction, | 3460 NewTypeError(MessageTemplate::kConstructorNotFunction, |
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4762 | 4976 |
4763 // Do not lazily compute eval position for AsyncFunction, as they may not be | 4977 // Do not lazily compute eval position for AsyncFunction, as they may not be |
4764 // determined after the function is resumed. | 4978 // determined after the function is resumed. |
4765 Handle<Script> script = handle(Script::cast(func->shared()->script())); | 4979 Handle<Script> script = handle(Script::cast(func->shared()->script())); |
4766 int position = script->GetEvalPosition(); | 4980 int position = script->GetEvalPosition(); |
4767 USE(position); | 4981 USE(position); |
4768 | 4982 |
4769 return *func; | 4983 return *func; |
4770 } | 4984 } |
4771 | 4985 |
| 4986 // ES6 19.1.3.6 Object.prototype.toString |
| 4987 BUILTIN(ObjectProtoToString) { |
| 4988 HandleScope scope(isolate); |
| 4989 Handle<Object> object = args.at<Object>(0); |
| 4990 RETURN_RESULT_OR_FAILURE(isolate, |
| 4991 Object::ObjectProtoToString(isolate, object)); |
| 4992 } |
| 4993 |
| 4994 // ----------------------------------------------------------------------------- |
| 4995 // ES6 section 19.4 Symbol Objects |
| 4996 |
4772 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. | 4997 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. |
4773 BUILTIN(SymbolConstructor) { | 4998 BUILTIN(SymbolConstructor) { |
4774 HandleScope scope(isolate); | 4999 HandleScope scope(isolate); |
4775 Handle<Symbol> result = isolate->factory()->NewSymbol(); | 5000 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
4776 Handle<Object> description = args.atOrUndefined(isolate, 1); | 5001 Handle<Object> description = args.atOrUndefined(isolate, 1); |
4777 if (!description->IsUndefined(isolate)) { | 5002 if (!description->IsUndefined(isolate)) { |
4778 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, | 5003 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
4779 Object::ToString(isolate, description)); | 5004 Object::ToString(isolate, description)); |
4780 result->set_name(*description); | 5005 result->set_name(*description); |
4781 } | 5006 } |
4782 return *result; | 5007 return *result; |
4783 } | 5008 } |
4784 | 5009 |
4785 | 5010 |
4786 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. | 5011 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. |
4787 BUILTIN(SymbolConstructor_ConstructStub) { | 5012 BUILTIN(SymbolConstructor_ConstructStub) { |
4788 HandleScope scope(isolate); | 5013 HandleScope scope(isolate); |
4789 THROW_NEW_ERROR_RETURN_FAILURE( | 5014 THROW_NEW_ERROR_RETURN_FAILURE( |
4790 isolate, NewTypeError(MessageTemplate::kNotConstructor, | 5015 isolate, NewTypeError(MessageTemplate::kNotConstructor, |
4791 isolate->factory()->Symbol_string())); | 5016 isolate->factory()->Symbol_string())); |
4792 } | 5017 } |
4793 | 5018 |
| 5019 // ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) |
| 5020 void Builtins::Generate_SymbolPrototypeToPrimitive( |
| 5021 CodeStubAssembler* assembler) { |
| 5022 typedef compiler::Node Node; |
4794 | 5023 |
4795 // ES6 19.1.3.6 Object.prototype.toString | 5024 Node* receiver = assembler->Parameter(0); |
4796 BUILTIN(ObjectProtoToString) { | 5025 Node* context = assembler->Parameter(4); |
4797 HandleScope scope(isolate); | 5026 |
4798 Handle<Object> object = args.at<Object>(0); | 5027 Node* result = |
4799 RETURN_RESULT_OR_FAILURE(isolate, | 5028 assembler->ToThisValue(context, receiver, PrimitiveType::kSymbol, |
4800 Object::ObjectProtoToString(isolate, object)); | 5029 "Symbol.prototype [ @@toPrimitive ]"); |
| 5030 assembler->Return(result); |
| 5031 } |
| 5032 |
| 5033 // ES6 section 19.4.3.2 Symbol.prototype.toString ( ) |
| 5034 void Builtins::Generate_SymbolPrototypeToString(CodeStubAssembler* assembler) { |
| 5035 typedef compiler::Node Node; |
| 5036 |
| 5037 Node* receiver = assembler->Parameter(0); |
| 5038 Node* context = assembler->Parameter(3); |
| 5039 |
| 5040 Node* value = assembler->ToThisValue( |
| 5041 context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.toString"); |
| 5042 Node* result = |
| 5043 assembler->CallRuntime(Runtime::kSymbolDescriptiveString, context, value); |
| 5044 assembler->Return(result); |
| 5045 } |
| 5046 |
| 5047 // ES6 section 19.4.3.3 Symbol.prototype.valueOf ( ) |
| 5048 void Builtins::Generate_SymbolPrototypeValueOf(CodeStubAssembler* assembler) { |
| 5049 typedef compiler::Node Node; |
| 5050 |
| 5051 Node* receiver = assembler->Parameter(0); |
| 5052 Node* context = assembler->Parameter(3); |
| 5053 |
| 5054 Node* result = assembler->ToThisValue( |
| 5055 context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.valueOf"); |
| 5056 assembler->Return(result); |
4801 } | 5057 } |
4802 | 5058 |
4803 // ----------------------------------------------------------------------------- | 5059 // ----------------------------------------------------------------------------- |
4804 // ES6 section 21.1 String Objects | 5060 // ES6 section 21.1 String Objects |
4805 | 5061 |
4806 // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits ) | 5062 // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits ) |
4807 void Builtins::Generate_StringFromCharCode(CodeStubAssembler* assembler) { | 5063 void Builtins::Generate_StringFromCharCode(CodeStubAssembler* assembler) { |
4808 typedef CodeStubAssembler::Label Label; | 5064 typedef CodeStubAssembler::Label Label; |
4809 typedef compiler::Node Node; | 5065 typedef compiler::Node Node; |
4810 typedef CodeStubAssembler::Variable Variable; | 5066 typedef CodeStubAssembler::Variable Variable; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5263 assembler->Return(assembler->NaNConstant()); | 5519 assembler->Return(assembler->NaNConstant()); |
5264 assembler->Bind(&if_positioninbounds); | 5520 assembler->Bind(&if_positioninbounds); |
5265 } | 5521 } |
5266 | 5522 |
5267 // Load the character at the {position} from the {receiver}. | 5523 // Load the character at the {position} from the {receiver}. |
5268 Node* value = assembler->StringCharCodeAt(receiver, position); | 5524 Node* value = assembler->StringCharCodeAt(receiver, position); |
5269 Node* result = assembler->SmiFromWord32(value); | 5525 Node* result = assembler->SmiFromWord32(value); |
5270 assembler->Return(result); | 5526 assembler->Return(result); |
5271 } | 5527 } |
5272 | 5528 |
5273 // ES6 section 21.1.3.25 String.prototype.trim () | 5529 // ES6 section 21.1.3.25 String.prototype.toString () |
| 5530 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { |
| 5531 typedef compiler::Node Node; |
| 5532 |
| 5533 Node* receiver = assembler->Parameter(0); |
| 5534 Node* context = assembler->Parameter(3); |
| 5535 |
| 5536 Node* result = assembler->ToThisValue( |
| 5537 context, receiver, PrimitiveType::kString, "String.prototype.toString"); |
| 5538 assembler->Return(result); |
| 5539 } |
| 5540 |
| 5541 // ES6 section 21.1.3.27 String.prototype.trim () |
5274 BUILTIN(StringPrototypeTrim) { | 5542 BUILTIN(StringPrototypeTrim) { |
5275 HandleScope scope(isolate); | 5543 HandleScope scope(isolate); |
5276 TO_THIS_STRING(string, "String.prototype.trim"); | 5544 TO_THIS_STRING(string, "String.prototype.trim"); |
5277 return *String::Trim(string, String::kTrim); | 5545 return *String::Trim(string, String::kTrim); |
5278 } | 5546 } |
5279 | 5547 |
5280 // Non-standard WebKit extension | 5548 // Non-standard WebKit extension |
5281 BUILTIN(StringPrototypeTrimLeft) { | 5549 BUILTIN(StringPrototypeTrimLeft) { |
5282 HandleScope scope(isolate); | 5550 HandleScope scope(isolate); |
5283 TO_THIS_STRING(string, "String.prototype.trimLeft"); | 5551 TO_THIS_STRING(string, "String.prototype.trimLeft"); |
5284 return *String::Trim(string, String::kTrimLeft); | 5552 return *String::Trim(string, String::kTrimLeft); |
5285 } | 5553 } |
5286 | 5554 |
5287 // Non-standard WebKit extension | 5555 // Non-standard WebKit extension |
5288 BUILTIN(StringPrototypeTrimRight) { | 5556 BUILTIN(StringPrototypeTrimRight) { |
5289 HandleScope scope(isolate); | 5557 HandleScope scope(isolate); |
5290 TO_THIS_STRING(string, "String.prototype.trimRight"); | 5558 TO_THIS_STRING(string, "String.prototype.trimRight"); |
5291 return *String::Trim(string, String::kTrimRight); | 5559 return *String::Trim(string, String::kTrimRight); |
5292 } | 5560 } |
5293 | 5561 |
| 5562 // ES6 section 21.1.3.28 String.prototype.valueOf ( ) |
| 5563 void Builtins::Generate_StringPrototypeValueOf(CodeStubAssembler* assembler) { |
| 5564 typedef compiler::Node Node; |
| 5565 |
| 5566 Node* receiver = assembler->Parameter(0); |
| 5567 Node* context = assembler->Parameter(3); |
| 5568 |
| 5569 Node* result = assembler->ToThisValue( |
| 5570 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); |
| 5571 assembler->Return(result); |
| 5572 } |
| 5573 |
5294 // ----------------------------------------------------------------------------- | 5574 // ----------------------------------------------------------------------------- |
5295 // ES6 section 21.1 ArrayBuffer Objects | 5575 // ES6 section 21.1 ArrayBuffer Objects |
5296 | 5576 |
5297 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case. | 5577 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case. |
5298 BUILTIN(ArrayBufferConstructor) { | 5578 BUILTIN(ArrayBufferConstructor) { |
5299 HandleScope scope(isolate); | 5579 HandleScope scope(isolate); |
5300 Handle<JSFunction> target = args.target<JSFunction>(); | 5580 Handle<JSFunction> target = args.target<JSFunction>(); |
5301 DCHECK(*target == target->native_context()->array_buffer_fun() || | 5581 DCHECK(*target == target->native_context()->array_buffer_fun() || |
5302 *target == target->native_context()->shared_array_buffer_fun()); | 5582 *target == target->native_context()->shared_array_buffer_fun()); |
5303 THROW_NEW_ERROR_RETURN_FAILURE( | 5583 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6426 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 6706 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
6427 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 6707 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
6428 #undef DEFINE_BUILTIN_ACCESSOR_C | 6708 #undef DEFINE_BUILTIN_ACCESSOR_C |
6429 #undef DEFINE_BUILTIN_ACCESSOR_A | 6709 #undef DEFINE_BUILTIN_ACCESSOR_A |
6430 #undef DEFINE_BUILTIN_ACCESSOR_T | 6710 #undef DEFINE_BUILTIN_ACCESSOR_T |
6431 #undef DEFINE_BUILTIN_ACCESSOR_S | 6711 #undef DEFINE_BUILTIN_ACCESSOR_S |
6432 #undef DEFINE_BUILTIN_ACCESSOR_H | 6712 #undef DEFINE_BUILTIN_ACCESSOR_H |
6433 | 6713 |
6434 } // namespace internal | 6714 } // namespace internal |
6435 } // namespace v8 | 6715 } // namespace v8 |
OLD | NEW |