OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 7164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7175 elms->set(0, Smi::FromInt(year)); | 7175 elms->set(0, Smi::FromInt(year)); |
7176 elms->set(1, Smi::FromInt(month)); | 7176 elms->set(1, Smi::FromInt(month)); |
7177 elms->set(2, Smi::FromInt(day)); | 7177 elms->set(2, Smi::FromInt(day)); |
7178 | 7178 |
7179 return isolate->heap()->undefined_value(); | 7179 return isolate->heap()->undefined_value(); |
7180 } | 7180 } |
7181 | 7181 |
7182 | 7182 |
7183 static MaybeObject* Runtime_NewArgumentsFast(RUNTIME_CALLING_CONVENTION) { | 7183 static MaybeObject* Runtime_NewArgumentsFast(RUNTIME_CALLING_CONVENTION) { |
7184 RUNTIME_GET_ISOLATE; | 7184 RUNTIME_GET_ISOLATE; |
7185 HandleScope scope(isolate); | |
7186 ASSERT(args.length() == 3); | |
7187 | |
7188 Handle<JSFunction> callee = args.at<JSFunction>(0); | |
7189 Object** parameters = reinterpret_cast<Object**>(args[1]); | |
7190 const int argument_count = Smi::cast(args[2])->value(); | |
7191 | |
7192 Handle<JSObject> result = | |
7193 isolate->factory()->NewArgumentsObject(callee, argument_count); | |
7194 // Allocate the elements if needed. | |
7195 int parameter_count = callee->shared()->formal_parameter_count(); | |
7196 if (argument_count > 0) { | |
Kevin Millikin (Chromium)
2011/03/23 16:07:20
I'm aware this is monolithic.
There will eventual
| |
7197 if (parameter_count > 0) { | |
7198 int mapped_count = Min(argument_count, parameter_count); | |
7199 Handle<FixedArray> parameter_map = | |
7200 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); | |
7201 parameter_map->set_map( | |
7202 isolate->heap()->non_strict_arguments_elements_map()); | |
7203 | |
7204 Handle<Map> old_map(result->map()); | |
7205 Handle<Map> new_map = | |
7206 isolate->factory()->CopyMapDropTransitions(old_map); | |
7207 new_map->set_has_fast_elements(false); | |
7208 | |
7209 result->set_map(*new_map); | |
7210 result->set_elements(*parameter_map); | |
7211 | |
7212 // Store the context and the arguments array at the end of the | |
Mads Ager (chromium)
2011/03/24 08:04:04
end -> beginning?
elements array -> parameter map
Kevin Millikin (Chromium)
2011/03/24 08:42:51
Thanks. Those were some stale comments.
| |
7213 // elements array. | |
7214 Handle<Context> context(isolate->context()); | |
7215 Handle<FixedArray> arguments = | |
7216 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); | |
7217 parameter_map->set(0, *context); | |
7218 parameter_map->set(1, *arguments); | |
7219 | |
7220 // Loop over the actual parameters backwards. | |
7221 int index = argument_count - 1; | |
7222 while (index >= mapped_count) { | |
7223 // These go directly in the arguments array and have no | |
7224 // corresponding slot in the elements array. | |
7225 arguments->set(index, *(parameters - index - 1)); | |
7226 --index; | |
7227 } | |
7228 | |
7229 ScopeInfo<> scope_info(callee->shared()->scope_info()); | |
7230 while (index >= 0) { | |
7231 // Detect duplicate names. | |
7232 Handle<String> name = scope_info.parameter_name(index); | |
7233 int context_slot_count = scope_info.number_of_context_slots(); | |
7234 bool duplicate = false; | |
7235 for (int j = 0; j < index; ++j) { | |
7236 if (scope_info.parameter_name(j).is_identical_to(name)) { | |
7237 duplicate = true; | |
7238 break; | |
7239 } | |
7240 } | |
7241 | |
7242 if (duplicate) { | |
7243 // This goes directly in the arguments array with a hole in the | |
7244 // elements array. | |
Mads Ager (chromium)
2011/03/24 08:04:04
elements array -> parameter map
| |
7245 arguments->set(index, *(parameters - index - 1)); | |
7246 parameter_map->set_the_hole(index + 2); | |
7247 } else { | |
7248 // The context index goes in the elements array with a hole in the | |
Mads Ager (chromium)
2011/03/24 08:04:04
elements array -> parameter map
| |
7249 // arguments array. | |
7250 int context_index = -1; | |
7251 for (int j = Context::MIN_CONTEXT_SLOTS; | |
7252 j < context_slot_count; | |
7253 ++j) { | |
7254 if (scope_info.context_slot_name(j).is_identical_to(name)) { | |
7255 context_index = j; | |
7256 break; | |
7257 } | |
7258 } | |
7259 ASSERT(context_index >= 0); | |
7260 arguments->set_the_hole(index); | |
7261 parameter_map->set(index + 2, Smi::FromInt(context_index)); | |
7262 } | |
7263 | |
7264 --index; | |
7265 } | |
7266 } else { | |
7267 Handle<FixedArray> elements = | |
7268 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); | |
7269 result->set_elements(*elements); | |
7270 for (int i = 0; i < argument_count; ++i) { | |
7271 elements->set(i, *(parameters - i - 1)); | |
7272 } | |
7273 } | |
7274 } | |
7275 return *result; | |
7276 } | |
7277 | |
7278 | |
7279 static MaybeObject* Runtime_NewStrictArgumentsFast(RUNTIME_CALLING_CONVENTION) { | |
7280 RUNTIME_GET_ISOLATE; | |
7185 NoHandleAllocation ha; | 7281 NoHandleAllocation ha; |
7186 ASSERT(args.length() == 3); | 7282 ASSERT(args.length() == 3); |
7187 | 7283 |
7188 JSFunction* callee = JSFunction::cast(args[0]); | 7284 JSFunction* callee = JSFunction::cast(args[0]); |
7189 Object** parameters = reinterpret_cast<Object**>(args[1]); | 7285 Object** parameters = reinterpret_cast<Object**>(args[1]); |
7190 const int length = Smi::cast(args[2])->value(); | 7286 const int length = Smi::cast(args[2])->value(); |
7191 | 7287 |
7192 Object* result; | 7288 Object* result; |
7193 { MaybeObject* maybe_result = | 7289 { MaybeObject* maybe_result = |
7194 isolate->heap()->AllocateArgumentsObject(callee, length); | 7290 isolate->heap()->AllocateArgumentsObject(callee, length); |
(...skipping 3481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10676 | 10772 |
10677 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { | 10773 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { |
10678 index = scope_info->ContextSlotIndex(isolate->heap()->arguments_symbol(), | 10774 index = scope_info->ContextSlotIndex(isolate->heap()->arguments_symbol(), |
10679 NULL); | 10775 NULL); |
10680 if (index != -1) { | 10776 if (index != -1) { |
10681 return Handle<Object>(function_context->get(index), isolate); | 10777 return Handle<Object>(function_context->get(index), isolate); |
10682 } | 10778 } |
10683 } | 10779 } |
10684 | 10780 |
10685 const int length = frame->ComputeParametersCount(); | 10781 const int length = frame->ComputeParametersCount(); |
10782 UNIMPLEMENTED(); | |
10686 Handle<JSObject> arguments = | 10783 Handle<JSObject> arguments = |
10687 isolate->factory()->NewArgumentsObject(function, length); | 10784 isolate->factory()->NewArgumentsObject(function, length); |
10688 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); | 10785 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); |
10689 | 10786 |
10690 AssertNoAllocation no_gc; | 10787 AssertNoAllocation no_gc; |
10691 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); | 10788 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); |
10692 for (int i = 0; i < length; i++) { | 10789 for (int i = 0; i < length; i++) { |
10693 array->set(i, frame->GetParameter(i), mode); | 10790 array->set(i, frame->GetParameter(i), mode); |
10694 } | 10791 } |
10695 arguments->set_elements(*array); | 10792 arguments->set_elements(*array); |
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12199 } else { | 12296 } else { |
12200 // Handle last resort GC and make sure to allow future allocations | 12297 // Handle last resort GC and make sure to allow future allocations |
12201 // to grow the heap without causing GCs (if possible). | 12298 // to grow the heap without causing GCs (if possible). |
12202 COUNTERS->gc_last_resort_from_js()->Increment(); | 12299 COUNTERS->gc_last_resort_from_js()->Increment(); |
12203 HEAP->CollectAllGarbage(false); | 12300 HEAP->CollectAllGarbage(false); |
12204 } | 12301 } |
12205 } | 12302 } |
12206 | 12303 |
12207 | 12304 |
12208 } } // namespace v8::internal | 12305 } } // namespace v8::internal |
OLD | NEW |