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

Side by Side Diff: src/runtime.cc

Issue 10915062: Add checks to runtime functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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
« no previous file with comments | « src/runtime.h ('k') | src/x64/full-codegen-x64.cc » ('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 // 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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if (JSObject::cast(*boilerplate)->elements()->map() == 666 if (JSObject::cast(*boilerplate)->elements()->map() ==
667 isolate->heap()->fixed_cow_array_map()) { 667 isolate->heap()->fixed_cow_array_map()) {
668 isolate->counters()->cow_arrays_created_runtime()->Increment(); 668 isolate->counters()->cow_arrays_created_runtime()->Increment();
669 } 669 }
670 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate)); 670 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate));
671 } 671 }
672 672
673 673
674 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) { 674 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) {
675 ASSERT(args.length() == 2); 675 ASSERT(args.length() == 2);
676 Object* handler = args[0]; 676 CONVERT_ARG_CHECKED(JSReceiver, handler, 0);
677 Object* prototype = args[1]; 677 Object* prototype = args[1];
678 Object* used_prototype = 678 Object* used_prototype =
679 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); 679 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value();
680 return isolate->heap()->AllocateJSProxy(handler, used_prototype); 680 return isolate->heap()->AllocateJSProxy(handler, used_prototype);
681 } 681 }
682 682
683 683
684 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) { 684 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) {
685 ASSERT(args.length() == 4); 685 ASSERT(args.length() == 4);
686 Object* handler = args[0]; 686 CONVERT_ARG_CHECKED(JSReceiver, handler, 0);
687 Object* call_trap = args[1]; 687 Object* call_trap = args[1];
688 Object* construct_trap = args[2]; 688 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy());
689 CONVERT_ARG_CHECKED(JSFunction, construct_trap, 2);
689 Object* prototype = args[3]; 690 Object* prototype = args[3];
690 Object* used_prototype = 691 Object* used_prototype =
691 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); 692 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value();
692 return isolate->heap()->AllocateJSFunctionProxy( 693 return isolate->heap()->AllocateJSFunctionProxy(
693 handler, call_trap, construct_trap, used_prototype); 694 handler, call_trap, construct_trap, used_prototype);
694 } 695 }
695 696
696 697
697 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSProxy) { 698 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSProxy) {
698 ASSERT(args.length() == 1); 699 ASSERT(args.length() == 1);
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 f->shared()->set_name_should_print_as_anonymous(true); 2060 f->shared()->set_name_should_print_as_anonymous(true);
2060 return isolate->heap()->undefined_value(); 2061 return isolate->heap()->undefined_value();
2061 } 2062 }
2062 2063
2063 2064
2064 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionRemovePrototype) { 2065 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionRemovePrototype) {
2065 NoHandleAllocation ha; 2066 NoHandleAllocation ha;
2066 ASSERT(args.length() == 1); 2067 ASSERT(args.length() == 1);
2067 2068
2068 CONVERT_ARG_CHECKED(JSFunction, f, 0); 2069 CONVERT_ARG_CHECKED(JSFunction, f, 0);
2069 Object* obj = f->RemovePrototype(); 2070 f->RemovePrototype();
2070 if (obj->IsFailure()) return obj;
2071 2071
2072 return isolate->heap()->undefined_value(); 2072 return isolate->heap()->undefined_value();
2073 } 2073 }
2074 2074
2075 2075
2076 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionGetScript) { 2076 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionGetScript) {
2077 HandleScope scope(isolate); 2077 HandleScope scope(isolate);
2078 ASSERT(args.length() == 1); 2078 ASSERT(args.length() == 1);
2079 2079
2080 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 2080 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
2300 } 2300 }
2301 return isolate->heap()->empty_string(); 2301 return isolate->heap()->empty_string();
2302 } 2302 }
2303 2303
2304 2304
2305 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringCharCodeAt) { 2305 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringCharCodeAt) {
2306 NoHandleAllocation ha; 2306 NoHandleAllocation ha;
2307 ASSERT(args.length() == 2); 2307 ASSERT(args.length() == 2);
2308 2308
2309 CONVERT_ARG_CHECKED(String, subject, 0); 2309 CONVERT_ARG_CHECKED(String, subject, 0);
2310 Object* index = args[1]; 2310 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]);
2311 RUNTIME_ASSERT(index->IsNumber());
2312
2313 uint32_t i = 0;
2314 if (index->IsSmi()) {
2315 int value = Smi::cast(index)->value();
2316 if (value < 0) return isolate->heap()->nan_value();
2317 i = value;
2318 } else {
2319 ASSERT(index->IsHeapNumber());
2320 double value = HeapNumber::cast(index)->value();
2321 i = static_cast<uint32_t>(DoubleToInteger(value));
2322 }
2323 2311
2324 // Flatten the string. If someone wants to get a char at an index 2312 // Flatten the string. If someone wants to get a char at an index
2325 // in a cons string, it is likely that more indices will be 2313 // in a cons string, it is likely that more indices will be
2326 // accessed. 2314 // accessed.
2327 Object* flat; 2315 Object* flat;
2328 { MaybeObject* maybe_flat = subject->TryFlatten(); 2316 { MaybeObject* maybe_flat = subject->TryFlatten();
2329 if (!maybe_flat->ToObject(&flat)) return maybe_flat; 2317 if (!maybe_flat->ToObject(&flat)) return maybe_flat;
2330 } 2318 }
2331 subject = String::cast(flat); 2319 subject = String::cast(flat);
2332 2320
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( 3270 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>(
3283 isolate, subject, regexp, last_match_info); 3271 isolate, subject, regexp, last_match_info);
3284 } 3272 }
3285 } 3273 }
3286 3274
3287 return StringReplaceRegExpWithString( 3275 return StringReplaceRegExpWithString(
3288 isolate, subject, regexp, replacement, last_match_info); 3276 isolate, subject, regexp, replacement, last_match_info);
3289 } 3277 }
3290 3278
3291 3279
3292 Handle<String> Runtime::StringReplaceOneCharWithString(Isolate* isolate, 3280 Handle<String> StringReplaceOneCharWithString(Isolate* isolate,
3293 Handle<String> subject, 3281 Handle<String> subject,
3294 Handle<String> search, 3282 Handle<String> search,
3295 Handle<String> replace, 3283 Handle<String> replace,
3296 bool* found, 3284 bool* found,
3297 int recursion_limit) { 3285 int recursion_limit) {
3298 if (recursion_limit == 0) return Handle<String>::null(); 3286 if (recursion_limit == 0) return Handle<String>::null();
3299 if (subject->IsConsString()) { 3287 if (subject->IsConsString()) {
3300 ConsString* cons = ConsString::cast(*subject); 3288 ConsString* cons = ConsString::cast(*subject);
3301 Handle<String> first = Handle<String>(cons->first()); 3289 Handle<String> first = Handle<String>(cons->first());
3302 Handle<String> second = Handle<String>(cons->second()); 3290 Handle<String> second = Handle<String>(cons->second());
3303 Handle<String> new_first = 3291 Handle<String> new_first =
3304 StringReplaceOneCharWithString(isolate, 3292 StringReplaceOneCharWithString(isolate,
3305 first, 3293 first,
3306 search, 3294 search,
3307 replace, 3295 replace,
3308 found, 3296 found,
3309 recursion_limit - 1); 3297 recursion_limit - 1);
3310 if (*found) return isolate->factory()->NewConsString(new_first, second); 3298 if (*found) return isolate->factory()->NewConsString(new_first, second);
3311 if (new_first.is_null()) return new_first; 3299 if (new_first.is_null()) return new_first;
3312 3300
3313 Handle<String> new_second = 3301 Handle<String> new_second =
3314 StringReplaceOneCharWithString(isolate, 3302 StringReplaceOneCharWithString(isolate,
3315 second, 3303 second,
3316 search, 3304 search,
3317 replace, 3305 replace,
3318 found, 3306 found,
3319 recursion_limit - 1); 3307 recursion_limit - 1);
3320 if (*found) return isolate->factory()->NewConsString(first, new_second); 3308 if (*found) return isolate->factory()->NewConsString(first, new_second);
3321 if (new_second.is_null()) return new_second; 3309 if (new_second.is_null()) return new_second;
3322 3310
3323 return subject; 3311 return subject;
3324 } else { 3312 } else {
3325 int index = StringMatch(isolate, subject, search, 0); 3313 int index = Runtime::StringMatch(isolate, subject, search, 0);
3326 if (index == -1) return subject; 3314 if (index == -1) return subject;
3327 *found = true; 3315 *found = true;
3328 Handle<String> first = isolate->factory()->NewSubString(subject, 0, index); 3316 Handle<String> first = isolate->factory()->NewSubString(subject, 0, index);
3329 Handle<String> cons1 = isolate->factory()->NewConsString(first, replace); 3317 Handle<String> cons1 = isolate->factory()->NewConsString(first, replace);
3330 Handle<String> second = 3318 Handle<String> second =
3331 isolate->factory()->NewSubString(subject, index + 1, subject->length()); 3319 isolate->factory()->NewSubString(subject, index + 1, subject->length());
3332 return isolate->factory()->NewConsString(cons1, second); 3320 return isolate->factory()->NewConsString(cons1, second);
3333 } 3321 }
3334 } 3322 }
3335 3323
3336 3324
3337 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceOneCharWithString) { 3325 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceOneCharWithString) {
3338 ASSERT(args.length() == 3); 3326 ASSERT(args.length() == 3);
3339 HandleScope scope(isolate); 3327 HandleScope scope(isolate);
3340 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 3328 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
3341 CONVERT_ARG_HANDLE_CHECKED(String, search, 1); 3329 CONVERT_ARG_HANDLE_CHECKED(String, search, 1);
3342 CONVERT_ARG_HANDLE_CHECKED(String, replace, 2); 3330 CONVERT_ARG_HANDLE_CHECKED(String, replace, 2);
3343 3331
3344 // If the cons string tree is too deep, we simply abort the recursion and 3332 // If the cons string tree is too deep, we simply abort the recursion and
3345 // retry with a flattened subject string. 3333 // retry with a flattened subject string.
3346 const int kRecursionLimit = 0x1000; 3334 const int kRecursionLimit = 0x1000;
3347 bool found = false; 3335 bool found = false;
3348 Handle<String> result = 3336 Handle<String> result = StringReplaceOneCharWithString(isolate,
3349 Runtime::StringReplaceOneCharWithString(isolate, 3337 subject,
3350 subject, 3338 search,
3351 search, 3339 replace,
3352 replace, 3340 &found,
3353 &found, 3341 kRecursionLimit);
3354 kRecursionLimit);
3355 if (!result.is_null()) return *result; 3342 if (!result.is_null()) return *result;
3356 return *Runtime::StringReplaceOneCharWithString(isolate, 3343 return *StringReplaceOneCharWithString(isolate,
3357 FlattenGetString(subject), 3344 FlattenGetString(subject),
3358 search, 3345 search,
3359 replace, 3346 replace,
3360 &found, 3347 &found,
3361 kRecursionLimit); 3348 kRecursionLimit);
3362 } 3349 }
3363 3350
3364 3351
3365 // Perform string match of pattern on subject, starting at start index. 3352 // Perform string match of pattern on subject, starting at start index.
3366 // Caller must ensure that 0 <= start_index <= sub->length(), 3353 // Caller must ensure that 0 <= start_index <= sub->length(),
3367 // and should check that pat->length() + start_index <= sub->length(). 3354 // and should check that pat->length() + start_index <= sub->length().
3368 int Runtime::StringMatch(Isolate* isolate, 3355 int Runtime::StringMatch(Isolate* isolate,
3369 Handle<String> sub, 3356 Handle<String> sub,
3370 Handle<String> pat, 3357 Handle<String> pat,
3371 int start_index) { 3358 int start_index) {
(...skipping 5485 matching lines...) Expand 10 before | Expand all | Expand 10 after
8857 ASSERT(args.length() == 1); 8844 ASSERT(args.length() == 1);
8858 8845
8859 Handle<Object> name(args[0], isolate); 8846 Handle<Object> name(args[0], isolate);
8860 Handle<Object> reference_error = 8847 Handle<Object> reference_error =
8861 isolate->factory()->NewReferenceError("not_defined", 8848 isolate->factory()->NewReferenceError("not_defined",
8862 HandleVector(&name, 1)); 8849 HandleVector(&name, 1));
8863 return isolate->Throw(*reference_error); 8850 return isolate->Throw(*reference_error);
8864 } 8851 }
8865 8852
8866 8853
8854 RUNTIME_FUNCTION(MaybeObject*, Runtime_ThrowNotDateError) {
8855 HandleScope scope(isolate);
8856 ASSERT(args.length() == 0);
8857 return isolate->Throw(*isolate->factory()->NewTypeError(
8858 "not_date_object", HandleVector<Object>(NULL, 0)));
8859 }
8860
8861
8862
8867 RUNTIME_FUNCTION(MaybeObject*, Runtime_StackGuard) { 8863 RUNTIME_FUNCTION(MaybeObject*, Runtime_StackGuard) {
8868 ASSERT(args.length() == 0); 8864 ASSERT(args.length() == 0);
8869 8865
8870 // First check if this is a real stack overflow. 8866 // First check if this is a real stack overflow.
8871 if (isolate->stack_guard()->IsStackOverflow()) { 8867 if (isolate->stack_guard()->IsStackOverflow()) {
8872 NoHandleAllocation na; 8868 NoHandleAllocation na;
8873 return isolate->StackOverflow(); 8869 return isolate->StackOverflow();
8874 } 8870 }
8875 8871
8876 return Execution::HandleStackGuardInterrupt(isolate); 8872 return Execution::HandleStackGuardInterrupt(isolate);
(...skipping 3376 matching lines...) Expand 10 before | Expand all | Expand 10 after
12253 12249
12254 // For a script finds all SharedFunctionInfo's in the heap that points 12250 // For a script finds all SharedFunctionInfo's in the heap that points
12255 // to this script. Returns JSArray of SharedFunctionInfo wrapped 12251 // to this script. Returns JSArray of SharedFunctionInfo wrapped
12256 // in OpaqueReferences. 12252 // in OpaqueReferences.
12257 RUNTIME_FUNCTION(MaybeObject*, 12253 RUNTIME_FUNCTION(MaybeObject*,
12258 Runtime_LiveEditFindSharedFunctionInfosForScript) { 12254 Runtime_LiveEditFindSharedFunctionInfosForScript) {
12259 ASSERT(args.length() == 1); 12255 ASSERT(args.length() == 1);
12260 HandleScope scope(isolate); 12256 HandleScope scope(isolate);
12261 CONVERT_ARG_CHECKED(JSValue, script_value, 0); 12257 CONVERT_ARG_CHECKED(JSValue, script_value, 0);
12262 12258
12263 12259 RUNTIME_ASSERT(script_value->value()->IsScript());
12264 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); 12260 Handle<Script> script = Handle<Script>(Script::cast(script_value->value()));
12265 12261
12266 const int kBufferSize = 32; 12262 const int kBufferSize = 32;
12267 12263
12268 Handle<FixedArray> array; 12264 Handle<FixedArray> array;
12269 array = isolate->factory()->NewFixedArray(kBufferSize); 12265 array = isolate->factory()->NewFixedArray(kBufferSize);
12270 int number; 12266 int number;
12271 { 12267 {
12272 isolate->heap()->EnsureHeapIsIterable(); 12268 isolate->heap()->EnsureHeapIsIterable();
12273 AssertNoAllocation no_allocations; 12269 AssertNoAllocation no_allocations;
(...skipping 25 matching lines...) Expand all
12299 // The source of the actual script is not used, however it is important that 12295 // The source of the actual script is not used, however it is important that
12300 // all generated code keeps references to this particular instance of script. 12296 // all generated code keeps references to this particular instance of script.
12301 // Returns a JSArray of compilation infos. The array is ordered so that 12297 // Returns a JSArray of compilation infos. The array is ordered so that
12302 // each function with all its descendant is always stored in a continues range 12298 // each function with all its descendant is always stored in a continues range
12303 // with the function itself going first. The root function is a script function. 12299 // with the function itself going first. The root function is a script function.
12304 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) { 12300 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) {
12305 ASSERT(args.length() == 2); 12301 ASSERT(args.length() == 2);
12306 HandleScope scope(isolate); 12302 HandleScope scope(isolate);
12307 CONVERT_ARG_CHECKED(JSValue, script, 0); 12303 CONVERT_ARG_CHECKED(JSValue, script, 0);
12308 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); 12304 CONVERT_ARG_HANDLE_CHECKED(String, source, 1);
12305
12306 RUNTIME_ASSERT(script->value()->IsScript());
12309 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 12307 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
12310 12308
12311 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source); 12309 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source);
12312 12310
12313 if (isolate->has_pending_exception()) { 12311 if (isolate->has_pending_exception()) {
12314 return Failure::Exception(); 12312 return Failure::Exception();
12315 } 12313 }
12316 12314
12317 return result; 12315 return result;
12318 } 12316 }
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
13287 // Handle last resort GC and make sure to allow future allocations 13285 // Handle last resort GC and make sure to allow future allocations
13288 // to grow the heap without causing GCs (if possible). 13286 // to grow the heap without causing GCs (if possible).
13289 isolate->counters()->gc_last_resort_from_js()->Increment(); 13287 isolate->counters()->gc_last_resort_from_js()->Increment();
13290 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13288 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13291 "Runtime::PerformGC"); 13289 "Runtime::PerformGC");
13292 } 13290 }
13293 } 13291 }
13294 13292
13295 13293
13296 } } // namespace v8::internal 13294 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698