OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "jsregexp.h" | 45 #include "jsregexp.h" |
46 #include "json-parser.h" | 46 #include "json-parser.h" |
47 #include "liveedit.h" | 47 #include "liveedit.h" |
48 #include "liveobjectlist-inl.h" | 48 #include "liveobjectlist-inl.h" |
49 #include "misc-intrinsics.h" | 49 #include "misc-intrinsics.h" |
50 #include "parser.h" | 50 #include "parser.h" |
51 #include "platform.h" | 51 #include "platform.h" |
52 #include "runtime-profiler.h" | 52 #include "runtime-profiler.h" |
53 #include "runtime.h" | 53 #include "runtime.h" |
54 #include "scopeinfo.h" | 54 #include "scopeinfo.h" |
55 #include "smart-pointer.h" | 55 #include "smart-array-pointer.h" |
56 #include "string-search.h" | 56 #include "string-search.h" |
57 #include "stub-cache.h" | 57 #include "stub-cache.h" |
58 #include "v8threads.h" | 58 #include "v8threads.h" |
59 #include "vm-state-inl.h" | 59 #include "vm-state-inl.h" |
60 | 60 |
61 namespace v8 { | 61 namespace v8 { |
62 namespace internal { | 62 namespace internal { |
63 | 63 |
64 | 64 |
65 #define RUNTIME_ASSERT(value) \ | 65 #define RUNTIME_ASSERT(value) \ |
(...skipping 7825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7891 // directly to properties. | 7891 // directly to properties. |
7892 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; | 7892 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; |
7893 Handle<JSFunction> result = | 7893 Handle<JSFunction> result = |
7894 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 7894 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
7895 context, | 7895 context, |
7896 pretenure_flag); | 7896 pretenure_flag); |
7897 return *result; | 7897 return *result; |
7898 } | 7898 } |
7899 | 7899 |
7900 | 7900 |
7901 static SmartPointer<Object**> GetNonBoundArguments(int bound_argc, | 7901 static SmartArrayPointer<Object**> GetNonBoundArguments(int bound_argc, |
7902 int* total_argc) { | 7902 int* total_argc) { |
7903 // Find frame containing arguments passed to the caller. | 7903 // Find frame containing arguments passed to the caller. |
7904 JavaScriptFrameIterator it; | 7904 JavaScriptFrameIterator it; |
7905 JavaScriptFrame* frame = it.frame(); | 7905 JavaScriptFrame* frame = it.frame(); |
7906 List<JSFunction*> functions(2); | 7906 List<JSFunction*> functions(2); |
7907 frame->GetFunctions(&functions); | 7907 frame->GetFunctions(&functions); |
7908 if (functions.length() > 1) { | 7908 if (functions.length() > 1) { |
7909 int inlined_frame_index = functions.length() - 1; | 7909 int inlined_frame_index = functions.length() - 1; |
7910 JSFunction* inlined_function = functions[inlined_frame_index]; | 7910 JSFunction* inlined_function = functions[inlined_frame_index]; |
7911 int args_count = inlined_function->shared()->formal_parameter_count(); | 7911 int args_count = inlined_function->shared()->formal_parameter_count(); |
7912 ScopedVector<SlotRef> args_slots(args_count); | 7912 ScopedVector<SlotRef> args_slots(args_count); |
7913 SlotRef::ComputeSlotMappingForArguments(frame, | 7913 SlotRef::ComputeSlotMappingForArguments(frame, |
7914 inlined_frame_index, | 7914 inlined_frame_index, |
7915 &args_slots); | 7915 &args_slots); |
7916 | 7916 |
7917 *total_argc = bound_argc + args_count; | 7917 *total_argc = bound_argc + args_count; |
7918 SmartPointer<Object**> param_data(NewArray<Object**>(*total_argc)); | 7918 SmartArrayPointer<Object**> param_data(NewArray<Object**>(*total_argc)); |
7919 for (int i = 0; i < args_count; i++) { | 7919 for (int i = 0; i < args_count; i++) { |
7920 Handle<Object> val = args_slots[i].GetValue(); | 7920 Handle<Object> val = args_slots[i].GetValue(); |
7921 param_data[bound_argc + i] = val.location(); | 7921 param_data[bound_argc + i] = val.location(); |
7922 } | 7922 } |
7923 return param_data; | 7923 return param_data; |
7924 } else { | 7924 } else { |
7925 it.AdvanceToArgumentsFrame(); | 7925 it.AdvanceToArgumentsFrame(); |
7926 frame = it.frame(); | 7926 frame = it.frame(); |
7927 int args_count = frame->ComputeParametersCount(); | 7927 int args_count = frame->ComputeParametersCount(); |
7928 | 7928 |
7929 *total_argc = bound_argc + args_count; | 7929 *total_argc = bound_argc + args_count; |
7930 SmartPointer<Object**> param_data(NewArray<Object**>(*total_argc)); | 7930 SmartArrayPointer<Object**> param_data(NewArray<Object**>(*total_argc)); |
7931 for (int i = 0; i < args_count; i++) { | 7931 for (int i = 0; i < args_count; i++) { |
7932 Handle<Object> val = Handle<Object>(frame->GetParameter(i)); | 7932 Handle<Object> val = Handle<Object>(frame->GetParameter(i)); |
7933 param_data[bound_argc + i] = val.location(); | 7933 param_data[bound_argc + i] = val.location(); |
7934 } | 7934 } |
7935 return param_data; | 7935 return param_data; |
7936 } | 7936 } |
7937 } | 7937 } |
7938 | 7938 |
7939 | 7939 |
7940 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObjectFromBound) { | 7940 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObjectFromBound) { |
7941 HandleScope scope(isolate); | 7941 HandleScope scope(isolate); |
7942 ASSERT(args.length() == 2); | 7942 ASSERT(args.length() == 2); |
7943 // First argument is a function to use as a constructor. | 7943 // First argument is a function to use as a constructor. |
7944 CONVERT_ARG_CHECKED(JSFunction, function, 0); | 7944 CONVERT_ARG_CHECKED(JSFunction, function, 0); |
7945 | 7945 |
7946 // Second argument is either null or an array of bound arguments. | 7946 // Second argument is either null or an array of bound arguments. |
7947 Handle<FixedArray> bound_args; | 7947 Handle<FixedArray> bound_args; |
7948 int bound_argc = 0; | 7948 int bound_argc = 0; |
7949 if (!args[1]->IsNull()) { | 7949 if (!args[1]->IsNull()) { |
7950 CONVERT_ARG_CHECKED(JSArray, params, 1); | 7950 CONVERT_ARG_CHECKED(JSArray, params, 1); |
7951 RUNTIME_ASSERT(params->HasFastElements()); | 7951 RUNTIME_ASSERT(params->HasFastElements()); |
7952 bound_args = Handle<FixedArray>(FixedArray::cast(params->elements())); | 7952 bound_args = Handle<FixedArray>(FixedArray::cast(params->elements())); |
7953 bound_argc = Smi::cast(params->length())->value(); | 7953 bound_argc = Smi::cast(params->length())->value(); |
7954 } | 7954 } |
7955 | 7955 |
7956 int total_argc = 0; | 7956 int total_argc = 0; |
7957 SmartPointer<Object**> param_data = | 7957 SmartArrayPointer<Object**> param_data = |
7958 GetNonBoundArguments(bound_argc, &total_argc); | 7958 GetNonBoundArguments(bound_argc, &total_argc); |
7959 for (int i = 0; i < bound_argc; i++) { | 7959 for (int i = 0; i < bound_argc; i++) { |
7960 Handle<Object> val = Handle<Object>(bound_args->get(i)); | 7960 Handle<Object> val = Handle<Object>(bound_args->get(i)); |
7961 param_data[i] = val.location(); | 7961 param_data[i] = val.location(); |
7962 } | 7962 } |
7963 | 7963 |
7964 bool exception = false; | 7964 bool exception = false; |
7965 Handle<Object> result = | 7965 Handle<Object> result = |
7966 Execution::New(function, total_argc, *param_data, &exception); | 7966 Execution::New(function, total_argc, *param_data, &exception); |
7967 if (exception) { | 7967 if (exception) { |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8866 return Execution::HandleStackGuardInterrupt(); | 8866 return Execution::HandleStackGuardInterrupt(); |
8867 } | 8867 } |
8868 | 8868 |
8869 | 8869 |
8870 // NOTE: These PrintXXX functions are defined for all builds (not just | 8870 // NOTE: These PrintXXX functions are defined for all builds (not just |
8871 // DEBUG builds) because we may want to be able to trace function | 8871 // DEBUG builds) because we may want to be able to trace function |
8872 // calls in all modes. | 8872 // calls in all modes. |
8873 static void PrintString(String* str) { | 8873 static void PrintString(String* str) { |
8874 // not uncommon to have empty strings | 8874 // not uncommon to have empty strings |
8875 if (str->length() > 0) { | 8875 if (str->length() > 0) { |
8876 SmartPointer<char> s = | 8876 SmartArrayPointer<char> s = |
8877 str->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 8877 str->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
8878 PrintF("%s", *s); | 8878 PrintF("%s", *s); |
8879 } | 8879 } |
8880 } | 8880 } |
8881 | 8881 |
8882 | 8882 |
8883 static void PrintObject(Object* obj) { | 8883 static void PrintObject(Object* obj) { |
8884 if (obj->IsSmi()) { | 8884 if (obj->IsSmi()) { |
8885 PrintF("%d", Smi::cast(obj)->value()); | 8885 PrintF("%d", Smi::cast(obj)->value()); |
8886 } else if (obj->IsString() || obj->IsSymbol()) { | 8886 } else if (obj->IsString() || obj->IsSymbol()) { |
(...skipping 3531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12418 return *result; | 12418 return *result; |
12419 } else { | 12419 } else { |
12420 return Failure::Exception(); | 12420 return Failure::Exception(); |
12421 } | 12421 } |
12422 } | 12422 } |
12423 | 12423 |
12424 | 12424 |
12425 // Sets a v8 flag. | 12425 // Sets a v8 flag. |
12426 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetFlags) { | 12426 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetFlags) { |
12427 CONVERT_CHECKED(String, arg, args[0]); | 12427 CONVERT_CHECKED(String, arg, args[0]); |
12428 SmartPointer<char> flags = | 12428 SmartArrayPointer<char> flags = |
12429 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 12429 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
12430 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); | 12430 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); |
12431 return isolate->heap()->undefined_value(); | 12431 return isolate->heap()->undefined_value(); |
12432 } | 12432 } |
12433 | 12433 |
12434 | 12434 |
12435 // Performs a GC. | 12435 // Performs a GC. |
12436 // Presently, it only does a full GC. | 12436 // Presently, it only does a full GC. |
12437 RUNTIME_FUNCTION(MaybeObject*, Runtime_CollectGarbage) { | 12437 RUNTIME_FUNCTION(MaybeObject*, Runtime_CollectGarbage) { |
12438 isolate->heap()->CollectAllGarbage(true); | 12438 isolate->heap()->CollectAllGarbage(true); |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13134 } else { | 13134 } else { |
13135 // Handle last resort GC and make sure to allow future allocations | 13135 // Handle last resort GC and make sure to allow future allocations |
13136 // to grow the heap without causing GCs (if possible). | 13136 // to grow the heap without causing GCs (if possible). |
13137 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13137 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13138 isolate->heap()->CollectAllGarbage(false); | 13138 isolate->heap()->CollectAllGarbage(false); |
13139 } | 13139 } |
13140 } | 13140 } |
13141 | 13141 |
13142 | 13142 |
13143 } } // namespace v8::internal | 13143 } } // namespace v8::internal |
OLD | NEW |