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

Side by Side Diff: src/runtime.cc

Issue 3473024: [Isolates] More handle improvements: (Closed)
Patch Set: Created 10 years, 2 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
« no previous file with comments | « src/runtime.h ('k') | test/cctest/test-func-name-inference.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 double name = (obj)->Number(); 95 double name = (obj)->Number();
96 96
97 // Call the specified converter on the object *comand store the result in 97 // Call the specified converter on the object *comand store the result in
98 // a variable of the specified type with the given name. If the 98 // a variable of the specified type with the given name. If the
99 // object is not a Number call IllegalOperation and return. 99 // object is not a Number call IllegalOperation and return.
100 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \ 100 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \
101 RUNTIME_ASSERT(obj->IsNumber()); \ 101 RUNTIME_ASSERT(obj->IsNumber()); \
102 type name = NumberTo##Type(obj); 102 type name = NumberTo##Type(obj);
103 103
104 104
105 MUST_USE_RESULT static Object* DeepCopyBoilerplate(Heap* heap, 105 MUST_USE_RESULT static Object* DeepCopyBoilerplate(Isolate* isolate,
106 JSObject* boilerplate) { 106 JSObject* boilerplate) {
107 StackLimitCheck check(heap->isolate()); 107 StackLimitCheck check(isolate);
108 if (check.HasOverflowed()) return heap->isolate()->StackOverflow(); 108 if (check.HasOverflowed()) return isolate->StackOverflow();
109 109
110 Heap* heap = isolate->heap();
110 Object* result = heap->CopyJSObject(boilerplate); 111 Object* result = heap->CopyJSObject(boilerplate);
111 if (result->IsFailure()) return result; 112 if (result->IsFailure()) return result;
112 JSObject* copy = JSObject::cast(result); 113 JSObject* copy = JSObject::cast(result);
113 114
114 // Deep copy local properties. 115 // Deep copy local properties.
115 if (copy->HasFastProperties()) { 116 if (copy->HasFastProperties()) {
116 FixedArray* properties = copy->properties(); 117 FixedArray* properties = copy->properties();
117 for (int i = 0; i < properties->length(); i++) { 118 for (int i = 0; i < properties->length(); i++) {
118 Object* value = properties->get(i); 119 Object* value = properties->get(i);
119 if (value->IsJSObject()) { 120 if (value->IsJSObject()) {
120 JSObject* js_object = JSObject::cast(value); 121 JSObject* js_object = JSObject::cast(value);
121 result = DeepCopyBoilerplate(heap, js_object); 122 result = DeepCopyBoilerplate(isolate, js_object);
122 if (result->IsFailure()) return result; 123 if (result->IsFailure()) return result;
123 properties->set(i, result); 124 properties->set(i, result);
124 } 125 }
125 } 126 }
126 int nof = copy->map()->inobject_properties(); 127 int nof = copy->map()->inobject_properties();
127 for (int i = 0; i < nof; i++) { 128 for (int i = 0; i < nof; i++) {
128 Object* value = copy->InObjectPropertyAt(i); 129 Object* value = copy->InObjectPropertyAt(i);
129 if (value->IsJSObject()) { 130 if (value->IsJSObject()) {
130 JSObject* js_object = JSObject::cast(value); 131 JSObject* js_object = JSObject::cast(value);
131 result = DeepCopyBoilerplate(heap, js_object); 132 result = DeepCopyBoilerplate(isolate, js_object);
132 if (result->IsFailure()) return result; 133 if (result->IsFailure()) return result;
133 copy->InObjectPropertyAtPut(i, result); 134 copy->InObjectPropertyAtPut(i, result);
134 } 135 }
135 } 136 }
136 } else { 137 } else {
137 result = heap->AllocateFixedArray(copy->NumberOfLocalProperties(NONE)); 138 result = heap->AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
138 if (result->IsFailure()) return result; 139 if (result->IsFailure()) return result;
139 FixedArray* names = FixedArray::cast(result); 140 FixedArray* names = FixedArray::cast(result);
140 copy->GetLocalPropertyNames(names, 0); 141 copy->GetLocalPropertyNames(names, 0);
141 for (int i = 0; i < names->length(); i++) { 142 for (int i = 0; i < names->length(); i++) {
142 ASSERT(names->get(i)->IsString()); 143 ASSERT(names->get(i)->IsString());
143 String* key_string = String::cast(names->get(i)); 144 String* key_string = String::cast(names->get(i));
144 PropertyAttributes attributes = 145 PropertyAttributes attributes =
145 copy->GetLocalPropertyAttribute(key_string); 146 copy->GetLocalPropertyAttribute(key_string);
146 // Only deep copy fields from the object literal expression. 147 // Only deep copy fields from the object literal expression.
147 // In particular, don't try to copy the length attribute of 148 // In particular, don't try to copy the length attribute of
148 // an array. 149 // an array.
149 if (attributes != NONE) continue; 150 if (attributes != NONE) continue;
150 Object* value = copy->GetProperty(key_string, &attributes); 151 Object* value = copy->GetProperty(key_string, &attributes);
151 ASSERT(!value->IsFailure()); 152 ASSERT(!value->IsFailure());
152 if (value->IsJSObject()) { 153 if (value->IsJSObject()) {
153 JSObject* js_object = JSObject::cast(value); 154 JSObject* js_object = JSObject::cast(value);
154 result = DeepCopyBoilerplate(heap, js_object); 155 result = DeepCopyBoilerplate(isolate, js_object);
155 if (result->IsFailure()) return result; 156 if (result->IsFailure()) return result;
156 result = copy->SetProperty(key_string, result, NONE); 157 result = copy->SetProperty(key_string, result, NONE);
157 if (result->IsFailure()) return result; 158 if (result->IsFailure()) return result;
158 } 159 }
159 } 160 }
160 } 161 }
161 162
162 // Deep copy local elements. 163 // Deep copy local elements.
163 // Pixel elements cannot be created using an object literal. 164 // Pixel elements cannot be created using an object literal.
164 ASSERT(!copy->HasPixelElements() && !copy->HasExternalArrayElements()); 165 ASSERT(!copy->HasPixelElements() && !copy->HasExternalArrayElements());
165 switch (copy->GetElementsKind()) { 166 switch (copy->GetElementsKind()) {
166 case JSObject::FAST_ELEMENTS: { 167 case JSObject::FAST_ELEMENTS: {
167 FixedArray* elements = FixedArray::cast(copy->elements()); 168 FixedArray* elements = FixedArray::cast(copy->elements());
168 if (elements->map() == heap->fixed_cow_array_map()) { 169 if (elements->map() == heap->fixed_cow_array_map()) {
169 heap->isolate()->counters()->cow_arrays_created_runtime()->Increment(); 170 isolate->counters()->cow_arrays_created_runtime()->Increment();
170 #ifdef DEBUG 171 #ifdef DEBUG
171 for (int i = 0; i < elements->length(); i++) { 172 for (int i = 0; i < elements->length(); i++) {
172 ASSERT(!elements->get(i)->IsJSObject()); 173 ASSERT(!elements->get(i)->IsJSObject());
173 } 174 }
174 #endif 175 #endif
175 } else { 176 } else {
176 for (int i = 0; i < elements->length(); i++) { 177 for (int i = 0; i < elements->length(); i++) {
177 Object* value = elements->get(i); 178 Object* value = elements->get(i);
178 if (value->IsJSObject()) { 179 if (value->IsJSObject()) {
179 JSObject* js_object = JSObject::cast(value); 180 JSObject* js_object = JSObject::cast(value);
180 result = DeepCopyBoilerplate(heap, js_object); 181 result = DeepCopyBoilerplate(isolate, js_object);
181 if (result->IsFailure()) return result; 182 if (result->IsFailure()) return result;
182 elements->set(i, result); 183 elements->set(i, result);
183 } 184 }
184 } 185 }
185 } 186 }
186 break; 187 break;
187 } 188 }
188 case JSObject::DICTIONARY_ELEMENTS: { 189 case JSObject::DICTIONARY_ELEMENTS: {
189 NumberDictionary* element_dictionary = copy->element_dictionary(); 190 NumberDictionary* element_dictionary = copy->element_dictionary();
190 int capacity = element_dictionary->Capacity(); 191 int capacity = element_dictionary->Capacity();
191 for (int i = 0; i < capacity; i++) { 192 for (int i = 0; i < capacity; i++) {
192 Object* k = element_dictionary->KeyAt(i); 193 Object* k = element_dictionary->KeyAt(i);
193 if (element_dictionary->IsKey(k)) { 194 if (element_dictionary->IsKey(k)) {
194 Object* value = element_dictionary->ValueAt(i); 195 Object* value = element_dictionary->ValueAt(i);
195 if (value->IsJSObject()) { 196 if (value->IsJSObject()) {
196 JSObject* js_object = JSObject::cast(value); 197 JSObject* js_object = JSObject::cast(value);
197 result = DeepCopyBoilerplate(heap, js_object); 198 result = DeepCopyBoilerplate(isolate, js_object);
198 if (result->IsFailure()) return result; 199 if (result->IsFailure()) return result;
199 element_dictionary->ValueAtPut(i, result); 200 element_dictionary->ValueAtPut(i, result);
200 } 201 }
201 } 202 }
202 } 203 }
203 break; 204 break;
204 } 205 }
205 default: 206 default:
206 UNREACHABLE(); 207 UNREACHABLE();
207 break; 208 break;
208 } 209 }
209 return copy; 210 return copy;
210 } 211 }
211 212
212 213
213 static Object* Runtime_CloneLiteralBoilerplate(RUNTIME_CALLING_CONVENTION) { 214 static Object* Runtime_CloneLiteralBoilerplate(RUNTIME_CALLING_CONVENTION) {
214 RUNTIME_GET_ISOLATE; 215 RUNTIME_GET_ISOLATE;
215 CONVERT_CHECKED(JSObject, boilerplate, args[0]); 216 CONVERT_CHECKED(JSObject, boilerplate, args[0]);
216 return DeepCopyBoilerplate(isolate->heap(), boilerplate); 217 return DeepCopyBoilerplate(isolate, boilerplate);
217 } 218 }
218 219
219 220
220 static Object* Runtime_CloneShallowLiteralBoilerplate( 221 static Object* Runtime_CloneShallowLiteralBoilerplate(
221 RUNTIME_CALLING_CONVENTION) { 222 RUNTIME_CALLING_CONVENTION) {
222 RUNTIME_GET_ISOLATE; 223 RUNTIME_GET_ISOLATE;
223 CONVERT_CHECKED(JSObject, boilerplate, args[0]); 224 CONVERT_CHECKED(JSObject, boilerplate, args[0]);
224 return isolate->heap()->CopyJSObject(boilerplate); 225 return isolate->heap()->CopyJSObject(boilerplate);
225 } 226 }
226 227
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 272 }
272 } 273 }
273 *is_result_from_cache = false; 274 *is_result_from_cache = false;
274 return Factory::CopyMap( 275 return Factory::CopyMap(
275 Handle<Map>(context->object_function()->initial_map()), 276 Handle<Map>(context->object_function()->initial_map()),
276 number_of_properties); 277 number_of_properties);
277 } 278 }
278 279
279 280
280 static Handle<Object> CreateLiteralBoilerplate( 281 static Handle<Object> CreateLiteralBoilerplate(
282 Isolate* isolate,
281 Handle<FixedArray> literals, 283 Handle<FixedArray> literals,
282 Handle<FixedArray> constant_properties); 284 Handle<FixedArray> constant_properties);
283 285
284 286
285 static Handle<Object> CreateObjectLiteralBoilerplate( 287 static Handle<Object> CreateObjectLiteralBoilerplate(
288 Isolate* isolate,
286 Handle<FixedArray> literals, 289 Handle<FixedArray> literals,
287 Handle<FixedArray> constant_properties, 290 Handle<FixedArray> constant_properties,
288 bool should_have_fast_elements) { 291 bool should_have_fast_elements) {
289 // Get the global context from the literals array. This is the 292 // Get the global context from the literals array. This is the
290 // context in which the function was created and we use the object 293 // context in which the function was created and we use the object
291 // function from this context to create the object literal. We do 294 // function from this context to create the object literal. We do
292 // not use the object function from the current global context 295 // not use the object function from the current global context
293 // because this might be the object function from another context 296 // because this might be the object function from another context
294 // which we should not have access to. 297 // which we should not have access to.
295 Handle<Context> context = 298 Handle<Context> context =
296 Handle<Context>(JSFunction::GlobalContextFromLiterals(*literals)); 299 Handle<Context>(JSFunction::GlobalContextFromLiterals(*literals));
297 300
298 bool is_result_from_cache; 301 bool is_result_from_cache;
299 Handle<Map> map = ComputeObjectLiteralMap(context, 302 Handle<Map> map = ComputeObjectLiteralMap(context,
300 constant_properties, 303 constant_properties,
301 &is_result_from_cache); 304 &is_result_from_cache);
302 305
303 Handle<JSObject> boilerplate = Factory::NewJSObjectFromMap(map); 306 Handle<JSObject> boilerplate = Factory::NewJSObjectFromMap(map);
304 307
305 // Normalize the elements of the boilerplate to save space if needed. 308 // Normalize the elements of the boilerplate to save space if needed.
306 if (!should_have_fast_elements) NormalizeElements(boilerplate); 309 if (!should_have_fast_elements) NormalizeElements(boilerplate);
307 310
308 { // Add the constant properties to the boilerplate. 311 { // Add the constant properties to the boilerplate.
309 int length = constant_properties->length(); 312 int length = constant_properties->length();
310 OptimizedObjectForAddingMultipleProperties opt(boilerplate, 313 OptimizedObjectForAddingMultipleProperties opt(boilerplate,
311 length / 2, 314 length / 2,
312 !is_result_from_cache); 315 !is_result_from_cache);
313 for (int index = 0; index < length; index +=2) { 316 for (int index = 0; index < length; index +=2) {
314 Handle<Object> key(constant_properties->get(index+0)); 317 Handle<Object> key(constant_properties->get(index+0), isolate);
315 Handle<Object> value(constant_properties->get(index+1)); 318 Handle<Object> value(constant_properties->get(index+1), isolate);
316 if (value->IsFixedArray()) { 319 if (value->IsFixedArray()) {
317 // The value contains the constant_properties of a 320 // The value contains the constant_properties of a
318 // simple object literal. 321 // simple object literal.
319 Handle<FixedArray> array = Handle<FixedArray>::cast(value); 322 Handle<FixedArray> array = Handle<FixedArray>::cast(value);
320 value = CreateLiteralBoilerplate(literals, array); 323 value = CreateLiteralBoilerplate(isolate, literals, array);
321 if (value.is_null()) return value; 324 if (value.is_null()) return value;
322 } 325 }
323 Handle<Object> result; 326 Handle<Object> result;
324 uint32_t element_index = 0; 327 uint32_t element_index = 0;
325 if (key->IsSymbol()) { 328 if (key->IsSymbol()) {
326 // If key is a symbol it is not an array element. 329 // If key is a symbol it is not an array element.
327 Handle<String> name(String::cast(*key)); 330 Handle<String> name(String::cast(*key));
328 ASSERT(!name->AsArrayIndex(&element_index)); 331 ASSERT(!name->AsArrayIndex(&element_index));
329 result = SetProperty(boilerplate, name, value, NONE); 332 result = SetProperty(boilerplate, name, value, NONE);
330 } else if (key->ToArrayIndex(&element_index)) { 333 } else if (key->ToArrayIndex(&element_index)) {
(...skipping 15 matching lines...) Expand all
346 // convert back to an exception. 349 // convert back to an exception.
347 if (result.is_null()) return result; 350 if (result.is_null()) return result;
348 } 351 }
349 } 352 }
350 353
351 return boilerplate; 354 return boilerplate;
352 } 355 }
353 356
354 357
355 static Handle<Object> CreateArrayLiteralBoilerplate( 358 static Handle<Object> CreateArrayLiteralBoilerplate(
359 Isolate* isolate,
356 Handle<FixedArray> literals, 360 Handle<FixedArray> literals,
357 Handle<FixedArray> elements) { 361 Handle<FixedArray> elements) {
358 // Create the JSArray. 362 // Create the JSArray.
359 Handle<JSFunction> constructor( 363 Handle<JSFunction> constructor(
360 JSFunction::GlobalContextFromLiterals(*literals)->array_function()); 364 JSFunction::GlobalContextFromLiterals(*literals)->array_function());
361 Handle<Object> object = Factory::NewJSObject(constructor); 365 Handle<Object> object = Factory::NewJSObject(constructor);
362 366
363 const bool is_cow = (elements->map() == HEAP->fixed_cow_array_map()); 367 const bool is_cow =
368 (elements->map() == isolate->heap()->fixed_cow_array_map());
364 Handle<FixedArray> copied_elements = 369 Handle<FixedArray> copied_elements =
365 is_cow ? elements : Factory::CopyFixedArray(elements); 370 is_cow ? elements : Factory::CopyFixedArray(elements);
366 371
367 Handle<FixedArray> content = Handle<FixedArray>::cast(copied_elements); 372 Handle<FixedArray> content = Handle<FixedArray>::cast(copied_elements);
368 if (is_cow) { 373 if (is_cow) {
369 #ifdef DEBUG 374 #ifdef DEBUG
370 // Copy-on-write arrays must be shallow (and simple). 375 // Copy-on-write arrays must be shallow (and simple).
371 for (int i = 0; i < content->length(); i++) { 376 for (int i = 0; i < content->length(); i++) {
372 ASSERT(!content->get(i)->IsFixedArray()); 377 ASSERT(!content->get(i)->IsFixedArray());
373 } 378 }
374 #endif 379 #endif
375 } else { 380 } else {
376 for (int i = 0; i < content->length(); i++) { 381 for (int i = 0; i < content->length(); i++) {
377 if (content->get(i)->IsFixedArray()) { 382 if (content->get(i)->IsFixedArray()) {
378 // The value contains the constant_properties of a 383 // The value contains the constant_properties of a
379 // simple object literal. 384 // simple object literal.
380 Handle<FixedArray> fa(FixedArray::cast(content->get(i))); 385 Handle<FixedArray> fa(FixedArray::cast(content->get(i)));
381 Handle<Object> result = 386 Handle<Object> result =
382 CreateLiteralBoilerplate(literals, fa); 387 CreateLiteralBoilerplate(isolate, literals, fa);
383 if (result.is_null()) return result; 388 if (result.is_null()) return result;
384 content->set(i, *result); 389 content->set(i, *result);
385 } 390 }
386 } 391 }
387 } 392 }
388 393
389 // Set the elements. 394 // Set the elements.
390 Handle<JSArray>::cast(object)->SetContent(*content); 395 Handle<JSArray>::cast(object)->SetContent(*content);
391 return object; 396 return object;
392 } 397 }
393 398
394 399
395 static Handle<Object> CreateLiteralBoilerplate( 400 static Handle<Object> CreateLiteralBoilerplate(
401 Isolate* isolate,
396 Handle<FixedArray> literals, 402 Handle<FixedArray> literals,
397 Handle<FixedArray> array) { 403 Handle<FixedArray> array) {
398 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); 404 Handle<FixedArray> elements = CompileTimeValue::GetElements(array);
399 switch (CompileTimeValue::GetType(array)) { 405 switch (CompileTimeValue::GetType(array)) {
400 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: 406 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS:
401 return CreateObjectLiteralBoilerplate(literals, elements, true); 407 return CreateObjectLiteralBoilerplate(isolate, literals, elements, true);
402 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: 408 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS:
403 return CreateObjectLiteralBoilerplate(literals, elements, false); 409 return CreateObjectLiteralBoilerplate(isolate, literals, elements, false);
404 case CompileTimeValue::ARRAY_LITERAL: 410 case CompileTimeValue::ARRAY_LITERAL:
405 return CreateArrayLiteralBoilerplate(literals, elements); 411 return CreateArrayLiteralBoilerplate(isolate, literals, elements);
406 default: 412 default:
407 UNREACHABLE(); 413 UNREACHABLE();
408 return Handle<Object>::null(); 414 return Handle<Object>::null();
409 } 415 }
410 } 416 }
411 417
412 418
413 static Object* Runtime_CreateArrayLiteralBoilerplate( 419 static Object* Runtime_CreateArrayLiteralBoilerplate(
414 RUNTIME_CALLING_CONVENTION) { 420 RUNTIME_CALLING_CONVENTION) {
415 RUNTIME_GET_ISOLATE; 421 RUNTIME_GET_ISOLATE;
416 // Takes a FixedArray of elements containing the literal elements of 422 // Takes a FixedArray of elements containing the literal elements of
417 // the array literal and produces JSArray with those elements. 423 // the array literal and produces JSArray with those elements.
418 // Additionally takes the literals array of the surrounding function 424 // Additionally takes the literals array of the surrounding function
419 // which contains the context from which to get the Array function 425 // which contains the context from which to get the Array function
420 // to use for creating the array literal. 426 // to use for creating the array literal.
421 HandleScope scope; 427 HandleScope scope(isolate);
422 ASSERT(args.length() == 3); 428 ASSERT(args.length() == 3);
423 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 429 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
424 CONVERT_SMI_CHECKED(literals_index, args[1]); 430 CONVERT_SMI_CHECKED(literals_index, args[1]);
425 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 431 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
426 432
427 Handle<Object> object = CreateArrayLiteralBoilerplate(literals, elements); 433 Handle<Object> object =
434 CreateArrayLiteralBoilerplate(isolate, literals, elements);
428 if (object.is_null()) return Failure::Exception(); 435 if (object.is_null()) return Failure::Exception();
429 436
430 // Update the functions literal and return the boilerplate. 437 // Update the functions literal and return the boilerplate.
431 literals->set(literals_index, *object); 438 literals->set(literals_index, *object);
432 return *object; 439 return *object;
433 } 440 }
434 441
435 442
436 static Object* Runtime_CreateObjectLiteral(RUNTIME_CALLING_CONVENTION) { 443 static Object* Runtime_CreateObjectLiteral(RUNTIME_CALLING_CONVENTION) {
437 RUNTIME_GET_ISOLATE; 444 RUNTIME_GET_ISOLATE;
438 HandleScope scope; 445 HandleScope scope(isolate);
439 ASSERT(args.length() == 4); 446 ASSERT(args.length() == 4);
440 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 447 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
441 CONVERT_SMI_CHECKED(literals_index, args[1]); 448 CONVERT_SMI_CHECKED(literals_index, args[1]);
442 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2); 449 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2);
443 CONVERT_SMI_CHECKED(fast_elements, args[3]); 450 CONVERT_SMI_CHECKED(fast_elements, args[3]);
444 bool should_have_fast_elements = fast_elements == 1; 451 bool should_have_fast_elements = fast_elements == 1;
445 452
446 // Check if boilerplate exists. If not, create it first. 453 // Check if boilerplate exists. If not, create it first.
447 Handle<Object> boilerplate(literals->get(literals_index)); 454 Handle<Object> boilerplate(literals->get(literals_index), isolate);
448 if (*boilerplate == isolate->heap()->undefined_value()) { 455 if (*boilerplate == isolate->heap()->undefined_value()) {
449 boilerplate = CreateObjectLiteralBoilerplate(literals, 456 boilerplate = CreateObjectLiteralBoilerplate(isolate,
457 literals,
450 constant_properties, 458 constant_properties,
451 should_have_fast_elements); 459 should_have_fast_elements);
452 if (boilerplate.is_null()) return Failure::Exception(); 460 if (boilerplate.is_null()) return Failure::Exception();
453 // Update the functions literal and return the boilerplate. 461 // Update the functions literal and return the boilerplate.
454 literals->set(literals_index, *boilerplate); 462 literals->set(literals_index, *boilerplate);
455 } 463 }
456 return DeepCopyBoilerplate(isolate->heap(), JSObject::cast(*boilerplate)); 464 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate));
457 } 465 }
458 466
459 467
460 static Object* Runtime_CreateObjectLiteralShallow(RUNTIME_CALLING_CONVENTION) { 468 static Object* Runtime_CreateObjectLiteralShallow(RUNTIME_CALLING_CONVENTION) {
461 RUNTIME_GET_ISOLATE; 469 RUNTIME_GET_ISOLATE;
462 HandleScope scope; 470 HandleScope scope(isolate);
463 ASSERT(args.length() == 4); 471 ASSERT(args.length() == 4);
464 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 472 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
465 CONVERT_SMI_CHECKED(literals_index, args[1]); 473 CONVERT_SMI_CHECKED(literals_index, args[1]);
466 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2); 474 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2);
467 CONVERT_SMI_CHECKED(fast_elements, args[3]); 475 CONVERT_SMI_CHECKED(fast_elements, args[3]);
468 bool should_have_fast_elements = fast_elements == 1; 476 bool should_have_fast_elements = fast_elements == 1;
469 477
470 // Check if boilerplate exists. If not, create it first. 478 // Check if boilerplate exists. If not, create it first.
471 Handle<Object> boilerplate(literals->get(literals_index)); 479 Handle<Object> boilerplate(literals->get(literals_index), isolate);
472 if (*boilerplate == isolate->heap()->undefined_value()) { 480 if (*boilerplate == isolate->heap()->undefined_value()) {
473 boilerplate = CreateObjectLiteralBoilerplate(literals, 481 boilerplate = CreateObjectLiteralBoilerplate(isolate,
482 literals,
474 constant_properties, 483 constant_properties,
475 should_have_fast_elements); 484 should_have_fast_elements);
476 if (boilerplate.is_null()) return Failure::Exception(); 485 if (boilerplate.is_null()) return Failure::Exception();
477 // Update the functions literal and return the boilerplate. 486 // Update the functions literal and return the boilerplate.
478 literals->set(literals_index, *boilerplate); 487 literals->set(literals_index, *boilerplate);
479 } 488 }
480 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate)); 489 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate));
481 } 490 }
482 491
483 492
484 static Object* Runtime_CreateArrayLiteral(RUNTIME_CALLING_CONVENTION) { 493 static Object* Runtime_CreateArrayLiteral(RUNTIME_CALLING_CONVENTION) {
485 RUNTIME_GET_ISOLATE; 494 RUNTIME_GET_ISOLATE;
486 HandleScope scope; 495 HandleScope scope(isolate);
487 ASSERT(args.length() == 3); 496 ASSERT(args.length() == 3);
488 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 497 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
489 CONVERT_SMI_CHECKED(literals_index, args[1]); 498 CONVERT_SMI_CHECKED(literals_index, args[1]);
490 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 499 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
491 500
492 // Check if boilerplate exists. If not, create it first. 501 // Check if boilerplate exists. If not, create it first.
493 Handle<Object> boilerplate(literals->get(literals_index)); 502 Handle<Object> boilerplate(literals->get(literals_index), isolate);
494 if (*boilerplate == isolate->heap()->undefined_value()) { 503 if (*boilerplate == isolate->heap()->undefined_value()) {
495 boilerplate = CreateArrayLiteralBoilerplate(literals, elements); 504 boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements);
496 if (boilerplate.is_null()) return Failure::Exception(); 505 if (boilerplate.is_null()) return Failure::Exception();
497 // Update the functions literal and return the boilerplate. 506 // Update the functions literal and return the boilerplate.
498 literals->set(literals_index, *boilerplate); 507 literals->set(literals_index, *boilerplate);
499 } 508 }
500 return DeepCopyBoilerplate(isolate->heap(), JSObject::cast(*boilerplate)); 509 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate));
501 } 510 }
502 511
503 512
504 static Object* Runtime_CreateArrayLiteralShallow(RUNTIME_CALLING_CONVENTION) { 513 static Object* Runtime_CreateArrayLiteralShallow(RUNTIME_CALLING_CONVENTION) {
505 RUNTIME_GET_ISOLATE; 514 RUNTIME_GET_ISOLATE;
506 HandleScope scope; 515 HandleScope scope(isolate);
507 ASSERT(args.length() == 3); 516 ASSERT(args.length() == 3);
508 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 517 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
509 CONVERT_SMI_CHECKED(literals_index, args[1]); 518 CONVERT_SMI_CHECKED(literals_index, args[1]);
510 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 519 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
511 520
512 // Check if boilerplate exists. If not, create it first. 521 // Check if boilerplate exists. If not, create it first.
513 Handle<Object> boilerplate(literals->get(literals_index)); 522 Handle<Object> boilerplate(literals->get(literals_index), isolate);
514 if (*boilerplate == isolate->heap()->undefined_value()) { 523 if (*boilerplate == isolate->heap()->undefined_value()) {
515 boilerplate = CreateArrayLiteralBoilerplate(literals, elements); 524 boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements);
516 if (boilerplate.is_null()) return Failure::Exception(); 525 if (boilerplate.is_null()) return Failure::Exception();
517 // Update the functions literal and return the boilerplate. 526 // Update the functions literal and return the boilerplate.
518 literals->set(literals_index, *boilerplate); 527 literals->set(literals_index, *boilerplate);
519 } 528 }
520 if (JSObject::cast(*boilerplate)->elements()->map() == 529 if (JSObject::cast(*boilerplate)->elements()->map() ==
521 isolate->heap()->fixed_cow_array_map()) { 530 isolate->heap()->fixed_cow_array_map()) {
522 COUNTERS->cow_arrays_created_runtime()->Increment(); 531 COUNTERS->cow_arrays_created_runtime()->Increment();
523 } 532 }
524 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate)); 533 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate));
525 } 534 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 // if args[1] is not a property on args[0] 657 // if args[1] is not a property on args[0]
649 // returns undefined 658 // returns undefined
650 // if args[1] is a data property on args[0] 659 // if args[1] is a data property on args[0]
651 // [false, value, Writeable, Enumerable, Configurable] 660 // [false, value, Writeable, Enumerable, Configurable]
652 // if args[1] is an accessor on args[0] 661 // if args[1] is an accessor on args[0]
653 // [true, GetFunction, SetFunction, Enumerable, Configurable] 662 // [true, GetFunction, SetFunction, Enumerable, Configurable]
654 static Object* Runtime_GetOwnProperty(RUNTIME_CALLING_CONVENTION) { 663 static Object* Runtime_GetOwnProperty(RUNTIME_CALLING_CONVENTION) {
655 RUNTIME_GET_ISOLATE; 664 RUNTIME_GET_ISOLATE;
656 ASSERT(args.length() == 2); 665 ASSERT(args.length() == 2);
657 Heap* heap = isolate->heap(); 666 Heap* heap = isolate->heap();
658 HandleScope scope; 667 HandleScope scope(isolate);
659 Handle<FixedArray> elms = Factory::NewFixedArray(DESCRIPTOR_SIZE); 668 Handle<FixedArray> elms = Factory::NewFixedArray(DESCRIPTOR_SIZE);
660 Handle<JSArray> desc = Factory::NewJSArrayWithElements(elms); 669 Handle<JSArray> desc = Factory::NewJSArrayWithElements(elms);
661 LookupResult result; 670 LookupResult result;
662 CONVERT_CHECKED(JSObject, obj, args[0]); 671 CONVERT_CHECKED(JSObject, obj, args[0]);
663 CONVERT_CHECKED(String, name, args[1]); 672 CONVERT_CHECKED(String, name, args[1]);
664 673
665 // This could be an element. 674 // This could be an element.
666 uint32_t index; 675 uint32_t index;
667 if (name->AsArrayIndex(&index)) { 676 if (name->AsArrayIndex(&index)) {
668 switch (obj->HasLocalElement(index)) { 677 switch (obj->HasLocalElement(index)) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 RUNTIME_GET_ISOLATE; 781 RUNTIME_GET_ISOLATE;
773 ASSERT(args.length() == 1); 782 ASSERT(args.length() == 1);
774 CONVERT_CHECKED(JSObject, obj, args[0]); 783 CONVERT_CHECKED(JSObject, obj, args[0]);
775 return obj->map()->is_extensible() ? isolate->heap()->true_value() 784 return obj->map()->is_extensible() ? isolate->heap()->true_value()
776 : isolate->heap()->false_value(); 785 : isolate->heap()->false_value();
777 } 786 }
778 787
779 788
780 static Object* Runtime_RegExpCompile(RUNTIME_CALLING_CONVENTION) { 789 static Object* Runtime_RegExpCompile(RUNTIME_CALLING_CONVENTION) {
781 RUNTIME_GET_ISOLATE; 790 RUNTIME_GET_ISOLATE;
782 HandleScope scope; 791 HandleScope scope(isolate);
783 ASSERT(args.length() == 3); 792 ASSERT(args.length() == 3);
784 CONVERT_ARG_CHECKED(JSRegExp, re, 0); 793 CONVERT_ARG_CHECKED(JSRegExp, re, 0);
785 CONVERT_ARG_CHECKED(String, pattern, 1); 794 CONVERT_ARG_CHECKED(String, pattern, 1);
786 CONVERT_ARG_CHECKED(String, flags, 2); 795 CONVERT_ARG_CHECKED(String, flags, 2);
787 Handle<Object> result = RegExpImpl::Compile(re, pattern, flags); 796 Handle<Object> result = RegExpImpl::Compile(re, pattern, flags);
788 if (result.is_null()) return Failure::Exception(); 797 if (result.is_null()) return Failure::Exception();
789 return *result; 798 return *result;
790 } 799 }
791 800
792 801
793 static Object* Runtime_CreateApiFunction(RUNTIME_CALLING_CONVENTION) { 802 static Object* Runtime_CreateApiFunction(RUNTIME_CALLING_CONVENTION) {
794 RUNTIME_GET_ISOLATE; 803 RUNTIME_GET_ISOLATE;
795 HandleScope scope; 804 HandleScope scope(isolate);
796 ASSERT(args.length() == 1); 805 ASSERT(args.length() == 1);
797 CONVERT_ARG_CHECKED(FunctionTemplateInfo, data, 0); 806 CONVERT_ARG_CHECKED(FunctionTemplateInfo, data, 0);
798 return *Factory::CreateApiFunction(data); 807 return *Factory::CreateApiFunction(data);
799 } 808 }
800 809
801 810
802 static Object* Runtime_IsTemplate(RUNTIME_CALLING_CONVENTION) { 811 static Object* Runtime_IsTemplate(RUNTIME_CALLING_CONVENTION) {
803 RUNTIME_GET_ISOLATE; 812 RUNTIME_GET_ISOLATE;
804 ASSERT(args.length() == 1); 813 ASSERT(args.length() == 1);
805 Object* arg = args[0]; 814 Object* arg = args[0];
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 Map::cast(new_map)->set_is_access_check_needed(true); 869 Map::cast(new_map)->set_is_access_check_needed(true);
861 object->set_map(Map::cast(new_map)); 870 object->set_map(Map::cast(new_map));
862 } 871 }
863 return isolate->heap()->undefined_value(); 872 return isolate->heap()->undefined_value();
864 } 873 }
865 874
866 875
867 static Object* ThrowRedeclarationError(Isolate* isolate, 876 static Object* ThrowRedeclarationError(Isolate* isolate,
868 const char* type, 877 const char* type,
869 Handle<String> name) { 878 Handle<String> name) {
870 HandleScope scope; 879 HandleScope scope(isolate);
871 Handle<Object> type_handle = Factory::NewStringFromAscii(CStrVector(type)); 880 Handle<Object> type_handle = Factory::NewStringFromAscii(CStrVector(type));
872 Handle<Object> args[2] = { type_handle, name }; 881 Handle<Object> args[2] = { type_handle, name };
873 Handle<Object> error = 882 Handle<Object> error =
874 Factory::NewTypeError("redeclaration", HandleVector(args, 2)); 883 Factory::NewTypeError("redeclaration", HandleVector(args, 2));
875 return isolate->Throw(*error); 884 return isolate->Throw(*error);
876 } 885 }
877 886
878 887
879 static Object* Runtime_DeclareGlobals(RUNTIME_CALLING_CONVENTION) { 888 static Object* Runtime_DeclareGlobals(RUNTIME_CALLING_CONVENTION) {
880 RUNTIME_GET_ISOLATE; 889 RUNTIME_GET_ISOLATE;
881 HandleScope scope; 890 HandleScope scope(isolate);
882 Handle<GlobalObject> global = Handle<GlobalObject>( 891 Handle<GlobalObject> global = Handle<GlobalObject>(
883 isolate->context()->global()); 892 isolate->context()->global());
884 893
885 Handle<Context> context = args.at<Context>(0); 894 Handle<Context> context = args.at<Context>(0);
886 CONVERT_ARG_CHECKED(FixedArray, pairs, 1); 895 CONVERT_ARG_CHECKED(FixedArray, pairs, 1);
887 bool is_eval = Smi::cast(args[2])->value() == 1; 896 bool is_eval = Smi::cast(args[2])->value() == 1;
888 897
889 // Compute the property attributes. According to ECMA-262, section 898 // Compute the property attributes. According to ECMA-262, section
890 // 13, page 71, the property must be read-only and 899 // 13, page 71, the property must be read-only and
891 // non-deletable. However, neither SpiderMonkey nor KJS creates the 900 // non-deletable. However, neither SpiderMonkey nor KJS creates the
892 // property as read-only, so we don't either. 901 // property as read-only, so we don't either.
893 PropertyAttributes base = is_eval ? NONE : DONT_DELETE; 902 PropertyAttributes base = is_eval ? NONE : DONT_DELETE;
894 903
895 // Traverse the name/value pairs and set the properties. 904 // Traverse the name/value pairs and set the properties.
896 int length = pairs->length(); 905 int length = pairs->length();
897 for (int i = 0; i < length; i += 2) { 906 for (int i = 0; i < length; i += 2) {
898 HandleScope scope; 907 HandleScope scope(isolate);
899 Handle<String> name(String::cast(pairs->get(i))); 908 Handle<String> name(String::cast(pairs->get(i)));
900 Handle<Object> value(pairs->get(i + 1)); 909 Handle<Object> value(pairs->get(i + 1), isolate);
901 910
902 // We have to declare a global const property. To capture we only 911 // We have to declare a global const property. To capture we only
903 // assign to it when evaluating the assignment for "const x = 912 // assign to it when evaluating the assignment for "const x =
904 // <expr>" the initial value is the hole. 913 // <expr>" the initial value is the hole.
905 bool is_const_property = value->IsTheHole(); 914 bool is_const_property = value->IsTheHole();
906 915
907 if (value->IsUndefined() || is_const_property) { 916 if (value->IsUndefined() || is_const_property) {
908 // Lookup the property in the global object, and don't set the 917 // Lookup the property in the global object, and don't set the
909 // value of the variable if the property is already there. 918 // value of the variable if the property is already there.
910 LookupResult lookup; 919 LookupResult lookup;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 IgnoreAttributesAndSetLocalProperty(global, name, value, attributes); 994 IgnoreAttributesAndSetLocalProperty(global, name, value, attributes);
986 } 995 }
987 } 996 }
988 997
989 return isolate->heap()->undefined_value(); 998 return isolate->heap()->undefined_value();
990 } 999 }
991 1000
992 1001
993 static Object* Runtime_DeclareContextSlot(RUNTIME_CALLING_CONVENTION) { 1002 static Object* Runtime_DeclareContextSlot(RUNTIME_CALLING_CONVENTION) {
994 RUNTIME_GET_ISOLATE; 1003 RUNTIME_GET_ISOLATE;
995 HandleScope scope; 1004 HandleScope scope(isolate);
996 ASSERT(args.length() == 4); 1005 ASSERT(args.length() == 4);
997 1006
998 CONVERT_ARG_CHECKED(Context, context, 0); 1007 CONVERT_ARG_CHECKED(Context, context, 0);
999 Handle<String> name(String::cast(args[1])); 1008 Handle<String> name(String::cast(args[1]));
1000 PropertyAttributes mode = 1009 PropertyAttributes mode =
1001 static_cast<PropertyAttributes>(Smi::cast(args[2])->value()); 1010 static_cast<PropertyAttributes>(Smi::cast(args[2])->value());
1002 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE); 1011 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE);
1003 Handle<Object> initial_value(args[3]); 1012 Handle<Object> initial_value(args[3], isolate);
1004 1013
1005 // Declarations are always done in the function context. 1014 // Declarations are always done in the function context.
1006 context = Handle<Context>(context->fcontext()); 1015 context = Handle<Context>(context->fcontext());
1007 1016
1008 int index; 1017 int index;
1009 PropertyAttributes attributes; 1018 PropertyAttributes attributes;
1010 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; 1019 ContextLookupFlags flags = DONT_FOLLOW_CHAINS;
1011 Handle<Object> holder = 1020 Handle<Object> holder =
1012 context->Lookup(name, flags, &index, &attributes); 1021 context->Lookup(name, flags, &index, &attributes);
1013 1022
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 isolate->context_extension_function()); 1069 isolate->context_extension_function());
1061 // And store it in the extension slot. 1070 // And store it in the extension slot.
1062 context->set_extension(*context_ext); 1071 context->set_extension(*context_ext);
1063 } 1072 }
1064 ASSERT(*context_ext != NULL); 1073 ASSERT(*context_ext != NULL);
1065 1074
1066 // Declare the property by setting it to the initial value if provided, 1075 // Declare the property by setting it to the initial value if provided,
1067 // or undefined, and use the correct mode (e.g. READ_ONLY attribute for 1076 // or undefined, and use the correct mode (e.g. READ_ONLY attribute for
1068 // constant declarations). 1077 // constant declarations).
1069 ASSERT(!context_ext->HasLocalProperty(*name)); 1078 ASSERT(!context_ext->HasLocalProperty(*name));
1070 Handle<Object> value(isolate->heap()->undefined_value()); 1079 Handle<Object> value(isolate->heap()->undefined_value(), isolate);
1071 if (*initial_value != NULL) value = initial_value; 1080 if (*initial_value != NULL) value = initial_value;
1072 SetProperty(context_ext, name, value, mode); 1081 SetProperty(context_ext, name, value, mode);
1073 ASSERT(context_ext->GetLocalPropertyAttribute(*name) == mode); 1082 ASSERT(context_ext->GetLocalPropertyAttribute(*name) == mode);
1074 } 1083 }
1075 1084
1076 return isolate->heap()->undefined_value(); 1085 return isolate->heap()->undefined_value();
1077 } 1086 }
1078 1087
1079 1088
1080 static Object* Runtime_InitializeVarGlobal(RUNTIME_CALLING_CONVENTION) { 1089 static Object* Runtime_InitializeVarGlobal(RUNTIME_CALLING_CONVENTION) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 // just shadow it. 1124 // just shadow it.
1116 if (real_holder != isolate->context()->global()) break; 1125 if (real_holder != isolate->context()->global()) break;
1117 return ThrowRedeclarationError(isolate, "const", name); 1126 return ThrowRedeclarationError(isolate, "const", name);
1118 } 1127 }
1119 1128
1120 // Determine if this is a redeclaration of an intercepted read-only 1129 // Determine if this is a redeclaration of an intercepted read-only
1121 // property and figure out if the property exists at all. 1130 // property and figure out if the property exists at all.
1122 bool found = true; 1131 bool found = true;
1123 PropertyType type = lookup.type(); 1132 PropertyType type = lookup.type();
1124 if (type == INTERCEPTOR) { 1133 if (type == INTERCEPTOR) {
1125 HandleScope handle_scope; 1134 HandleScope handle_scope(isolate);
1126 Handle<JSObject> holder(real_holder); 1135 Handle<JSObject> holder(real_holder);
1127 PropertyAttributes intercepted = holder->GetPropertyAttribute(*name); 1136 PropertyAttributes intercepted = holder->GetPropertyAttribute(*name);
1128 real_holder = *holder; 1137 real_holder = *holder;
1129 if (intercepted == ABSENT) { 1138 if (intercepted == ABSENT) {
1130 // The interceptor claims the property isn't there. We need to 1139 // The interceptor claims the property isn't there. We need to
1131 // make sure to introduce it. 1140 // make sure to introduce it.
1132 found = false; 1141 found = false;
1133 } else if ((intercepted & READ_ONLY) != 0) { 1142 } else if ((intercepted & READ_ONLY) != 0) {
1134 // The property is present, but read-only. Since we're trying to 1143 // The property is present, but read-only. Since we're trying to
1135 // overwrite it with a variable declaration we must throw a 1144 // overwrite it with a variable declaration we must throw a
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 ASSERT(lookup.IsReadOnly() && type == CONSTANT_FUNCTION); 1258 ASSERT(lookup.IsReadOnly() && type == CONSTANT_FUNCTION);
1250 } 1259 }
1251 1260
1252 // Use the set value as the result of the operation. 1261 // Use the set value as the result of the operation.
1253 return *value; 1262 return *value;
1254 } 1263 }
1255 1264
1256 1265
1257 static Object* Runtime_InitializeConstContextSlot(RUNTIME_CALLING_CONVENTION) { 1266 static Object* Runtime_InitializeConstContextSlot(RUNTIME_CALLING_CONVENTION) {
1258 RUNTIME_GET_ISOLATE; 1267 RUNTIME_GET_ISOLATE;
1259 HandleScope scope; 1268 HandleScope scope(isolate);
1260 ASSERT(args.length() == 3); 1269 ASSERT(args.length() == 3);
1261 1270
1262 Handle<Object> value(args[0]); 1271 Handle<Object> value(args[0], isolate);
1263 ASSERT(!value->IsTheHole()); 1272 ASSERT(!value->IsTheHole());
1264 CONVERT_ARG_CHECKED(Context, context, 1); 1273 CONVERT_ARG_CHECKED(Context, context, 1);
1265 Handle<String> name(String::cast(args[2])); 1274 Handle<String> name(String::cast(args[2]));
1266 1275
1267 // Initializations are always done in the function context. 1276 // Initializations are always done in the function context.
1268 context = Handle<Context>(context->fcontext()); 1277 context = Handle<Context>(context->fcontext());
1269 1278
1270 int index; 1279 int index;
1271 PropertyAttributes attributes; 1280 PropertyAttributes attributes;
1272 ContextLookupFlags flags = FOLLOW_CHAINS; 1281 ContextLookupFlags flags = FOLLOW_CHAINS;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 } 1366 }
1358 } 1367 }
1359 1368
1360 return *value; 1369 return *value;
1361 } 1370 }
1362 1371
1363 1372
1364 static Object* Runtime_OptimizeObjectForAddingMultipleProperties( 1373 static Object* Runtime_OptimizeObjectForAddingMultipleProperties(
1365 RUNTIME_CALLING_CONVENTION) { 1374 RUNTIME_CALLING_CONVENTION) {
1366 RUNTIME_GET_ISOLATE; 1375 RUNTIME_GET_ISOLATE;
1367 HandleScope scope; 1376 HandleScope scope(isolate);
1368 ASSERT(args.length() == 2); 1377 ASSERT(args.length() == 2);
1369 CONVERT_ARG_CHECKED(JSObject, object, 0); 1378 CONVERT_ARG_CHECKED(JSObject, object, 0);
1370 CONVERT_SMI_CHECKED(properties, args[1]); 1379 CONVERT_SMI_CHECKED(properties, args[1]);
1371 if (object->HasFastProperties()) { 1380 if (object->HasFastProperties()) {
1372 NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties); 1381 NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties);
1373 } 1382 }
1374 return *object; 1383 return *object;
1375 } 1384 }
1376 1385
1377 1386
1378 static Object* Runtime_RegExpExec(RUNTIME_CALLING_CONVENTION) { 1387 static Object* Runtime_RegExpExec(RUNTIME_CALLING_CONVENTION) {
1379 RUNTIME_GET_ISOLATE; 1388 RUNTIME_GET_ISOLATE;
1380 HandleScope scope; 1389 HandleScope scope(isolate);
1381 ASSERT(args.length() == 4); 1390 ASSERT(args.length() == 4);
1382 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); 1391 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
1383 CONVERT_ARG_CHECKED(String, subject, 1); 1392 CONVERT_ARG_CHECKED(String, subject, 1);
1384 // Due to the way the JS calls are constructed this must be less than the 1393 // Due to the way the JS calls are constructed this must be less than the
1385 // length of a string, i.e. it is always a Smi. We check anyway for security. 1394 // length of a string, i.e. it is always a Smi. We check anyway for security.
1386 CONVERT_SMI_CHECKED(index, args[2]); 1395 CONVERT_SMI_CHECKED(index, args[2]);
1387 CONVERT_ARG_CHECKED(JSArray, last_match_info, 3); 1396 CONVERT_ARG_CHECKED(JSArray, last_match_info, 3);
1388 RUNTIME_ASSERT(last_match_info->HasFastElements()); 1397 RUNTIME_ASSERT(last_match_info->HasFastElements());
1389 RUNTIME_ASSERT(index >= 0); 1398 RUNTIME_ASSERT(index >= 0);
1390 RUNTIME_ASSERT(index <= subject->length()); 1399 RUNTIME_ASSERT(index <= subject->length());
(...skipping 17 matching lines...) Expand all
1408 Object* new_object = 1417 Object* new_object =
1409 isolate->heap()->AllocateFixedArrayWithHoles(elements_count); 1418 isolate->heap()->AllocateFixedArrayWithHoles(elements_count);
1410 if (new_object->IsFailure()) return new_object; 1419 if (new_object->IsFailure()) return new_object;
1411 FixedArray* elements = FixedArray::cast(new_object); 1420 FixedArray* elements = FixedArray::cast(new_object);
1412 new_object = isolate->heap()->AllocateRaw(JSRegExpResult::kSize, 1421 new_object = isolate->heap()->AllocateRaw(JSRegExpResult::kSize,
1413 NEW_SPACE, 1422 NEW_SPACE,
1414 OLD_POINTER_SPACE); 1423 OLD_POINTER_SPACE);
1415 if (new_object->IsFailure()) return new_object; 1424 if (new_object->IsFailure()) return new_object;
1416 { 1425 {
1417 AssertNoAllocation no_gc; 1426 AssertNoAllocation no_gc;
1418 HandleScope scope; 1427 HandleScope scope(isolate);
1419 reinterpret_cast<HeapObject*>(new_object)-> 1428 reinterpret_cast<HeapObject*>(new_object)->
1420 set_map(isolate->global_context()->regexp_result_map()); 1429 set_map(isolate->global_context()->regexp_result_map());
1421 } 1430 }
1422 JSArray* array = JSArray::cast(new_object); 1431 JSArray* array = JSArray::cast(new_object);
1423 array->set_properties(isolate->heap()->empty_fixed_array()); 1432 array->set_properties(isolate->heap()->empty_fixed_array());
1424 array->set_elements(elements); 1433 array->set_elements(elements);
1425 array->set_length(Smi::FromInt(elements_count)); 1434 array->set_length(Smi::FromInt(elements_count));
1426 // Write in-object properties after the length of the array. 1435 // Write in-object properties after the length of the array.
1427 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); 1436 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]);
1428 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); 1437 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 regexp->IgnoreAttributesAndSetLocalProperty( 1545 regexp->IgnoreAttributesAndSetLocalProperty(
1537 isolate->heap()->multiline_symbol(), multiline, final); 1546 isolate->heap()->multiline_symbol(), multiline, final);
1538 regexp->IgnoreAttributesAndSetLocalProperty( 1547 regexp->IgnoreAttributesAndSetLocalProperty(
1539 isolate->heap()->last_index_symbol(), Smi::FromInt(0), writable); 1548 isolate->heap()->last_index_symbol(), Smi::FromInt(0), writable);
1540 return regexp; 1549 return regexp;
1541 } 1550 }
1542 1551
1543 1552
1544 static Object* Runtime_FinishArrayPrototypeSetup(RUNTIME_CALLING_CONVENTION) { 1553 static Object* Runtime_FinishArrayPrototypeSetup(RUNTIME_CALLING_CONVENTION) {
1545 RUNTIME_GET_ISOLATE; 1554 RUNTIME_GET_ISOLATE;
1546 HandleScope scope; 1555 HandleScope scope(isolate);
1547 ASSERT(args.length() == 1); 1556 ASSERT(args.length() == 1);
1548 CONVERT_ARG_CHECKED(JSArray, prototype, 0); 1557 CONVERT_ARG_CHECKED(JSArray, prototype, 0);
1549 // This is necessary to enable fast checks for absence of elements 1558 // This is necessary to enable fast checks for absence of elements
1550 // on Array.prototype and below. 1559 // on Array.prototype and below.
1551 prototype->set_elements(isolate->heap()->empty_fixed_array()); 1560 prototype->set_elements(isolate->heap()->empty_fixed_array());
1552 return Smi::FromInt(0); 1561 return Smi::FromInt(0);
1553 } 1562 }
1554 1563
1555 1564
1556 static Handle<JSFunction> InstallBuiltin(Isolate* isolate, 1565 static Handle<JSFunction> InstallBuiltin(Isolate* isolate,
1557 Handle<JSObject> holder, 1566 Handle<JSObject> holder,
1558 const char* name, 1567 const char* name,
1559 Builtins::Name builtin_name) { 1568 Builtins::Name builtin_name) {
1560 Handle<String> key = Factory::LookupAsciiSymbol(name); 1569 Handle<String> key = Factory::LookupAsciiSymbol(name);
1561 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); 1570 Handle<Code> code(isolate->builtins()->builtin(builtin_name));
1562 Handle<JSFunction> optimized = Factory::NewFunction(key, 1571 Handle<JSFunction> optimized = Factory::NewFunction(key,
1563 JS_OBJECT_TYPE, 1572 JS_OBJECT_TYPE,
1564 JSObject::kHeaderSize, 1573 JSObject::kHeaderSize,
1565 code, 1574 code,
1566 false); 1575 false);
1567 optimized->shared()->DontAdaptArguments(); 1576 optimized->shared()->DontAdaptArguments();
1568 SetProperty(holder, key, optimized, NONE); 1577 SetProperty(holder, key, optimized, NONE);
1569 return optimized; 1578 return optimized;
1570 } 1579 }
1571 1580
1572 1581
1573 static Object* Runtime_SpecialArrayFunctions(RUNTIME_CALLING_CONVENTION) { 1582 static Object* Runtime_SpecialArrayFunctions(RUNTIME_CALLING_CONVENTION) {
1574 RUNTIME_GET_ISOLATE; 1583 RUNTIME_GET_ISOLATE;
1575 HandleScope scope; 1584 HandleScope scope(isolate);
1576 ASSERT(args.length() == 1); 1585 ASSERT(args.length() == 1);
1577 CONVERT_ARG_CHECKED(JSObject, holder, 0); 1586 CONVERT_ARG_CHECKED(JSObject, holder, 0);
1578 1587
1579 InstallBuiltin(isolate, holder, "pop", Builtins::ArrayPop); 1588 InstallBuiltin(isolate, holder, "pop", Builtins::ArrayPop);
1580 InstallBuiltin(isolate, holder, "push", Builtins::ArrayPush); 1589 InstallBuiltin(isolate, holder, "push", Builtins::ArrayPush);
1581 InstallBuiltin(isolate, holder, "shift", Builtins::ArrayShift); 1590 InstallBuiltin(isolate, holder, "shift", Builtins::ArrayShift);
1582 InstallBuiltin(isolate, holder, "unshift", Builtins::ArrayUnshift); 1591 InstallBuiltin(isolate, holder, "unshift", Builtins::ArrayUnshift);
1583 InstallBuiltin(isolate, holder, "slice", Builtins::ArraySlice); 1592 InstallBuiltin(isolate, holder, "slice", Builtins::ArraySlice);
1584 InstallBuiltin(isolate, holder, "splice", Builtins::ArraySplice); 1593 InstallBuiltin(isolate, holder, "splice", Builtins::ArraySplice);
1585 InstallBuiltin(isolate, holder, "concat", Builtins::ArrayConcat); 1594 InstallBuiltin(isolate, holder, "concat", Builtins::ArrayConcat);
1586 1595
1587 return *holder; 1596 return *holder;
1588 } 1597 }
1589 1598
1590 1599
1591 static Object* Runtime_GetGlobalReceiver(RUNTIME_CALLING_CONVENTION) { 1600 static Object* Runtime_GetGlobalReceiver(RUNTIME_CALLING_CONVENTION) {
1592 RUNTIME_GET_ISOLATE; 1601 RUNTIME_GET_ISOLATE;
1593 // Returns a real global receiver, not one of builtins object. 1602 // Returns a real global receiver, not one of builtins object.
1594 Context* global_context = 1603 Context* global_context =
1595 isolate->context()->global()->global_context(); 1604 isolate->context()->global()->global_context();
1596 return global_context->global()->global_receiver(); 1605 return global_context->global()->global_receiver();
1597 } 1606 }
1598 1607
1599 1608
1600 static Object* Runtime_MaterializeRegExpLiteral(RUNTIME_CALLING_CONVENTION) { 1609 static Object* Runtime_MaterializeRegExpLiteral(RUNTIME_CALLING_CONVENTION) {
1601 RUNTIME_GET_ISOLATE; 1610 RUNTIME_GET_ISOLATE;
1602 HandleScope scope; 1611 HandleScope scope(isolate);
1603 ASSERT(args.length() == 4); 1612 ASSERT(args.length() == 4);
1604 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 1613 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
1605 int index = Smi::cast(args[1])->value(); 1614 int index = Smi::cast(args[1])->value();
1606 Handle<String> pattern = args.at<String>(2); 1615 Handle<String> pattern = args.at<String>(2);
1607 Handle<String> flags = args.at<String>(3); 1616 Handle<String> flags = args.at<String>(3);
1608 1617
1609 // Get the RegExp function from the context in the literals array. 1618 // Get the RegExp function from the context in the literals array.
1610 // This is the RegExp function from the context in which the 1619 // This is the RegExp function from the context in which the
1611 // function was created. We do not use the RegExp function from the 1620 // function was created. We do not use the RegExp function from the
1612 // current global context because this might be the RegExp function 1621 // current global context because this might be the RegExp function
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 CONVERT_CHECKED(JSFunction, f, args[0]); 1667 CONVERT_CHECKED(JSFunction, f, args[0]);
1659 Object* obj = f->RemovePrototype(); 1668 Object* obj = f->RemovePrototype();
1660 if (obj->IsFailure()) return obj; 1669 if (obj->IsFailure()) return obj;
1661 1670
1662 return isolate->heap()->undefined_value(); 1671 return isolate->heap()->undefined_value();
1663 } 1672 }
1664 1673
1665 1674
1666 static Object* Runtime_FunctionGetScript(RUNTIME_CALLING_CONVENTION) { 1675 static Object* Runtime_FunctionGetScript(RUNTIME_CALLING_CONVENTION) {
1667 RUNTIME_GET_ISOLATE; 1676 RUNTIME_GET_ISOLATE;
1668 HandleScope scope; 1677 HandleScope scope(isolate);
1669 ASSERT(args.length() == 1); 1678 ASSERT(args.length() == 1);
1670 1679
1671 CONVERT_CHECKED(JSFunction, fun, args[0]); 1680 CONVERT_CHECKED(JSFunction, fun, args[0]);
1672 Handle<Object> script = Handle<Object>(fun->shared()->script()); 1681 Handle<Object> script = Handle<Object>(fun->shared()->script(), isolate);
1673 if (!script->IsScript()) return isolate->heap()->undefined_value(); 1682 if (!script->IsScript()) return isolate->heap()->undefined_value();
1674 1683
1675 return *GetScriptWrapper(Handle<Script>::cast(script)); 1684 return *GetScriptWrapper(Handle<Script>::cast(script));
1676 } 1685 }
1677 1686
1678 1687
1679 static Object* Runtime_FunctionGetSourceCode(RUNTIME_CALLING_CONVENTION) { 1688 static Object* Runtime_FunctionGetSourceCode(RUNTIME_CALLING_CONVENTION) {
1680 RUNTIME_GET_ISOLATE; 1689 RUNTIME_GET_ISOLATE;
1681 NoHandleAllocation ha; 1690 NoHandleAllocation ha;
1682 ASSERT(args.length() == 1); 1691 ASSERT(args.length() == 1);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 ASSERT(args.length() == 1); 1778 ASSERT(args.length() == 1);
1770 1779
1771 CONVERT_CHECKED(JSFunction, f, args[0]); 1780 CONVERT_CHECKED(JSFunction, f, args[0]);
1772 return f->IsBuiltin() ? isolate->heap()->true_value() : 1781 return f->IsBuiltin() ? isolate->heap()->true_value() :
1773 isolate->heap()->false_value(); 1782 isolate->heap()->false_value();
1774 } 1783 }
1775 1784
1776 1785
1777 static Object* Runtime_SetCode(RUNTIME_CALLING_CONVENTION) { 1786 static Object* Runtime_SetCode(RUNTIME_CALLING_CONVENTION) {
1778 RUNTIME_GET_ISOLATE; 1787 RUNTIME_GET_ISOLATE;
1779 HandleScope scope; 1788 HandleScope scope(isolate);
1780 ASSERT(args.length() == 2); 1789 ASSERT(args.length() == 2);
1781 1790
1782 CONVERT_ARG_CHECKED(JSFunction, target, 0); 1791 CONVERT_ARG_CHECKED(JSFunction, target, 0);
1783 Handle<Object> code = args.at<Object>(1); 1792 Handle<Object> code = args.at<Object>(1);
1784 1793
1785 Handle<Context> context(target->context()); 1794 Handle<Context> context(target->context());
1786 1795
1787 if (!code->IsNull()) { 1796 if (!code->IsNull()) {
1788 RUNTIME_ASSERT(code->IsJSFunction()); 1797 RUNTIME_ASSERT(code->IsJSFunction());
1789 Handle<JSFunction> fun = Handle<JSFunction>::cast(code); 1798 Handle<JSFunction> fun = Handle<JSFunction>::cast(code);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 } 1837 }
1829 1838
1830 target->set_context(*context); 1839 target->set_context(*context);
1831 return *target; 1840 return *target;
1832 } 1841 }
1833 1842
1834 1843
1835 static Object* Runtime_SetExpectedNumberOfProperties( 1844 static Object* Runtime_SetExpectedNumberOfProperties(
1836 RUNTIME_CALLING_CONVENTION) { 1845 RUNTIME_CALLING_CONVENTION) {
1837 RUNTIME_GET_ISOLATE; 1846 RUNTIME_GET_ISOLATE;
1838 HandleScope scope; 1847 HandleScope scope(isolate);
1839 ASSERT(args.length() == 2); 1848 ASSERT(args.length() == 2);
1840 CONVERT_ARG_CHECKED(JSFunction, function, 0); 1849 CONVERT_ARG_CHECKED(JSFunction, function, 0);
1841 CONVERT_SMI_CHECKED(num, args[1]); 1850 CONVERT_SMI_CHECKED(num, args[1]);
1842 RUNTIME_ASSERT(num >= 0); 1851 RUNTIME_ASSERT(num >= 0);
1843 SetExpectedNofProperties(function, num); 1852 SetExpectedNofProperties(function, num);
1844 return isolate->heap()->undefined_value(); 1853 return isolate->heap()->undefined_value();
1845 } 1854 }
1846 1855
1847 1856
1848 static Object* CharFromCode(Heap* heap, Object* char_code) { 1857 static Object* CharFromCode(Isolate* isolate, Object* char_code) {
1849 uint32_t code; 1858 uint32_t code;
1850 if (char_code->ToArrayIndex(&code)) { 1859 if (char_code->ToArrayIndex(&code)) {
1851 if (code <= 0xffff) { 1860 if (code <= 0xffff) {
1852 return heap->LookupSingleCharacterStringFromCode(code); 1861 return isolate->heap()->LookupSingleCharacterStringFromCode(code);
1853 } 1862 }
1854 } 1863 }
1855 return heap->empty_string(); 1864 return isolate->heap()->empty_string();
1856 } 1865 }
1857 1866
1858 1867
1859 static Object* Runtime_StringCharCodeAt(RUNTIME_CALLING_CONVENTION) { 1868 static Object* Runtime_StringCharCodeAt(RUNTIME_CALLING_CONVENTION) {
1860 RUNTIME_GET_ISOLATE; 1869 RUNTIME_GET_ISOLATE;
1861 NoHandleAllocation ha; 1870 NoHandleAllocation ha;
1862 ASSERT(args.length() == 2); 1871 ASSERT(args.length() == 2);
1863 1872
1864 CONVERT_CHECKED(String, subject, args[0]); 1873 CONVERT_CHECKED(String, subject, args[0]);
1865 Object* index = args[1]; 1874 Object* index = args[1];
(...skipping 22 matching lines...) Expand all
1888 } 1897 }
1889 1898
1890 return Smi::FromInt(subject->Get(i)); 1899 return Smi::FromInt(subject->Get(i));
1891 } 1900 }
1892 1901
1893 1902
1894 static Object* Runtime_CharFromCode(RUNTIME_CALLING_CONVENTION) { 1903 static Object* Runtime_CharFromCode(RUNTIME_CALLING_CONVENTION) {
1895 RUNTIME_GET_ISOLATE; 1904 RUNTIME_GET_ISOLATE;
1896 NoHandleAllocation ha; 1905 NoHandleAllocation ha;
1897 ASSERT(args.length() == 1); 1906 ASSERT(args.length() == 1);
1898 return CharFromCode(isolate->heap(), args[0]); 1907 return CharFromCode(isolate, args[0]);
1899 } 1908 }
1900 1909
1901 1910
1902 class FixedArrayBuilder { 1911 class FixedArrayBuilder {
1903 public: 1912 public:
1904 explicit FixedArrayBuilder(int initial_capacity) 1913 explicit FixedArrayBuilder(int initial_capacity)
1905 : array_(Factory::NewFixedArrayWithHoles(initial_capacity)), 1914 : array_(Factory::NewFixedArrayWithHoles(initial_capacity)),
1906 length_(0) { 1915 length_(0) {
1907 // Require a non-zero initial size. Ensures that doubling the size to 1916 // Require a non-zero initial size. Ensures that doubling the size to
1908 // extend the array will work. 1917 // extend the array will work.
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 builder->AddString(replacement_substrings_[part.data]); 2387 builder->AddString(replacement_substrings_[part.data]);
2379 break; 2388 break;
2380 default: 2389 default:
2381 UNREACHABLE(); 2390 UNREACHABLE();
2382 } 2391 }
2383 } 2392 }
2384 } 2393 }
2385 2394
2386 2395
2387 2396
2388 static Object* StringReplaceRegExpWithString(Heap* heap, 2397 static Object* StringReplaceRegExpWithString(Isolate* isolate,
2389 String* subject, 2398 String* subject,
2390 JSRegExp* regexp, 2399 JSRegExp* regexp,
2391 String* replacement, 2400 String* replacement,
2392 JSArray* last_match_info) { 2401 JSArray* last_match_info) {
2393 ASSERT(subject->IsFlat()); 2402 ASSERT(subject->IsFlat());
2394 ASSERT(replacement->IsFlat()); 2403 ASSERT(replacement->IsFlat());
2395 2404
2396 HandleScope handles; 2405 HandleScope handles(isolate);
2397 2406
2398 int length = subject->length(); 2407 int length = subject->length();
2399 Handle<String> subject_handle(subject); 2408 Handle<String> subject_handle(subject);
2400 Handle<JSRegExp> regexp_handle(regexp); 2409 Handle<JSRegExp> regexp_handle(regexp);
2401 Handle<String> replacement_handle(replacement); 2410 Handle<String> replacement_handle(replacement);
2402 Handle<JSArray> last_match_info_handle(last_match_info); 2411 Handle<JSArray> last_match_info_handle(last_match_info);
2403 Handle<Object> match = RegExpImpl::Exec(regexp_handle, 2412 Handle<Object> match = RegExpImpl::Exec(regexp_handle,
2404 subject_handle, 2413 subject_handle,
2405 0, 2414 0,
2406 last_match_info_handle); 2415 last_match_info_handle);
(...skipping 13 matching lines...) Expand all
2420 capture_count, 2429 capture_count,
2421 length); 2430 length);
2422 2431
2423 bool is_global = regexp_handle->GetFlags().is_global(); 2432 bool is_global = regexp_handle->GetFlags().is_global();
2424 2433
2425 // Guessing the number of parts that the final result string is built 2434 // Guessing the number of parts that the final result string is built
2426 // from. Global regexps can match any number of times, so we guess 2435 // from. Global regexps can match any number of times, so we guess
2427 // conservatively. 2436 // conservatively.
2428 int expected_parts = 2437 int expected_parts =
2429 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; 2438 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1;
2430 ReplacementStringBuilder builder(heap, subject_handle, expected_parts); 2439 ReplacementStringBuilder builder(isolate->heap(),
2440 subject_handle,
2441 expected_parts);
2431 2442
2432 // Index of end of last match. 2443 // Index of end of last match.
2433 int prev = 0; 2444 int prev = 0;
2434 2445
2435 // Number of parts added by compiled replacement plus preceeding 2446 // Number of parts added by compiled replacement plus preceeding
2436 // string and possibly suffix after last match. It is possible for 2447 // string and possibly suffix after last match. It is possible for
2437 // all components to use two elements when encoded as two smis. 2448 // all components to use two elements when encoded as two smis.
2438 const int parts_added_per_loop = 2 * (compiled_replacement.parts() + 2); 2449 const int parts_added_per_loop = 2 * (compiled_replacement.parts() + 2);
2439 bool matched = true; 2450 bool matched = true;
2440 do { 2451 do {
2441 ASSERT(last_match_info_handle->HasFastElements()); 2452 ASSERT(last_match_info_handle->HasFastElements());
2442 // Increase the capacity of the builder before entering local handle-scope, 2453 // Increase the capacity of the builder before entering local handle-scope,
2443 // so its internal buffer can safely allocate a new handle if it grows. 2454 // so its internal buffer can safely allocate a new handle if it grows.
2444 builder.EnsureCapacity(parts_added_per_loop); 2455 builder.EnsureCapacity(parts_added_per_loop);
2445 2456
2446 HandleScope loop_scope; 2457 HandleScope loop_scope(isolate);
2447 int start, end; 2458 int start, end;
2448 { 2459 {
2449 AssertNoAllocation match_info_array_is_not_in_a_handle; 2460 AssertNoAllocation match_info_array_is_not_in_a_handle;
2450 FixedArray* match_info_array = 2461 FixedArray* match_info_array =
2451 FixedArray::cast(last_match_info_handle->elements()); 2462 FixedArray::cast(last_match_info_handle->elements());
2452 2463
2453 ASSERT_EQ(capture_count * 2 + 2, 2464 ASSERT_EQ(capture_count * 2 + 2,
2454 RegExpImpl::GetLastCaptureCount(match_info_array)); 2465 RegExpImpl::GetLastCaptureCount(match_info_array));
2455 start = RegExpImpl::GetCapture(match_info_array, 0); 2466 start = RegExpImpl::GetCapture(match_info_array, 0);
2456 end = RegExpImpl::GetCapture(match_info_array, 1); 2467 end = RegExpImpl::GetCapture(match_info_array, 1);
(...skipping 30 matching lines...) Expand all
2487 2498
2488 if (prev < length) { 2499 if (prev < length) {
2489 builder.AddSubjectSlice(prev, length); 2500 builder.AddSubjectSlice(prev, length);
2490 } 2501 }
2491 2502
2492 return *(builder.ToString()); 2503 return *(builder.ToString());
2493 } 2504 }
2494 2505
2495 2506
2496 template <typename ResultSeqString> 2507 template <typename ResultSeqString>
2497 static Object* StringReplaceRegExpWithEmptyString(Heap* heap, 2508 static Object* StringReplaceRegExpWithEmptyString(Isolate* isolate,
2498 String* subject, 2509 String* subject,
2499 JSRegExp* regexp, 2510 JSRegExp* regexp,
2500 JSArray* last_match_info) { 2511 JSArray* last_match_info) {
2501 ASSERT(subject->IsFlat()); 2512 ASSERT(subject->IsFlat());
2502 2513
2503 HandleScope handles; 2514 HandleScope handles(isolate);
2504 2515
2505 Handle<String> subject_handle(subject); 2516 Handle<String> subject_handle(subject);
2506 Handle<JSRegExp> regexp_handle(regexp); 2517 Handle<JSRegExp> regexp_handle(regexp);
2507 Handle<JSArray> last_match_info_handle(last_match_info); 2518 Handle<JSArray> last_match_info_handle(last_match_info);
2508 Handle<Object> match = RegExpImpl::Exec(regexp_handle, 2519 Handle<Object> match = RegExpImpl::Exec(regexp_handle,
2509 subject_handle, 2520 subject_handle,
2510 0, 2521 0,
2511 last_match_info_handle); 2522 last_match_info_handle);
2512 if (match.is_null()) return Failure::Exception(); 2523 if (match.is_null()) return Failure::Exception();
2513 if (match->IsNull()) return *subject_handle; 2524 if (match->IsNull()) return *subject_handle;
2514 2525
2515 ASSERT(last_match_info_handle->HasFastElements()); 2526 ASSERT(last_match_info_handle->HasFastElements());
2516 2527
2517 HandleScope loop_scope;
2518 int start, end; 2528 int start, end;
2519 { 2529 {
2520 AssertNoAllocation match_info_array_is_not_in_a_handle; 2530 AssertNoAllocation match_info_array_is_not_in_a_handle;
2521 FixedArray* match_info_array = 2531 FixedArray* match_info_array =
2522 FixedArray::cast(last_match_info_handle->elements()); 2532 FixedArray::cast(last_match_info_handle->elements());
2523 2533
2524 start = RegExpImpl::GetCapture(match_info_array, 0); 2534 start = RegExpImpl::GetCapture(match_info_array, 0);
2525 end = RegExpImpl::GetCapture(match_info_array, 1); 2535 end = RegExpImpl::GetCapture(match_info_array, 1);
2526 } 2536 }
2527 2537
2528 int length = subject->length(); 2538 int length = subject->length();
2529 int new_length = length - (end - start); 2539 int new_length = length - (end - start);
2530 if (new_length == 0) { 2540 if (new_length == 0) {
2531 return heap->empty_string(); 2541 return isolate->heap()->empty_string();
2532 } 2542 }
2533 Handle<ResultSeqString> answer; 2543 Handle<ResultSeqString> answer;
2534 if (ResultSeqString::kHasAsciiEncoding) { 2544 if (ResultSeqString::kHasAsciiEncoding) {
2535 answer = 2545 answer =
2536 Handle<ResultSeqString>::cast(Factory::NewRawAsciiString(new_length)); 2546 Handle<ResultSeqString>::cast(Factory::NewRawAsciiString(new_length));
2537 } else { 2547 } else {
2538 answer = 2548 answer =
2539 Handle<ResultSeqString>::cast(Factory::NewRawTwoByteString(new_length)); 2549 Handle<ResultSeqString>::cast(Factory::NewRawTwoByteString(new_length));
2540 } 2550 }
2541 2551
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 if (next > length) break; 2587 if (next > length) break;
2578 } 2588 }
2579 match = RegExpImpl::Exec(regexp_handle, 2589 match = RegExpImpl::Exec(regexp_handle,
2580 subject_handle, 2590 subject_handle,
2581 next, 2591 next,
2582 last_match_info_handle); 2592 last_match_info_handle);
2583 if (match.is_null()) return Failure::Exception(); 2593 if (match.is_null()) return Failure::Exception();
2584 if (match->IsNull()) break; 2594 if (match->IsNull()) break;
2585 2595
2586 ASSERT(last_match_info_handle->HasFastElements()); 2596 ASSERT(last_match_info_handle->HasFastElements());
2587 HandleScope loop_scope; 2597 HandleScope loop_scope(isolate);
2588 { 2598 {
2589 AssertNoAllocation match_info_array_is_not_in_a_handle; 2599 AssertNoAllocation match_info_array_is_not_in_a_handle;
2590 FixedArray* match_info_array = 2600 FixedArray* match_info_array =
2591 FixedArray::cast(last_match_info_handle->elements()); 2601 FixedArray::cast(last_match_info_handle->elements());
2592 start = RegExpImpl::GetCapture(match_info_array, 0); 2602 start = RegExpImpl::GetCapture(match_info_array, 0);
2593 end = RegExpImpl::GetCapture(match_info_array, 1); 2603 end = RegExpImpl::GetCapture(match_info_array, 1);
2594 } 2604 }
2595 } while (true); 2605 } while (true);
2596 2606
2597 if (prev < length) { 2607 if (prev < length) {
2598 // Add substring subject[prev;length] to answer string. 2608 // Add substring subject[prev;length] to answer string.
2599 String::WriteToFlat(*subject_handle, 2609 String::WriteToFlat(*subject_handle,
2600 answer->GetChars() + position, 2610 answer->GetChars() + position,
2601 prev, 2611 prev,
2602 length); 2612 length);
2603 position += length - prev; 2613 position += length - prev;
2604 } 2614 }
2605 2615
2606 if (position == 0) { 2616 if (position == 0) {
2607 return heap->empty_string(); 2617 return isolate->heap()->empty_string();
2608 } 2618 }
2609 2619
2610 // Shorten string and fill 2620 // Shorten string and fill
2611 int string_size = ResultSeqString::SizeFor(position); 2621 int string_size = ResultSeqString::SizeFor(position);
2612 int allocated_string_size = ResultSeqString::SizeFor(new_length); 2622 int allocated_string_size = ResultSeqString::SizeFor(new_length);
2613 int delta = allocated_string_size - string_size; 2623 int delta = allocated_string_size - string_size;
2614 2624
2615 answer->set_length(position); 2625 answer->set_length(position);
2616 if (delta == 0) return *answer; 2626 if (delta == 0) return *answer;
2617 2627
2618 Address end_of_string = answer->address() + string_size; 2628 Address end_of_string = answer->address() + string_size;
2619 heap->CreateFillerObjectAt(end_of_string, delta); 2629 isolate->heap()->CreateFillerObjectAt(end_of_string, delta);
2620 2630
2621 return *answer; 2631 return *answer;
2622 } 2632 }
2623 2633
2624 2634
2625 static Object* Runtime_StringReplaceRegExpWithString( 2635 static Object* Runtime_StringReplaceRegExpWithString(
2626 RUNTIME_CALLING_CONVENTION) { 2636 RUNTIME_CALLING_CONVENTION) {
2627 RUNTIME_GET_ISOLATE; 2637 RUNTIME_GET_ISOLATE;
2628 ASSERT(args.length() == 4); 2638 ASSERT(args.length() == 4);
2629 2639
(...skipping 16 matching lines...) Expand all
2646 } 2656 }
2647 2657
2648 CONVERT_CHECKED(JSRegExp, regexp, args[1]); 2658 CONVERT_CHECKED(JSRegExp, regexp, args[1]);
2649 CONVERT_CHECKED(JSArray, last_match_info, args[3]); 2659 CONVERT_CHECKED(JSArray, last_match_info, args[3]);
2650 2660
2651 ASSERT(last_match_info->HasFastElements()); 2661 ASSERT(last_match_info->HasFastElements());
2652 2662
2653 if (replacement->length() == 0) { 2663 if (replacement->length() == 0) {
2654 if (subject->HasOnlyAsciiChars()) { 2664 if (subject->HasOnlyAsciiChars()) {
2655 return StringReplaceRegExpWithEmptyString<SeqAsciiString>( 2665 return StringReplaceRegExpWithEmptyString<SeqAsciiString>(
2656 isolate->heap(), subject, regexp, last_match_info); 2666 isolate, subject, regexp, last_match_info);
2657 } else { 2667 } else {
2658 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( 2668 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>(
2659 isolate->heap(), subject, regexp, last_match_info); 2669 isolate, subject, regexp, last_match_info);
2660 } 2670 }
2661 } 2671 }
2662 2672
2663 return StringReplaceRegExpWithString(isolate->heap(), 2673 return StringReplaceRegExpWithString(isolate,
2664 subject, 2674 subject,
2665 regexp, 2675 regexp,
2666 replacement, 2676 replacement,
2667 last_match_info); 2677 last_match_info);
2668 } 2678 }
2669 2679
2670 2680
2671 // Perform string match of pattern on subject, starting at start index. 2681 // Perform string match of pattern on subject, starting at start index.
2672 // Caller must ensure that 0 <= start_index <= sub->length(), 2682 // Caller must ensure that 0 <= start_index <= sub->length(),
2673 // and should check that pat->length() + start_index <= sub->length() 2683 // and should check that pat->length() + start_index <= sub->length()
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 } 2727 }
2718 return StringSearch(runtime_state, 2728 return StringSearch(runtime_state,
2719 seq_sub->ToUC16Vector(), 2729 seq_sub->ToUC16Vector(),
2720 pat_vector, 2730 pat_vector,
2721 start_index); 2731 start_index);
2722 } 2732 }
2723 2733
2724 2734
2725 static Object* Runtime_StringIndexOf(RUNTIME_CALLING_CONVENTION) { 2735 static Object* Runtime_StringIndexOf(RUNTIME_CALLING_CONVENTION) {
2726 RUNTIME_GET_ISOLATE; 2736 RUNTIME_GET_ISOLATE;
2727 HandleScope scope; // create a new handle scope 2737 HandleScope scope(isolate); // create a new handle scope
2728 ASSERT(args.length() == 3); 2738 ASSERT(args.length() == 3);
2729 2739
2730 CONVERT_ARG_CHECKED(String, sub, 0); 2740 CONVERT_ARG_CHECKED(String, sub, 0);
2731 CONVERT_ARG_CHECKED(String, pat, 1); 2741 CONVERT_ARG_CHECKED(String, pat, 1);
2732 2742
2733 Object* index = args[2]; 2743 Object* index = args[2];
2734 uint32_t start_index; 2744 uint32_t start_index;
2735 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1); 2745 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);
2736 2746
2737 RUNTIME_ASSERT(start_index <= static_cast<uint32_t>(sub->length())); 2747 RUNTIME_ASSERT(start_index <= static_cast<uint32_t>(sub->length()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 } 2780 }
2771 if (j == pattern_length) { 2781 if (j == pattern_length) {
2772 return i; 2782 return i;
2773 } 2783 }
2774 } 2784 }
2775 return -1; 2785 return -1;
2776 } 2786 }
2777 2787
2778 static Object* Runtime_StringLastIndexOf(RUNTIME_CALLING_CONVENTION) { 2788 static Object* Runtime_StringLastIndexOf(RUNTIME_CALLING_CONVENTION) {
2779 RUNTIME_GET_ISOLATE; 2789 RUNTIME_GET_ISOLATE;
2780 HandleScope scope; // create a new handle scope 2790 HandleScope scope(isolate); // create a new handle scope
2781 ASSERT(args.length() == 3); 2791 ASSERT(args.length() == 3);
2782 2792
2783 CONVERT_ARG_CHECKED(String, sub, 0); 2793 CONVERT_ARG_CHECKED(String, sub, 0);
2784 CONVERT_ARG_CHECKED(String, pat, 1); 2794 CONVERT_ARG_CHECKED(String, pat, 1);
2785 2795
2786 Object* index = args[2]; 2796 Object* index = args[2];
2787 uint32_t start_index; 2797 uint32_t start_index;
2788 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1); 2798 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);
2789 2799
2790 uint32_t pat_length = pat->length(); 2800 uint32_t pat_length = pat->length();
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
3111 last_match_info, 3121 last_match_info,
3112 match_pos, 3122 match_pos,
3113 match_pos + pattern->length()); 3123 match_pos + pattern->length());
3114 return true; 3124 return true;
3115 } 3125 }
3116 return false; // No matches at all. 3126 return false; // No matches at all.
3117 } 3127 }
3118 3128
3119 3129
3120 static RegExpImpl::IrregexpResult SearchRegExpNoCaptureMultiple( 3130 static RegExpImpl::IrregexpResult SearchRegExpNoCaptureMultiple(
3131 Isolate* isolate,
3121 Handle<String> subject, 3132 Handle<String> subject,
3122 Handle<JSRegExp> regexp, 3133 Handle<JSRegExp> regexp,
3123 Handle<JSArray> last_match_array, 3134 Handle<JSArray> last_match_array,
3124 FixedArrayBuilder* builder) { 3135 FixedArrayBuilder* builder) {
3125 ASSERT(subject->IsFlat()); 3136 ASSERT(subject->IsFlat());
3126 int match_start = -1; 3137 int match_start = -1;
3127 int match_end = 0; 3138 int match_end = 0;
3128 int pos = 0; 3139 int pos = 0;
3129 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); 3140 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject);
3130 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; 3141 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION;
(...skipping 10 matching lines...) Expand all
3141 register_vector); 3152 register_vector);
3142 if (result == RegExpImpl::RE_SUCCESS) { 3153 if (result == RegExpImpl::RE_SUCCESS) {
3143 match_start = register_vector[0]; 3154 match_start = register_vector[0];
3144 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); 3155 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch);
3145 if (match_end < match_start) { 3156 if (match_end < match_start) {
3146 ReplacementStringBuilder::AddSubjectSlice(builder, 3157 ReplacementStringBuilder::AddSubjectSlice(builder,
3147 match_end, 3158 match_end,
3148 match_start); 3159 match_start);
3149 } 3160 }
3150 match_end = register_vector[1]; 3161 match_end = register_vector[1];
3151 HandleScope loop_scope; 3162 HandleScope loop_scope(isolate);
3152 builder->Add(*Factory::NewSubString(subject, match_start, match_end)); 3163 builder->Add(*Factory::NewSubString(subject, match_start, match_end));
3153 if (match_start != match_end) { 3164 if (match_start != match_end) {
3154 pos = match_end; 3165 pos = match_end;
3155 } else { 3166 } else {
3156 pos = match_end + 1; 3167 pos = match_end + 1;
3157 if (pos > subject_length) break; 3168 if (pos > subject_length) break;
3158 } 3169 }
3159 } else if (result == RegExpImpl::RE_FAILURE) { 3170 } else if (result == RegExpImpl::RE_FAILURE) {
3160 break; 3171 break;
3161 } else { 3172 } else {
(...skipping 13 matching lines...) Expand all
3175 match_start, 3186 match_start,
3176 match_end); 3187 match_end);
3177 return RegExpImpl::RE_SUCCESS; 3188 return RegExpImpl::RE_SUCCESS;
3178 } else { 3189 } else {
3179 return RegExpImpl::RE_FAILURE; // No matches at all. 3190 return RegExpImpl::RE_FAILURE; // No matches at all.
3180 } 3191 }
3181 } 3192 }
3182 3193
3183 3194
3184 static RegExpImpl::IrregexpResult SearchRegExpMultiple( 3195 static RegExpImpl::IrregexpResult SearchRegExpMultiple(
3185 Heap* heap, 3196 Isolate* isolate,
3186 Handle<String> subject, 3197 Handle<String> subject,
3187 Handle<JSRegExp> regexp, 3198 Handle<JSRegExp> regexp,
3188 Handle<JSArray> last_match_array, 3199 Handle<JSArray> last_match_array,
3189 FixedArrayBuilder* builder) { 3200 FixedArrayBuilder* builder) {
3190 3201
3191 ASSERT(subject->IsFlat()); 3202 ASSERT(subject->IsFlat());
3192 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); 3203 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject);
3193 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; 3204 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION;
3194 3205
3195 OffsetsVector registers(required_registers); 3206 OffsetsVector registers(required_registers);
(...skipping 23 matching lines...) Expand all
3219 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); 3230 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch);
3220 if (match_end < match_start) { 3231 if (match_end < match_start) {
3221 ReplacementStringBuilder::AddSubjectSlice(builder, 3232 ReplacementStringBuilder::AddSubjectSlice(builder,
3222 match_end, 3233 match_end,
3223 match_start); 3234 match_start);
3224 } 3235 }
3225 match_end = register_vector[1]; 3236 match_end = register_vector[1];
3226 3237
3227 { 3238 {
3228 // Avoid accumulating new handles inside loop. 3239 // Avoid accumulating new handles inside loop.
3229 HandleScope temp_scope; 3240 HandleScope temp_scope(isolate);
3230 // Arguments array to replace function is match, captures, index and 3241 // Arguments array to replace function is match, captures, index and
3231 // subject, i.e., 3 + capture count in total. 3242 // subject, i.e., 3 + capture count in total.
3232 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count); 3243 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count);
3233 Handle<String> match = Factory::NewSubString(subject, 3244 Handle<String> match = Factory::NewSubString(subject,
3234 match_start, 3245 match_start,
3235 match_end); 3246 match_end);
3236 elements->set(0, *match); 3247 elements->set(0, *match);
3237 for (int i = 1; i <= capture_count; i++) { 3248 for (int i = 1; i <= capture_count; i++) {
3238 int start = register_vector[i * 2]; 3249 int start = register_vector[i * 2];
3239 if (start >= 0) { 3250 if (start >= 0) {
3240 int end = register_vector[i * 2 + 1]; 3251 int end = register_vector[i * 2 + 1];
3241 ASSERT(start <= end); 3252 ASSERT(start <= end);
3242 Handle<String> substring = Factory::NewSubString(subject, 3253 Handle<String> substring = Factory::NewSubString(subject,
3243 start, 3254 start,
3244 end); 3255 end);
3245 elements->set(i, *substring); 3256 elements->set(i, *substring);
3246 } else { 3257 } else {
3247 ASSERT(register_vector[i * 2 + 1] < 0); 3258 ASSERT(register_vector[i * 2 + 1] < 0);
3248 elements->set(i, heap->undefined_value()); 3259 elements->set(i, isolate->heap()->undefined_value());
3249 } 3260 }
3250 } 3261 }
3251 elements->set(capture_count + 1, Smi::FromInt(match_start)); 3262 elements->set(capture_count + 1, Smi::FromInt(match_start));
3252 elements->set(capture_count + 2, *subject); 3263 elements->set(capture_count + 2, *subject);
3253 builder->Add(*Factory::NewJSArrayWithElements(elements)); 3264 builder->Add(*Factory::NewJSArrayWithElements(elements));
3254 } 3265 }
3255 // Swap register vectors, so the last successful match is in 3266 // Swap register vectors, so the last successful match is in
3256 // prev_register_vector. 3267 // prev_register_vector.
3257 Vector<int32_t> tmp = prev_register_vector; 3268 Vector<int32_t> tmp = prev_register_vector;
3258 prev_register_vector = register_vector; 3269 prev_register_vector = register_vector;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 last_match_info, &builder)) { 3342 last_match_info, &builder)) {
3332 return *builder.ToJSArray(result_array); 3343 return *builder.ToJSArray(result_array);
3333 } 3344 }
3334 return isolate->heap()->null_value(); 3345 return isolate->heap()->null_value();
3335 } 3346 }
3336 3347
3337 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); 3348 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP);
3338 3349
3339 RegExpImpl::IrregexpResult result; 3350 RegExpImpl::IrregexpResult result;
3340 if (regexp->CaptureCount() == 0) { 3351 if (regexp->CaptureCount() == 0) {
3341 result = SearchRegExpNoCaptureMultiple(subject, 3352 result = SearchRegExpNoCaptureMultiple(isolate,
3353 subject,
3342 regexp, 3354 regexp,
3343 last_match_info, 3355 last_match_info,
3344 &builder); 3356 &builder);
3345 } else { 3357 } else {
3346 result = SearchRegExpMultiple(isolate->heap(), subject, regexp, 3358 result = SearchRegExpMultiple(isolate,
3347 last_match_info, &builder); 3359 subject,
3360 regexp,
3361 last_match_info,
3362 &builder);
3348 } 3363 }
3349 if (result == RegExpImpl::RE_SUCCESS) return *builder.ToJSArray(result_array); 3364 if (result == RegExpImpl::RE_SUCCESS) return *builder.ToJSArray(result_array);
3350 if (result == RegExpImpl::RE_FAILURE) return isolate->heap()->null_value(); 3365 if (result == RegExpImpl::RE_FAILURE) return isolate->heap()->null_value();
3351 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION); 3366 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION);
3352 return Failure::Exception(); 3367 return Failure::Exception();
3353 } 3368 }
3354 3369
3355 3370
3356 static Object* Runtime_NumberToRadixString(RUNTIME_CALLING_CONVENTION) { 3371 static Object* Runtime_NumberToRadixString(RUNTIME_CALLING_CONVENTION) {
3357 RUNTIME_GET_ISOLATE; 3372 RUNTIME_GET_ISOLATE;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { 3487 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
3473 if (index < static_cast<uint32_t>(string->length())) { 3488 if (index < static_cast<uint32_t>(string->length())) {
3474 string->TryFlatten(); 3489 string->TryFlatten();
3475 return LookupSingleCharacterStringFromCode( 3490 return LookupSingleCharacterStringFromCode(
3476 string->Get(index)); 3491 string->Get(index));
3477 } 3492 }
3478 return Execution::CharAt(string, index); 3493 return Execution::CharAt(string, index);
3479 } 3494 }
3480 3495
3481 3496
3482 Object* Runtime::GetElementOrCharAt(Heap* heap, 3497 Object* Runtime::GetElementOrCharAt(Isolate* isolate,
3483 Handle<Object> object, 3498 Handle<Object> object,
3484 uint32_t index) { 3499 uint32_t index) {
3485 // Handle [] indexing on Strings 3500 // Handle [] indexing on Strings
3486 if (object->IsString()) { 3501 if (object->IsString()) {
3487 Handle<Object> result = GetCharAt(Handle<String>::cast(object), index); 3502 Handle<Object> result = GetCharAt(Handle<String>::cast(object), index);
3488 if (!result->IsUndefined()) return *result; 3503 if (!result->IsUndefined()) return *result;
3489 } 3504 }
3490 3505
3491 // Handle [] indexing on String objects 3506 // Handle [] indexing on String objects
3492 if (object->IsStringObjectWithCharacterAt(index)) { 3507 if (object->IsStringObjectWithCharacterAt(index)) {
(...skipping 10 matching lines...) Expand all
3503 3518
3504 return GetElement(object, index); 3519 return GetElement(object, index);
3505 } 3520 }
3506 3521
3507 3522
3508 Object* Runtime::GetElement(Handle<Object> object, uint32_t index) { 3523 Object* Runtime::GetElement(Handle<Object> object, uint32_t index) {
3509 return object->GetElement(index); 3524 return object->GetElement(index);
3510 } 3525 }
3511 3526
3512 3527
3513 Object* Runtime::GetObjectProperty(Heap* heap, 3528 Object* Runtime::GetObjectProperty(Isolate* isolate,
3514 Handle<Object> object, 3529 Handle<Object> object,
3515 Handle<Object> key) { 3530 Handle<Object> key) {
3516 HandleScope scope; 3531 HandleScope scope(isolate);
3517 3532
3518 if (object->IsUndefined() || object->IsNull()) { 3533 if (object->IsUndefined() || object->IsNull()) {
3519 Handle<Object> args[2] = { key, object }; 3534 Handle<Object> args[2] = { key, object };
3520 Handle<Object> error = 3535 Handle<Object> error =
3521 Factory::NewTypeError("non_object_property_load", 3536 Factory::NewTypeError("non_object_property_load",
3522 HandleVector(args, 2)); 3537 HandleVector(args, 2));
3523 return heap->isolate()->Throw(*error); 3538 return isolate->Throw(*error);
3524 } 3539 }
3525 3540
3526 // Check if the given key is an array index. 3541 // Check if the given key is an array index.
3527 uint32_t index; 3542 uint32_t index;
3528 if (key->ToArrayIndex(&index)) { 3543 if (key->ToArrayIndex(&index)) {
3529 return GetElementOrCharAt(heap, object, index); 3544 return GetElementOrCharAt(isolate, object, index);
3530 } 3545 }
3531 3546
3532 // Convert the key to a string - possibly by calling back into JavaScript. 3547 // Convert the key to a string - possibly by calling back into JavaScript.
3533 Handle<String> name; 3548 Handle<String> name;
3534 if (key->IsString()) { 3549 if (key->IsString()) {
3535 name = Handle<String>::cast(key); 3550 name = Handle<String>::cast(key);
3536 } else { 3551 } else {
3537 bool has_pending_exception = false; 3552 bool has_pending_exception = false;
3538 Handle<Object> converted = 3553 Handle<Object> converted =
3539 Execution::ToString(key, &has_pending_exception); 3554 Execution::ToString(key, &has_pending_exception);
3540 if (has_pending_exception) return Failure::Exception(); 3555 if (has_pending_exception) return Failure::Exception();
3541 name = Handle<String>::cast(converted); 3556 name = Handle<String>::cast(converted);
3542 } 3557 }
3543 3558
3544 // Check if the name is trivially convertible to an index and get 3559 // Check if the name is trivially convertible to an index and get
3545 // the element if so. 3560 // the element if so.
3546 if (name->AsArrayIndex(&index)) { 3561 if (name->AsArrayIndex(&index)) {
3547 return GetElementOrCharAt(heap, object, index); 3562 return GetElementOrCharAt(isolate, object, index);
3548 } else { 3563 } else {
3549 PropertyAttributes attr; 3564 PropertyAttributes attr;
3550 return object->GetProperty(*name, &attr); 3565 return object->GetProperty(*name, &attr);
3551 } 3566 }
3552 } 3567 }
3553 3568
3554 3569
3555 static Object* Runtime_GetProperty(RUNTIME_CALLING_CONVENTION) { 3570 static Object* Runtime_GetProperty(RUNTIME_CALLING_CONVENTION) {
3556 RUNTIME_GET_ISOLATE; 3571 RUNTIME_GET_ISOLATE;
3557 NoHandleAllocation ha; 3572 NoHandleAllocation ha;
3558 ASSERT(args.length() == 2); 3573 ASSERT(args.length() == 2);
3559 3574
3560 Handle<Object> object = args.at<Object>(0); 3575 Handle<Object> object = args.at<Object>(0);
3561 Handle<Object> key = args.at<Object>(1); 3576 Handle<Object> key = args.at<Object>(1);
3562 3577
3563 return Runtime::GetObjectProperty(isolate->heap(), object, key); 3578 return Runtime::GetObjectProperty(isolate, object, key);
3564 } 3579 }
3565 3580
3566 3581
3567 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric. 3582 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric.
3568 static Object* Runtime_KeyedGetProperty(RUNTIME_CALLING_CONVENTION) { 3583 static Object* Runtime_KeyedGetProperty(RUNTIME_CALLING_CONVENTION) {
3569 RUNTIME_GET_ISOLATE; 3584 RUNTIME_GET_ISOLATE;
3570 NoHandleAllocation ha; 3585 NoHandleAllocation ha;
3571 ASSERT(args.length() == 2); 3586 ASSERT(args.length() == 2);
3572 3587
3573 // Fast cases for getting named properties of the receiver JSObject 3588 // Fast cases for getting named properties of the receiver JSObject
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 (dictionary->DetailsAt(entry).type() == NORMAL)) { 3627 (dictionary->DetailsAt(entry).type() == NORMAL)) {
3613 Object* value = dictionary->ValueAt(entry); 3628 Object* value = dictionary->ValueAt(entry);
3614 if (!receiver->IsGlobalObject()) return value; 3629 if (!receiver->IsGlobalObject()) return value;
3615 value = JSGlobalPropertyCell::cast(value)->value(); 3630 value = JSGlobalPropertyCell::cast(value)->value();
3616 if (!value->IsTheHole()) return value; 3631 if (!value->IsTheHole()) return value;
3617 // If value is the hole do the general lookup. 3632 // If value is the hole do the general lookup.
3618 } 3633 }
3619 } 3634 }
3620 } else if (args[0]->IsString() && args[1]->IsSmi()) { 3635 } else if (args[0]->IsString() && args[1]->IsSmi()) {
3621 // Fast case for string indexing using [] with a smi index. 3636 // Fast case for string indexing using [] with a smi index.
3622 HandleScope scope; 3637 HandleScope scope(isolate);
3623 Handle<String> str = args.at<String>(0); 3638 Handle<String> str = args.at<String>(0);
3624 int index = Smi::cast(args[1])->value(); 3639 int index = Smi::cast(args[1])->value();
3625 Handle<Object> result = GetCharAt(str, index); 3640 Handle<Object> result = GetCharAt(str, index);
3626 return *result; 3641 return *result;
3627 } 3642 }
3628 3643
3629 // Fall back to GetObjectProperty. 3644 // Fall back to GetObjectProperty.
3630 return Runtime::GetObjectProperty(isolate->heap(), 3645 return Runtime::GetObjectProperty(isolate,
3631 args.at<Object>(0), 3646 args.at<Object>(0),
3632 args.at<Object>(1)); 3647 args.at<Object>(1));
3633 } 3648 }
3634 3649
3635 3650
3636 static Object* Runtime_DefineOrRedefineAccessorProperty( 3651 static Object* Runtime_DefineOrRedefineAccessorProperty(
3637 RUNTIME_CALLING_CONVENTION) { 3652 RUNTIME_CALLING_CONVENTION) {
3638 RUNTIME_GET_ISOLATE; 3653 RUNTIME_GET_ISOLATE;
3639 ASSERT(args.length() == 5); 3654 ASSERT(args.length() == 5);
3640 HandleScope scope; 3655 HandleScope scope(isolate);
3641 CONVERT_ARG_CHECKED(JSObject, obj, 0); 3656 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3642 CONVERT_CHECKED(String, name, args[1]); 3657 CONVERT_CHECKED(String, name, args[1]);
3643 CONVERT_CHECKED(Smi, flag_setter, args[2]); 3658 CONVERT_CHECKED(Smi, flag_setter, args[2]);
3644 CONVERT_CHECKED(JSFunction, fun, args[3]); 3659 CONVERT_CHECKED(JSFunction, fun, args[3]);
3645 CONVERT_CHECKED(Smi, flag_attr, args[4]); 3660 CONVERT_CHECKED(Smi, flag_attr, args[4]);
3646 int unchecked = flag_attr->value(); 3661 int unchecked = flag_attr->value();
3647 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3662 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3648 RUNTIME_ASSERT(!obj->IsNull()); 3663 RUNTIME_ASSERT(!obj->IsNull());
3649 LookupResult result; 3664 LookupResult result;
3650 obj->LocalLookupRealNamedProperty(name, &result); 3665 obj->LocalLookupRealNamedProperty(name, &result);
3651 3666
3652 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3667 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3653 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION 3668 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION
3654 // delete it to avoid running into trouble in DefineAccessor, which 3669 // delete it to avoid running into trouble in DefineAccessor, which
3655 // handles this incorrectly if the property is readonly (does nothing) 3670 // handles this incorrectly if the property is readonly (does nothing)
3656 if (result.IsProperty() && 3671 if (result.IsProperty() &&
3657 (result.type() == FIELD || result.type() == NORMAL 3672 (result.type() == FIELD || result.type() == NORMAL
3658 || result.type() == CONSTANT_FUNCTION)) { 3673 || result.type() == CONSTANT_FUNCTION)) {
3659 Object* ok = obj->DeleteProperty(name, JSObject::NORMAL_DELETION); 3674 Object* ok = obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
3660 if (ok->IsFailure()) return ok; 3675 if (ok->IsFailure()) return ok;
3661 } 3676 }
3662 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); 3677 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr);
3663 } 3678 }
3664 3679
3665 static Object* Runtime_DefineOrRedefineDataProperty( 3680 static Object* Runtime_DefineOrRedefineDataProperty(
3666 RUNTIME_CALLING_CONVENTION) { 3681 RUNTIME_CALLING_CONVENTION) {
3667 RUNTIME_GET_ISOLATE; 3682 RUNTIME_GET_ISOLATE;
3668 ASSERT(args.length() == 4); 3683 ASSERT(args.length() == 4);
3669 HandleScope scope; 3684 HandleScope scope(isolate);
3670 CONVERT_ARG_CHECKED(JSObject, js_object, 0); 3685 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
3671 CONVERT_ARG_CHECKED(String, name, 1); 3686 CONVERT_ARG_CHECKED(String, name, 1);
3672 Handle<Object> obj_value = args.at<Object>(2); 3687 Handle<Object> obj_value = args.at<Object>(2);
3673 3688
3674 CONVERT_CHECKED(Smi, flag, args[3]); 3689 CONVERT_CHECKED(Smi, flag, args[3]);
3675 int unchecked = flag->value(); 3690 int unchecked = flag->value();
3676 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3691 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3677 3692
3678 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3693 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3679 3694
(...skipping 27 matching lines...) Expand all
3707 if (result.IsProperty() && attr != result.GetAttributes()) { 3722 if (result.IsProperty() && attr != result.GetAttributes()) {
3708 // New attributes - normalize to avoid writing to instance descriptor 3723 // New attributes - normalize to avoid writing to instance descriptor
3709 js_object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 3724 js_object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
3710 // Use IgnoreAttributes version since a readonly property may be 3725 // Use IgnoreAttributes version since a readonly property may be
3711 // overridden and SetProperty does not allow this. 3726 // overridden and SetProperty does not allow this.
3712 return js_object->IgnoreAttributesAndSetLocalProperty(*name, 3727 return js_object->IgnoreAttributesAndSetLocalProperty(*name,
3713 *obj_value, 3728 *obj_value,
3714 attr); 3729 attr);
3715 } 3730 }
3716 3731
3717 return Runtime::SetObjectProperty(isolate->heap(), js_object, name, obj_value, 3732 return Runtime::SetObjectProperty(isolate, js_object, name, obj_value, attr);
3718 attr);
3719 } 3733 }
3720 3734
3721 3735
3722 Object* Runtime::SetObjectProperty(Heap* heap, 3736 Object* Runtime::SetObjectProperty(Isolate* isolate,
3723 Handle<Object> object, 3737 Handle<Object> object,
3724 Handle<Object> key, 3738 Handle<Object> key,
3725 Handle<Object> value, 3739 Handle<Object> value,
3726 PropertyAttributes attr) { 3740 PropertyAttributes attr) {
3727 HandleScope scope; 3741 HandleScope scope(isolate);
3728 3742
3729 if (object->IsUndefined() || object->IsNull()) { 3743 if (object->IsUndefined() || object->IsNull()) {
3730 Handle<Object> args[2] = { key, object }; 3744 Handle<Object> args[2] = { key, object };
3731 Handle<Object> error = 3745 Handle<Object> error =
3732 Factory::NewTypeError("non_object_property_store", 3746 Factory::NewTypeError("non_object_property_store",
3733 HandleVector(args, 2)); 3747 HandleVector(args, 2));
3734 return heap->isolate()->Throw(*error); 3748 return isolate->Throw(*error);
3735 } 3749 }
3736 3750
3737 // If the object isn't a JavaScript object, we ignore the store. 3751 // If the object isn't a JavaScript object, we ignore the store.
3738 if (!object->IsJSObject()) return *value; 3752 if (!object->IsJSObject()) return *value;
3739 3753
3740 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 3754 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
3741 3755
3742 // Check if the given key is an array index. 3756 // Check if the given key is an array index.
3743 uint32_t index; 3757 uint32_t index;
3744 if (key->ToArrayIndex(&index)) { 3758 if (key->ToArrayIndex(&index)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3778 Handle<String> name = Handle<String>::cast(converted); 3792 Handle<String> name = Handle<String>::cast(converted);
3779 3793
3780 if (name->AsArrayIndex(&index)) { 3794 if (name->AsArrayIndex(&index)) {
3781 return js_object->SetElement(index, *value); 3795 return js_object->SetElement(index, *value);
3782 } else { 3796 } else {
3783 return js_object->SetProperty(*name, *value, attr); 3797 return js_object->SetProperty(*name, *value, attr);
3784 } 3798 }
3785 } 3799 }
3786 3800
3787 3801
3788 Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, 3802 Object* Runtime::ForceSetObjectProperty(Isolate* isolate,
3803 Handle<JSObject> js_object,
3789 Handle<Object> key, 3804 Handle<Object> key,
3790 Handle<Object> value, 3805 Handle<Object> value,
3791 PropertyAttributes attr) { 3806 PropertyAttributes attr) {
3792 HandleScope scope; 3807 HandleScope scope(isolate);
3793 3808
3794 // Check if the given key is an array index. 3809 // Check if the given key is an array index.
3795 uint32_t index; 3810 uint32_t index;
3796 if (key->ToArrayIndex(&index)) { 3811 if (key->ToArrayIndex(&index)) {
3797 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters 3812 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
3798 // of a string using [] notation. We need to support this too in 3813 // of a string using [] notation. We need to support this too in
3799 // JavaScript. 3814 // JavaScript.
3800 // In the case of a String object we just need to redirect the assignment to 3815 // In the case of a String object we just need to redirect the assignment to
3801 // the underlying string if the index is in range. Since the underlying 3816 // the underlying string if the index is in range. Since the underlying
3802 // string does nothing with the assignment then we can ignore such 3817 // string does nothing with the assignment then we can ignore such
(...skipping 24 matching lines...) Expand all
3827 Handle<String> name = Handle<String>::cast(converted); 3842 Handle<String> name = Handle<String>::cast(converted);
3828 3843
3829 if (name->AsArrayIndex(&index)) { 3844 if (name->AsArrayIndex(&index)) {
3830 return js_object->SetElement(index, *value); 3845 return js_object->SetElement(index, *value);
3831 } else { 3846 } else {
3832 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr); 3847 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr);
3833 } 3848 }
3834 } 3849 }
3835 3850
3836 3851
3837 Object* Runtime::ForceDeleteObjectProperty(Heap* heap, 3852 Object* Runtime::ForceDeleteObjectProperty(Isolate* isolate,
3838 Handle<JSObject> js_object, 3853 Handle<JSObject> js_object,
3839 Handle<Object> key) { 3854 Handle<Object> key) {
3840 HandleScope scope; 3855 HandleScope scope(isolate);
3841 3856
3842 // Check if the given key is an array index. 3857 // Check if the given key is an array index.
3843 uint32_t index; 3858 uint32_t index;
3844 if (key->ToArrayIndex(&index)) { 3859 if (key->ToArrayIndex(&index)) {
3845 // In Firefox/SpiderMonkey, Safari and Opera you can access the 3860 // In Firefox/SpiderMonkey, Safari and Opera you can access the
3846 // characters of a string using [] notation. In the case of a 3861 // characters of a string using [] notation. In the case of a
3847 // String object we just need to redirect the deletion to the 3862 // String object we just need to redirect the deletion to the
3848 // underlying string if the index is in range. Since the 3863 // underlying string if the index is in range. Since the
3849 // underlying string does nothing with the deletion, we can ignore 3864 // underlying string does nothing with the deletion, we can ignore
3850 // such deletions. 3865 // such deletions.
3851 if (js_object->IsStringObjectWithCharacterAt(index)) { 3866 if (js_object->IsStringObjectWithCharacterAt(index)) {
3852 return heap->true_value(); 3867 return isolate->heap()->true_value();
3853 } 3868 }
3854 3869
3855 return js_object->DeleteElement(index, JSObject::FORCE_DELETION); 3870 return js_object->DeleteElement(index, JSObject::FORCE_DELETION);
3856 } 3871 }
3857 3872
3858 Handle<String> key_string; 3873 Handle<String> key_string;
3859 if (key->IsString()) { 3874 if (key->IsString()) {
3860 key_string = Handle<String>::cast(key); 3875 key_string = Handle<String>::cast(key);
3861 } else { 3876 } else {
3862 // Call-back into JavaScript to convert the key to a string. 3877 // Call-back into JavaScript to convert the key to a string.
(...skipping 20 matching lines...) Expand all
3883 // Compute attributes. 3898 // Compute attributes.
3884 PropertyAttributes attributes = NONE; 3899 PropertyAttributes attributes = NONE;
3885 if (args.length() == 4) { 3900 if (args.length() == 4) {
3886 CONVERT_CHECKED(Smi, value_obj, args[3]); 3901 CONVERT_CHECKED(Smi, value_obj, args[3]);
3887 int unchecked_value = value_obj->value(); 3902 int unchecked_value = value_obj->value();
3888 // Only attribute bits should be set. 3903 // Only attribute bits should be set.
3889 RUNTIME_ASSERT( 3904 RUNTIME_ASSERT(
3890 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3905 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3891 attributes = static_cast<PropertyAttributes>(unchecked_value); 3906 attributes = static_cast<PropertyAttributes>(unchecked_value);
3892 } 3907 }
3893 return Runtime::SetObjectProperty(isolate->heap(), object, key, value, 3908 return Runtime::SetObjectProperty(isolate, object, key, value, attributes);
3894 attributes);
3895 } 3909 }
3896 3910
3897 3911
3898 // Set a local property, even if it is READ_ONLY. If the property does not 3912 // Set a local property, even if it is READ_ONLY. If the property does not
3899 // exist, it will be added with attributes NONE. 3913 // exist, it will be added with attributes NONE.
3900 static Object* Runtime_IgnoreAttributesAndSetProperty( 3914 static Object* Runtime_IgnoreAttributesAndSetProperty(
3901 RUNTIME_CALLING_CONVENTION) { 3915 RUNTIME_CALLING_CONVENTION) {
3902 RUNTIME_GET_ISOLATE; 3916 RUNTIME_GET_ISOLATE;
3903 NoHandleAllocation ha; 3917 NoHandleAllocation ha;
3904 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); 3918 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4);
(...skipping 19 matching lines...) Expand all
3924 RUNTIME_GET_ISOLATE; 3938 RUNTIME_GET_ISOLATE;
3925 NoHandleAllocation ha; 3939 NoHandleAllocation ha;
3926 ASSERT(args.length() == 2); 3940 ASSERT(args.length() == 2);
3927 3941
3928 CONVERT_CHECKED(JSObject, object, args[0]); 3942 CONVERT_CHECKED(JSObject, object, args[0]);
3929 CONVERT_CHECKED(String, key, args[1]); 3943 CONVERT_CHECKED(String, key, args[1]);
3930 return object->DeleteProperty(key, JSObject::NORMAL_DELETION); 3944 return object->DeleteProperty(key, JSObject::NORMAL_DELETION);
3931 } 3945 }
3932 3946
3933 3947
3934 static Object* HasLocalPropertyImplementation(Heap* heap, 3948 static Object* HasLocalPropertyImplementation(Isolate* isolate,
3935 Handle<JSObject> object, 3949 Handle<JSObject> object,
3936 Handle<String> key) { 3950 Handle<String> key) {
3937 if (object->HasLocalProperty(*key)) return heap->true_value(); 3951 if (object->HasLocalProperty(*key)) return isolate->heap()->true_value();
3938 // Handle hidden prototypes. If there's a hidden prototype above this thing 3952 // Handle hidden prototypes. If there's a hidden prototype above this thing
3939 // then we have to check it for properties, because they are supposed to 3953 // then we have to check it for properties, because they are supposed to
3940 // look like they are on this object. 3954 // look like they are on this object.
3941 Handle<Object> proto(object->GetPrototype()); 3955 Handle<Object> proto(object->GetPrototype());
3942 if (proto->IsJSObject() && 3956 if (proto->IsJSObject() &&
3943 Handle<JSObject>::cast(proto)->map()->is_hidden_prototype()) { 3957 Handle<JSObject>::cast(proto)->map()->is_hidden_prototype()) {
3944 return HasLocalPropertyImplementation(heap, Handle<JSObject>::cast(proto), 3958 return HasLocalPropertyImplementation(isolate,
3959 Handle<JSObject>::cast(proto),
3945 key); 3960 key);
3946 } 3961 }
3947 return heap->false_value(); 3962 return isolate->heap()->false_value();
3948 } 3963 }
3949 3964
3950 3965
3951 static Object* Runtime_HasLocalProperty(RUNTIME_CALLING_CONVENTION) { 3966 static Object* Runtime_HasLocalProperty(RUNTIME_CALLING_CONVENTION) {
3952 RUNTIME_GET_ISOLATE; 3967 RUNTIME_GET_ISOLATE;
3953 NoHandleAllocation ha; 3968 NoHandleAllocation ha;
3954 ASSERT(args.length() == 2); 3969 ASSERT(args.length() == 2);
3955 CONVERT_CHECKED(String, key, args[1]); 3970 CONVERT_CHECKED(String, key, args[1]);
3956 3971
3957 Object* obj = args[0]; 3972 Object* obj = args[0];
3958 // Only JS objects can have properties. 3973 // Only JS objects can have properties.
3959 if (obj->IsJSObject()) { 3974 if (obj->IsJSObject()) {
3960 JSObject* object = JSObject::cast(obj); 3975 JSObject* object = JSObject::cast(obj);
3961 // Fast case - no interceptors. 3976 // Fast case - no interceptors.
3962 if (object->HasRealNamedProperty(key)) return isolate->heap()->true_value(); 3977 if (object->HasRealNamedProperty(key)) return isolate->heap()->true_value();
3963 // Slow case. Either it's not there or we have an interceptor. We should 3978 // Slow case. Either it's not there or we have an interceptor. We should
3964 // have handles for this kind of deal. 3979 // have handles for this kind of deal.
3965 HandleScope scope; 3980 HandleScope scope(isolate);
3966 return HasLocalPropertyImplementation(isolate->heap(), 3981 return HasLocalPropertyImplementation(isolate,
3967 Handle<JSObject>(object), 3982 Handle<JSObject>(object),
3968 Handle<String>(key)); 3983 Handle<String>(key));
3969 } else if (obj->IsString()) { 3984 } else if (obj->IsString()) {
3970 // Well, there is one exception: Handle [] on strings. 3985 // Well, there is one exception: Handle [] on strings.
3971 uint32_t index; 3986 uint32_t index;
3972 if (key->AsArrayIndex(&index)) { 3987 if (key->AsArrayIndex(&index)) {
3973 String* string = String::cast(obj); 3988 String* string = String::cast(obj);
3974 if (index < static_cast<uint32_t>(string->length())) 3989 if (index < static_cast<uint32_t>(string->length()))
3975 return isolate->heap()->true_value(); 3990 return isolate->heap()->true_value();
3976 } 3991 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4023 return isolate->heap()->ToBoolean(object->HasElement(index)); 4038 return isolate->heap()->ToBoolean(object->HasElement(index));
4024 } 4039 }
4025 4040
4026 PropertyAttributes att = object->GetLocalPropertyAttribute(key); 4041 PropertyAttributes att = object->GetLocalPropertyAttribute(key);
4027 return isolate->heap()->ToBoolean(att != ABSENT && (att & DONT_ENUM) == 0); 4042 return isolate->heap()->ToBoolean(att != ABSENT && (att & DONT_ENUM) == 0);
4028 } 4043 }
4029 4044
4030 4045
4031 static Object* Runtime_GetPropertyNames(RUNTIME_CALLING_CONVENTION) { 4046 static Object* Runtime_GetPropertyNames(RUNTIME_CALLING_CONVENTION) {
4032 RUNTIME_GET_ISOLATE; 4047 RUNTIME_GET_ISOLATE;
4033 HandleScope scope; 4048 HandleScope scope(isolate);
4034 ASSERT(args.length() == 1); 4049 ASSERT(args.length() == 1);
4035 CONVERT_ARG_CHECKED(JSObject, object, 0); 4050 CONVERT_ARG_CHECKED(JSObject, object, 0);
4036 return *GetKeysFor(object); 4051 return *GetKeysFor(object);
4037 } 4052 }
4038 4053
4039 4054
4040 // Returns either a FixedArray as Runtime_GetPropertyNames, 4055 // Returns either a FixedArray as Runtime_GetPropertyNames,
4041 // or, if the given object has an enum cache that contains 4056 // or, if the given object has an enum cache that contains
4042 // all enumerable properties of the object and its prototypes 4057 // all enumerable properties of the object and its prototypes
4043 // have none, the map of the object. This is used to speed up 4058 // have none, the map of the object. This is used to speed up
4044 // the check for deletions during a for-in. 4059 // the check for deletions during a for-in.
4045 static Object* Runtime_GetPropertyNamesFast(RUNTIME_CALLING_CONVENTION) { 4060 static Object* Runtime_GetPropertyNamesFast(RUNTIME_CALLING_CONVENTION) {
4046 RUNTIME_GET_ISOLATE; 4061 RUNTIME_GET_ISOLATE;
4047 ASSERT(args.length() == 1); 4062 ASSERT(args.length() == 1);
4048 4063
4049 CONVERT_CHECKED(JSObject, raw_object, args[0]); 4064 CONVERT_CHECKED(JSObject, raw_object, args[0]);
4050 4065
4051 if (raw_object->IsSimpleEnum()) return raw_object->map(); 4066 if (raw_object->IsSimpleEnum()) return raw_object->map();
4052 4067
4053 HandleScope scope; 4068 HandleScope scope(isolate);
4054 Handle<JSObject> object(raw_object); 4069 Handle<JSObject> object(raw_object);
4055 Handle<FixedArray> content = GetKeysInFixedArrayFor(object, 4070 Handle<FixedArray> content = GetKeysInFixedArrayFor(object,
4056 INCLUDE_PROTOS); 4071 INCLUDE_PROTOS);
4057 4072
4058 // Test again, since cache may have been built by preceding call. 4073 // Test again, since cache may have been built by preceding call.
4059 if (object->IsSimpleEnum()) return object->map(); 4074 if (object->IsSimpleEnum()) return object->map();
4060 4075
4061 return *content; 4076 return *content;
4062 } 4077 }
4063 4078
(...skipping 10 matching lines...) Expand all
4074 proto = JSObject::cast(proto)->GetPrototype(); 4089 proto = JSObject::cast(proto)->GetPrototype();
4075 } 4090 }
4076 return count; 4091 return count;
4077 } 4092 }
4078 4093
4079 4094
4080 // Return the names of the local named properties. 4095 // Return the names of the local named properties.
4081 // args[0]: object 4096 // args[0]: object
4082 static Object* Runtime_GetLocalPropertyNames(RUNTIME_CALLING_CONVENTION) { 4097 static Object* Runtime_GetLocalPropertyNames(RUNTIME_CALLING_CONVENTION) {
4083 RUNTIME_GET_ISOLATE; 4098 RUNTIME_GET_ISOLATE;
4084 HandleScope scope; 4099 HandleScope scope(isolate);
4085 ASSERT(args.length() == 1); 4100 ASSERT(args.length() == 1);
4086 if (!args[0]->IsJSObject()) { 4101 if (!args[0]->IsJSObject()) {
4087 return isolate->heap()->undefined_value(); 4102 return isolate->heap()->undefined_value();
4088 } 4103 }
4089 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4104 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4090 4105
4091 // Skip the global proxy as it has no properties and always delegates to the 4106 // Skip the global proxy as it has no properties and always delegates to the
4092 // real global object. 4107 // real global object.
4093 if (obj->IsJSGlobalProxy()) { 4108 if (obj->IsJSGlobalProxy()) {
4094 // Only collect names if access is permitted. 4109 // Only collect names if access is permitted.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4160 } 4175 }
4161 4176
4162 return *Factory::NewJSArrayWithElements(names); 4177 return *Factory::NewJSArrayWithElements(names);
4163 } 4178 }
4164 4179
4165 4180
4166 // Return the names of the local indexed properties. 4181 // Return the names of the local indexed properties.
4167 // args[0]: object 4182 // args[0]: object
4168 static Object* Runtime_GetLocalElementNames(RUNTIME_CALLING_CONVENTION) { 4183 static Object* Runtime_GetLocalElementNames(RUNTIME_CALLING_CONVENTION) {
4169 RUNTIME_GET_ISOLATE; 4184 RUNTIME_GET_ISOLATE;
4170 HandleScope scope; 4185 HandleScope scope(isolate);
4171 ASSERT(args.length() == 1); 4186 ASSERT(args.length() == 1);
4172 if (!args[0]->IsJSObject()) { 4187 if (!args[0]->IsJSObject()) {
4173 return isolate->heap()->undefined_value(); 4188 return isolate->heap()->undefined_value();
4174 } 4189 }
4175 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4190 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4176 4191
4177 int n = obj->NumberOfLocalElements(static_cast<PropertyAttributes>(NONE)); 4192 int n = obj->NumberOfLocalElements(static_cast<PropertyAttributes>(NONE));
4178 Handle<FixedArray> names = Factory::NewFixedArray(n); 4193 Handle<FixedArray> names = Factory::NewFixedArray(n);
4179 obj->GetLocalElementKeys(*names, static_cast<PropertyAttributes>(NONE)); 4194 obj->GetLocalElementKeys(*names, static_cast<PropertyAttributes>(NONE));
4180 return *Factory::NewJSArrayWithElements(names); 4195 return *Factory::NewJSArrayWithElements(names);
4181 } 4196 }
4182 4197
4183 4198
4184 // Return information on whether an object has a named or indexed interceptor. 4199 // Return information on whether an object has a named or indexed interceptor.
4185 // args[0]: object 4200 // args[0]: object
4186 static Object* Runtime_GetInterceptorInfo(RUNTIME_CALLING_CONVENTION) { 4201 static Object* Runtime_GetInterceptorInfo(RUNTIME_CALLING_CONVENTION) {
4187 RUNTIME_GET_ISOLATE; 4202 RUNTIME_GET_ISOLATE;
4188 HandleScope scope; 4203 HandleScope scope(isolate);
4189 ASSERT(args.length() == 1); 4204 ASSERT(args.length() == 1);
4190 if (!args[0]->IsJSObject()) { 4205 if (!args[0]->IsJSObject()) {
4191 return Smi::FromInt(0); 4206 return Smi::FromInt(0);
4192 } 4207 }
4193 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4208 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4194 4209
4195 int result = 0; 4210 int result = 0;
4196 if (obj->HasNamedInterceptor()) result |= 2; 4211 if (obj->HasNamedInterceptor()) result |= 2;
4197 if (obj->HasIndexedInterceptor()) result |= 1; 4212 if (obj->HasIndexedInterceptor()) result |= 1;
4198 4213
4199 return Smi::FromInt(result); 4214 return Smi::FromInt(result);
4200 } 4215 }
4201 4216
4202 4217
4203 // Return property names from named interceptor. 4218 // Return property names from named interceptor.
4204 // args[0]: object 4219 // args[0]: object
4205 static Object* Runtime_GetNamedInterceptorPropertyNames( 4220 static Object* Runtime_GetNamedInterceptorPropertyNames(
4206 RUNTIME_CALLING_CONVENTION) { 4221 RUNTIME_CALLING_CONVENTION) {
4207 RUNTIME_GET_ISOLATE; 4222 RUNTIME_GET_ISOLATE;
4208 HandleScope scope; 4223 HandleScope scope(isolate);
4209 ASSERT(args.length() == 1); 4224 ASSERT(args.length() == 1);
4210 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4225 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4211 4226
4212 if (obj->HasNamedInterceptor()) { 4227 if (obj->HasNamedInterceptor()) {
4213 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj); 4228 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj);
4214 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result); 4229 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
4215 } 4230 }
4216 return isolate->heap()->undefined_value(); 4231 return isolate->heap()->undefined_value();
4217 } 4232 }
4218 4233
4219 4234
4220 // Return element names from indexed interceptor. 4235 // Return element names from indexed interceptor.
4221 // args[0]: object 4236 // args[0]: object
4222 static Object* Runtime_GetIndexedInterceptorElementNames( 4237 static Object* Runtime_GetIndexedInterceptorElementNames(
4223 RUNTIME_CALLING_CONVENTION) { 4238 RUNTIME_CALLING_CONVENTION) {
4224 RUNTIME_GET_ISOLATE; 4239 RUNTIME_GET_ISOLATE;
4225 HandleScope scope; 4240 HandleScope scope(isolate);
4226 ASSERT(args.length() == 1); 4241 ASSERT(args.length() == 1);
4227 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4242 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4228 4243
4229 if (obj->HasIndexedInterceptor()) { 4244 if (obj->HasIndexedInterceptor()) {
4230 v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj); 4245 v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj);
4231 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result); 4246 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
4232 } 4247 }
4233 return isolate->heap()->undefined_value(); 4248 return isolate->heap()->undefined_value();
4234 } 4249 }
4235 4250
4236 4251
4237 static Object* Runtime_LocalKeys(RUNTIME_CALLING_CONVENTION) { 4252 static Object* Runtime_LocalKeys(RUNTIME_CALLING_CONVENTION) {
4238 RUNTIME_GET_ISOLATE; 4253 RUNTIME_GET_ISOLATE;
4239 ASSERT_EQ(args.length(), 1); 4254 ASSERT_EQ(args.length(), 1);
4240 CONVERT_CHECKED(JSObject, raw_object, args[0]); 4255 CONVERT_CHECKED(JSObject, raw_object, args[0]);
4241 HandleScope scope; 4256 HandleScope scope(isolate);
4242 Handle<JSObject> object(raw_object); 4257 Handle<JSObject> object(raw_object);
4243 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object, 4258 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object,
4244 LOCAL_ONLY); 4259 LOCAL_ONLY);
4245 // Some fast paths through GetKeysInFixedArrayFor reuse a cached 4260 // Some fast paths through GetKeysInFixedArrayFor reuse a cached
4246 // property array and since the result is mutable we have to create 4261 // property array and since the result is mutable we have to create
4247 // a fresh clone on each invocation. 4262 // a fresh clone on each invocation.
4248 int length = contents->length(); 4263 int length = contents->length();
4249 Handle<FixedArray> copy = Factory::NewFixedArray(length); 4264 Handle<FixedArray> copy = Factory::NewFixedArray(length);
4250 for (int i = 0; i < length; i++) { 4265 for (int i = 0; i < length; i++) {
4251 Object* entry = contents->get(i); 4266 Object* entry = contents->get(i);
4252 if (entry->IsString()) { 4267 if (entry->IsString()) {
4253 copy->set(i, entry); 4268 copy->set(i, entry);
4254 } else { 4269 } else {
4255 ASSERT(entry->IsNumber()); 4270 ASSERT(entry->IsNumber());
4256 HandleScope scope; 4271 HandleScope scope(isolate);
4257 Handle<Object> entry_handle(entry); 4272 Handle<Object> entry_handle(entry, isolate);
4258 Handle<Object> entry_str = Factory::NumberToString(entry_handle); 4273 Handle<Object> entry_str = Factory::NumberToString(entry_handle);
4259 copy->set(i, *entry_str); 4274 copy->set(i, *entry_str);
4260 } 4275 }
4261 } 4276 }
4262 return *Factory::NewJSArrayWithElements(copy); 4277 return *Factory::NewJSArrayWithElements(copy);
4263 } 4278 }
4264 4279
4265 4280
4266 static Object* Runtime_GetArgumentsProperty(RUNTIME_CALLING_CONVENTION) { 4281 static Object* Runtime_GetArgumentsProperty(RUNTIME_CALLING_CONVENTION) {
4267 RUNTIME_GET_ISOLATE; 4282 RUNTIME_GET_ISOLATE;
4268 NoHandleAllocation ha; 4283 NoHandleAllocation ha;
4269 ASSERT(args.length() == 1); 4284 ASSERT(args.length() == 1);
4270 4285
4271 // Compute the frame holding the arguments. 4286 // Compute the frame holding the arguments.
4272 JavaScriptFrameIterator it; 4287 JavaScriptFrameIterator it;
4273 it.AdvanceToArgumentsFrame(); 4288 it.AdvanceToArgumentsFrame();
4274 JavaScriptFrame* frame = it.frame(); 4289 JavaScriptFrame* frame = it.frame();
4275 4290
4276 // Get the actual number of provided arguments. 4291 // Get the actual number of provided arguments.
4277 const uint32_t n = frame->GetProvidedParametersCount(); 4292 const uint32_t n = frame->GetProvidedParametersCount();
4278 4293
4279 // Try to convert the key to an index. If successful and within 4294 // Try to convert the key to an index. If successful and within
4280 // index return the the argument from the frame. 4295 // index return the the argument from the frame.
4281 uint32_t index; 4296 uint32_t index;
4282 if (args[0]->ToArrayIndex(&index) && index < n) { 4297 if (args[0]->ToArrayIndex(&index) && index < n) {
4283 return frame->GetParameter(index); 4298 return frame->GetParameter(index);
4284 } 4299 }
4285 4300
4286 // Convert the key to a string. 4301 // Convert the key to a string.
4287 HandleScope scope; 4302 HandleScope scope(isolate);
4288 bool exception = false; 4303 bool exception = false;
4289 Handle<Object> converted = 4304 Handle<Object> converted =
4290 Execution::ToString(args.at<Object>(0), &exception); 4305 Execution::ToString(args.at<Object>(0), &exception);
4291 if (exception) return Failure::Exception(); 4306 if (exception) return Failure::Exception();
4292 Handle<String> key = Handle<String>::cast(converted); 4307 Handle<String> key = Handle<String>::cast(converted);
4293 4308
4294 // Try to convert the string key into an array index. 4309 // Try to convert the string key into an array index.
4295 if (key->AsArrayIndex(&index)) { 4310 if (key->AsArrayIndex(&index)) {
4296 if (index < n) { 4311 if (index < n) {
4297 return frame->GetParameter(index); 4312 return frame->GetParameter(index);
4298 } else { 4313 } else {
4299 return isolate->initial_object_prototype()->GetElement(index); 4314 return isolate->initial_object_prototype()->GetElement(index);
4300 } 4315 }
4301 } 4316 }
4302 4317
4303 // Handle special arguments properties. 4318 // Handle special arguments properties.
4304 if (key->Equals(isolate->heap()->length_symbol())) return Smi::FromInt(n); 4319 if (key->Equals(isolate->heap()->length_symbol())) return Smi::FromInt(n);
4305 if (key->Equals(isolate->heap()->callee_symbol())) return frame->function(); 4320 if (key->Equals(isolate->heap()->callee_symbol())) return frame->function();
4306 4321
4307 // Lookup in the initial Object.prototype object. 4322 // Lookup in the initial Object.prototype object.
4308 return isolate->initial_object_prototype()->GetProperty(*key); 4323 return isolate->initial_object_prototype()->GetProperty(*key);
4309 } 4324 }
4310 4325
4311 4326
4312 static Object* Runtime_ToFastProperties(RUNTIME_CALLING_CONVENTION) { 4327 static Object* Runtime_ToFastProperties(RUNTIME_CALLING_CONVENTION) {
4313 RUNTIME_GET_ISOLATE; 4328 RUNTIME_GET_ISOLATE;
4314 HandleScope scope; 4329 HandleScope scope(isolate);
4315 4330
4316 ASSERT(args.length() == 1); 4331 ASSERT(args.length() == 1);
4317 Handle<Object> object = args.at<Object>(0); 4332 Handle<Object> object = args.at<Object>(0);
4318 if (object->IsJSObject()) { 4333 if (object->IsJSObject()) {
4319 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 4334 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
4320 if (!js_object->HasFastProperties() && !js_object->IsGlobalObject()) { 4335 if (!js_object->HasFastProperties() && !js_object->IsGlobalObject()) {
4321 js_object->TransformToFastProperties(0); 4336 js_object->TransformToFastProperties(0);
4322 } 4337 }
4323 } 4338 }
4324 return *object; 4339 return *object;
4325 } 4340 }
4326 4341
4327 4342
4328 static Object* Runtime_ToSlowProperties(RUNTIME_CALLING_CONVENTION) { 4343 static Object* Runtime_ToSlowProperties(RUNTIME_CALLING_CONVENTION) {
4329 RUNTIME_GET_ISOLATE; 4344 RUNTIME_GET_ISOLATE;
4330 HandleScope scope; 4345 HandleScope scope(isolate);
4331 4346
4332 ASSERT(args.length() == 1); 4347 ASSERT(args.length() == 1);
4333 Handle<Object> object = args.at<Object>(0); 4348 Handle<Object> object = args.at<Object>(0);
4334 if (object->IsJSObject()) { 4349 if (object->IsJSObject()) {
4335 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 4350 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
4336 js_object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 4351 js_object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
4337 } 4352 }
4338 return *object; 4353 return *object;
4339 } 4354 }
4340 4355
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
4716 4731
4717 // ECMA-262 section 15.1.2.3, empty string is NaN 4732 // ECMA-262 section 15.1.2.3, empty string is NaN
4718 double value = StringToDouble(str, ALLOW_TRAILING_JUNK, OS::nan_value()); 4733 double value = StringToDouble(str, ALLOW_TRAILING_JUNK, OS::nan_value());
4719 4734
4720 // Create a number object from the value. 4735 // Create a number object from the value.
4721 return isolate->heap()->NumberFromDouble(value); 4736 return isolate->heap()->NumberFromDouble(value);
4722 } 4737 }
4723 4738
4724 4739
4725 template <class Converter> 4740 template <class Converter>
4726 static Object* ConvertCaseHelper(Heap* heap, 4741 static Object* ConvertCaseHelper(Isolate* isolate,
4727 RuntimeState* state, 4742 RuntimeState* state,
4728 String* s, 4743 String* s,
4729 int length, 4744 int length,
4730 int input_string_length, 4745 int input_string_length,
4731 unibrow::Mapping<Converter, 128>* mapping) { 4746 unibrow::Mapping<Converter, 128>* mapping) {
4732 // We try this twice, once with the assumption that the result is no longer 4747 // We try this twice, once with the assumption that the result is no longer
4733 // than the input and, if that assumption breaks, again with the exact 4748 // than the input and, if that assumption breaks, again with the exact
4734 // length. This may not be pretty, but it is nicer than what was here before 4749 // length. This may not be pretty, but it is nicer than what was here before
4735 // and I hereby claim my vaffel-is. 4750 // and I hereby claim my vaffel-is.
4736 // 4751 //
4737 // Allocate the resulting string. 4752 // Allocate the resulting string.
4738 // 4753 //
4739 // NOTE: This assumes that the upper/lower case of an ascii 4754 // NOTE: This assumes that the upper/lower case of an ascii
4740 // character is also ascii. This is currently the case, but it 4755 // character is also ascii. This is currently the case, but it
4741 // might break in the future if we implement more context and locale 4756 // might break in the future if we implement more context and locale
4742 // dependent upper/lower conversions. 4757 // dependent upper/lower conversions.
4743 Object* o = s->IsAsciiRepresentation() 4758 Object* o = s->IsAsciiRepresentation()
4744 ? heap->AllocateRawAsciiString(length) 4759 ? isolate->heap()->AllocateRawAsciiString(length)
4745 : heap->AllocateRawTwoByteString(length); 4760 : isolate->heap()->AllocateRawTwoByteString(length);
4746 if (o->IsFailure()) return o; 4761 if (o->IsFailure()) return o;
4747 String* result = String::cast(o); 4762 String* result = String::cast(o);
4748 bool has_changed_character = false; 4763 bool has_changed_character = false;
4749 4764
4750 // Convert all characters to upper case, assuming that they will fit 4765 // Convert all characters to upper case, assuming that they will fit
4751 // in the buffer 4766 // in the buffer
4752 Access<StringInputBuffer> buffer(state->string_input_buffer()); 4767 Access<StringInputBuffer> buffer(state->string_input_buffer());
4753 buffer->Reset(s); 4768 buffer->Reset(s);
4754 unibrow::uchar chars[Converter::kMaxWidth]; 4769 unibrow::uchar chars[Converter::kMaxWidth];
4755 // We can assume that the string is not empty 4770 // We can assume that the string is not empty
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4789 while (buffer->has_more()) { 4804 while (buffer->has_more()) {
4790 current = buffer->GetNext(); 4805 current = buffer->GetNext();
4791 // NOTE: we use 0 as the next character here because, while 4806 // NOTE: we use 0 as the next character here because, while
4792 // the next character may affect what a character converts to, 4807 // the next character may affect what a character converts to,
4793 // it does not in any case affect the length of what it convert 4808 // it does not in any case affect the length of what it convert
4794 // to. 4809 // to.
4795 int char_length = mapping->get(current, 0, chars); 4810 int char_length = mapping->get(current, 0, chars);
4796 if (char_length == 0) char_length = 1; 4811 if (char_length == 0) char_length = 1;
4797 current_length += char_length; 4812 current_length += char_length;
4798 if (current_length > Smi::kMaxValue) { 4813 if (current_length > Smi::kMaxValue) {
4799 heap->isolate()->context()->mark_out_of_memory(); 4814 isolate->context()->mark_out_of_memory();
4800 return Failure::OutOfMemoryException(); 4815 return Failure::OutOfMemoryException();
4801 } 4816 }
4802 } 4817 }
4803 // Try again with the real length. 4818 // Try again with the real length.
4804 return Smi::FromInt(current_length); 4819 return Smi::FromInt(current_length);
4805 } else { 4820 } else {
4806 for (int j = 0; j < char_length; j++) { 4821 for (int j = 0; j < char_length; j++) {
4807 result->Set(i, chars[j]); 4822 result->Set(i, chars[j]);
4808 i++; 4823 i++;
4809 } 4824 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4861 }; 4876 };
4862 4877
4863 } // namespace 4878 } // namespace
4864 4879
4865 4880
4866 template <typename ConvertTraits> 4881 template <typename ConvertTraits>
4867 static Object* ConvertCase( 4882 static Object* ConvertCase(
4868 Arguments args, 4883 Arguments args,
4869 Isolate* isolate, 4884 Isolate* isolate,
4870 unibrow::Mapping<typename ConvertTraits::UnibrowConverter, 128>* mapping) { 4885 unibrow::Mapping<typename ConvertTraits::UnibrowConverter, 128>* mapping) {
4871 Heap* heap = isolate->heap();
4872 RuntimeState* state = isolate->runtime_state(); 4886 RuntimeState* state = isolate->runtime_state();
4873 NoHandleAllocation ha; 4887 NoHandleAllocation ha;
4874 CONVERT_CHECKED(String, s, args[0]); 4888 CONVERT_CHECKED(String, s, args[0]);
4875 s = s->TryFlattenGetString(); 4889 s = s->TryFlattenGetString();
4876 4890
4877 const int length = s->length(); 4891 const int length = s->length();
4878 // Assume that the string is not empty; we need this assumption later 4892 // Assume that the string is not empty; we need this assumption later
4879 if (length == 0) return s; 4893 if (length == 0) return s;
4880 4894
4881 // Simpler handling of ascii strings. 4895 // Simpler handling of ascii strings.
4882 // 4896 //
4883 // NOTE: This assumes that the upper/lower case of an ascii 4897 // NOTE: This assumes that the upper/lower case of an ascii
4884 // character is also ascii. This is currently the case, but it 4898 // character is also ascii. This is currently the case, but it
4885 // might break in the future if we implement more context and locale 4899 // might break in the future if we implement more context and locale
4886 // dependent upper/lower conversions. 4900 // dependent upper/lower conversions.
4887 if (s->IsSeqAsciiString()) { 4901 if (s->IsSeqAsciiString()) {
4888 Object* o = isolate->heap()->AllocateRawAsciiString(length); 4902 Object* o = isolate->heap()->AllocateRawAsciiString(length);
4889 if (o->IsFailure()) return o; 4903 if (o->IsFailure()) return o;
4890 SeqAsciiString* result = SeqAsciiString::cast(o); 4904 SeqAsciiString* result = SeqAsciiString::cast(o);
4891 bool has_changed_character = ConvertTraits::ConvertAscii( 4905 bool has_changed_character = ConvertTraits::ConvertAscii(
4892 result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length); 4906 result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length);
4893 return has_changed_character ? result : s; 4907 return has_changed_character ? result : s;
4894 } 4908 }
4895 4909
4896 Object* answer = ConvertCaseHelper(heap, state, s, length, length, mapping); 4910 Object* answer = ConvertCaseHelper(
4911 isolate, state, s, length, length, mapping);
4897 if (answer->IsSmi()) { 4912 if (answer->IsSmi()) {
4898 // Retry with correct length. 4913 // Retry with correct length.
4899 answer = ConvertCaseHelper(heap, state, s, Smi::cast(answer)->value(), 4914 answer = ConvertCaseHelper(isolate, state, s, Smi::cast(answer)->value(),
4900 length, mapping); 4915 length, mapping);
4901 } 4916 }
4902 return answer; // This may be a failure. 4917 return answer; // This may be a failure.
4903 } 4918 }
4904 4919
4905 4920
4906 static Object* Runtime_StringToLowerCase(RUNTIME_CALLING_CONVENTION) { 4921 static Object* Runtime_StringToLowerCase(RUNTIME_CALLING_CONVENTION) {
4907 RUNTIME_GET_ISOLATE; 4922 RUNTIME_GET_ISOLATE;
4908 return ConvertCase<ToLowerTraits>( 4923 return ConvertCase<ToLowerTraits>(
4909 args, isolate, isolate->runtime_state()->to_lower_mapping()); 4924 args, isolate, isolate->runtime_state()->to_lower_mapping());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4991 default: 5006 default:
4992 UNREACHABLE(); 5007 UNREACHABLE();
4993 return; 5008 return;
4994 } 5009 }
4995 } 5010 }
4996 5011
4997 5012
4998 static Object* Runtime_StringSplit(RUNTIME_CALLING_CONVENTION) { 5013 static Object* Runtime_StringSplit(RUNTIME_CALLING_CONVENTION) {
4999 RUNTIME_GET_ISOLATE; 5014 RUNTIME_GET_ISOLATE;
5000 ASSERT(args.length() == 3); 5015 ASSERT(args.length() == 3);
5001 HandleScope handle_scope; 5016 HandleScope handle_scope(isolate);
5002 CONVERT_ARG_CHECKED(String, subject, 0); 5017 CONVERT_ARG_CHECKED(String, subject, 0);
5003 CONVERT_ARG_CHECKED(String, pattern, 1); 5018 CONVERT_ARG_CHECKED(String, pattern, 1);
5004 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); 5019 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
5005 5020
5006 int subject_length = subject->length(); 5021 int subject_length = subject->length();
5007 int pattern_length = pattern->length(); 5022 int pattern_length = pattern->length();
5008 RUNTIME_ASSERT(pattern_length > 0); 5023 RUNTIME_ASSERT(pattern_length > 0);
5009 5024
5010 // The limit can be very large (0xffffffffu), but since the pattern 5025 // The limit can be very large (0xffffffffu), but since the pattern
5011 // isn't empty, we can never create more parts than ~half the length 5026 // isn't empty, we can never create more parts than ~half the length
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5122 } 5137 }
5123 #endif 5138 #endif
5124 return i; 5139 return i;
5125 } 5140 }
5126 5141
5127 5142
5128 // Converts a String to JSArray. 5143 // Converts a String to JSArray.
5129 // For example, "foo" => ["f", "o", "o"]. 5144 // For example, "foo" => ["f", "o", "o"].
5130 static Object* Runtime_StringToArray(RUNTIME_CALLING_CONVENTION) { 5145 static Object* Runtime_StringToArray(RUNTIME_CALLING_CONVENTION) {
5131 RUNTIME_GET_ISOLATE; 5146 RUNTIME_GET_ISOLATE;
5132 HandleScope scope; 5147 HandleScope scope(isolate);
5133 ASSERT(args.length() == 1); 5148 ASSERT(args.length() == 1);
5134 CONVERT_ARG_CHECKED(String, s, 0); 5149 CONVERT_ARG_CHECKED(String, s, 0);
5135 5150
5136 s->TryFlatten(); 5151 s->TryFlatten();
5137 const int length = s->length(); 5152 const int length = s->length();
5138 5153
5139 Handle<FixedArray> elements; 5154 Handle<FixedArray> elements;
5140 if (s->IsFlat() && s->IsAsciiRepresentation()) { 5155 if (s->IsFlat() && s->IsAsciiRepresentation()) {
5141 Object* obj = isolate->heap()->AllocateUninitializedFixedArray(length); 5156 Object* obj = isolate->heap()->AllocateUninitializedFixedArray(length);
5142 if (obj->IsFailure()) return obj; 5157 if (obj->IsFailure()) return obj;
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
6485 array->set(i, *--parameters, mode); 6500 array->set(i, *--parameters, mode);
6486 } 6501 }
6487 JSObject::cast(result)->set_elements(FixedArray::cast(obj)); 6502 JSObject::cast(result)->set_elements(FixedArray::cast(obj));
6488 } 6503 }
6489 return result; 6504 return result;
6490 } 6505 }
6491 6506
6492 6507
6493 static Object* Runtime_NewClosure(RUNTIME_CALLING_CONVENTION) { 6508 static Object* Runtime_NewClosure(RUNTIME_CALLING_CONVENTION) {
6494 RUNTIME_GET_ISOLATE; 6509 RUNTIME_GET_ISOLATE;
6495 HandleScope scope; 6510 HandleScope scope(isolate);
6496 ASSERT(args.length() == 2); 6511 ASSERT(args.length() == 2);
6497 CONVERT_ARG_CHECKED(Context, context, 0); 6512 CONVERT_ARG_CHECKED(Context, context, 0);
6498 CONVERT_ARG_CHECKED(SharedFunctionInfo, shared, 1); 6513 CONVERT_ARG_CHECKED(SharedFunctionInfo, shared, 1);
6499 6514
6500 PretenureFlag pretenure = (context->global_context() == *context) 6515 PretenureFlag pretenure = (context->global_context() == *context)
6501 ? TENURED // Allocate global closures in old space. 6516 ? TENURED // Allocate global closures in old space.
6502 : NOT_TENURED; // Allocate local closures in new space. 6517 : NOT_TENURED; // Allocate local closures in new space.
6503 Handle<JSFunction> result = 6518 Handle<JSFunction> result =
6504 Factory::NewFunctionFromSharedFunctionInfo(shared, context, pretenure); 6519 Factory::NewFunctionFromSharedFunctionInfo(shared, context, pretenure);
6505 return *result; 6520 return *result;
6506 } 6521 }
6507 6522
6508 static Object* Runtime_NewObjectFromBound(RUNTIME_CALLING_CONVENTION) { 6523 static Object* Runtime_NewObjectFromBound(RUNTIME_CALLING_CONVENTION) {
6509 RUNTIME_GET_ISOLATE; 6524 RUNTIME_GET_ISOLATE;
6510 HandleScope scope; 6525 HandleScope scope(isolate);
6511 ASSERT(args.length() == 2); 6526 ASSERT(args.length() == 2);
6512 CONVERT_ARG_CHECKED(JSFunction, function, 0); 6527 CONVERT_ARG_CHECKED(JSFunction, function, 0);
6513 CONVERT_ARG_CHECKED(JSArray, params, 1); 6528 CONVERT_ARG_CHECKED(JSArray, params, 1);
6514 6529
6515 RUNTIME_ASSERT(params->HasFastElements()); 6530 RUNTIME_ASSERT(params->HasFastElements());
6516 FixedArray* fixed = FixedArray::cast(params->elements()); 6531 FixedArray* fixed = FixedArray::cast(params->elements());
6517 6532
6518 int fixed_length = Smi::cast(params->length())->value(); 6533 int fixed_length = Smi::cast(params->length())->value();
6519 SmartPointer<Object**> param_data(NewArray<Object**>(fixed_length)); 6534 SmartPointer<Object**> param_data(NewArray<Object**>(fixed_length));
6520 for (int i = 0; i < fixed_length; i++) { 6535 for (int i = 0; i < fixed_length; i++) {
6521 Handle<Object> val = Handle<Object>(fixed->get(i)); 6536 Handle<Object> val(fixed->get(i), isolate);
6522 param_data[i] = val.location(); 6537 param_data[i] = val.location();
6523 } 6538 }
6524 6539
6525 bool exception = false; 6540 bool exception = false;
6526 Handle<Object> result = Execution::New( 6541 Handle<Object> result = Execution::New(
6527 function, fixed_length, *param_data, &exception); 6542 function, fixed_length, *param_data, &exception);
6528 if (exception) { 6543 if (exception) {
6529 return Failure::Exception(); 6544 return Failure::Exception();
6530 } 6545 }
6531 ASSERT(!result.is_null()); 6546 ASSERT(!result.is_null());
6532 return *result; 6547 return *result;
6533 } 6548 }
6534 6549
6535 6550
6536 static void TrySettingInlineConstructStub(Handle<JSFunction> function) { 6551 static void TrySettingInlineConstructStub(Isolate* isolate,
6552 Handle<JSFunction> function) {
6537 Handle<Object> prototype = Factory::null_value(); 6553 Handle<Object> prototype = Factory::null_value();
6538 if (function->has_instance_prototype()) { 6554 if (function->has_instance_prototype()) {
6539 prototype = Handle<Object>(function->instance_prototype()); 6555 prototype = Handle<Object>(function->instance_prototype(), isolate);
6540 } 6556 }
6541 if (function->shared()->CanGenerateInlineConstructor(*prototype)) { 6557 if (function->shared()->CanGenerateInlineConstructor(*prototype)) {
6542 ConstructStubCompiler compiler; 6558 ConstructStubCompiler compiler;
6543 Object* code = compiler.CompileConstructStub(function->shared()); 6559 Object* code = compiler.CompileConstructStub(function->shared());
6544 if (!code->IsFailure()) { 6560 if (!code->IsFailure()) {
6545 function->shared()->set_construct_stub(Code::cast(code)); 6561 function->shared()->set_construct_stub(Code::cast(code));
6546 } 6562 }
6547 } 6563 }
6548 } 6564 }
6549 6565
6550 6566
6551 static Object* Runtime_NewObject(RUNTIME_CALLING_CONVENTION) { 6567 static Object* Runtime_NewObject(RUNTIME_CALLING_CONVENTION) {
6552 RUNTIME_GET_ISOLATE; 6568 RUNTIME_GET_ISOLATE;
6553 HandleScope scope; 6569 HandleScope scope(isolate);
6554 ASSERT(args.length() == 1); 6570 ASSERT(args.length() == 1);
6555 6571
6556 Handle<Object> constructor = args.at<Object>(0); 6572 Handle<Object> constructor = args.at<Object>(0);
6557 6573
6558 // If the constructor isn't a proper function we throw a type error. 6574 // If the constructor isn't a proper function we throw a type error.
6559 if (!constructor->IsJSFunction()) { 6575 if (!constructor->IsJSFunction()) {
6560 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1); 6576 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1);
6561 Handle<Object> type_error = 6577 Handle<Object> type_error =
6562 Factory::NewTypeError("not_constructor", arguments); 6578 Factory::NewTypeError("not_constructor", arguments);
6563 return isolate->Throw(*type_error); 6579 return isolate->Throw(*type_error);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6602 // The function should be compiled for the optimization hints to be available. 6618 // The function should be compiled for the optimization hints to be available.
6603 Handle<SharedFunctionInfo> shared(function->shared()); 6619 Handle<SharedFunctionInfo> shared(function->shared());
6604 EnsureCompiled(shared, CLEAR_EXCEPTION); 6620 EnsureCompiled(shared, CLEAR_EXCEPTION);
6605 6621
6606 if (!function->has_initial_map() && 6622 if (!function->has_initial_map() &&
6607 shared->IsInobjectSlackTrackingInProgress()) { 6623 shared->IsInobjectSlackTrackingInProgress()) {
6608 // The tracking is already in progress for another function. We can only 6624 // The tracking is already in progress for another function. We can only
6609 // track one initial_map at a time, so we force the completion before the 6625 // track one initial_map at a time, so we force the completion before the
6610 // function is called as a constructor for the first time. 6626 // function is called as a constructor for the first time.
6611 shared->CompleteInobjectSlackTracking(); 6627 shared->CompleteInobjectSlackTracking();
6612 TrySettingInlineConstructStub(function); 6628 TrySettingInlineConstructStub(isolate, function);
6613 } 6629 }
6614 6630
6615 bool first_allocation = !shared->live_objects_may_exist(); 6631 bool first_allocation = !shared->live_objects_may_exist();
6616 Handle<JSObject> result = Factory::NewJSObject(function); 6632 Handle<JSObject> result = Factory::NewJSObject(function);
6617 // Delay setting the stub if inobject slack tracking is in progress. 6633 // Delay setting the stub if inobject slack tracking is in progress.
6618 if (first_allocation && !shared->IsInobjectSlackTrackingInProgress()) { 6634 if (first_allocation && !shared->IsInobjectSlackTrackingInProgress()) {
6619 TrySettingInlineConstructStub(function); 6635 TrySettingInlineConstructStub(isolate, function);
6620 } 6636 }
6621 6637
6622 isolate->counters()->constructed_objects()->Increment(); 6638 isolate->counters()->constructed_objects()->Increment();
6623 isolate->counters()->constructed_objects_runtime()->Increment(); 6639 isolate->counters()->constructed_objects_runtime()->Increment();
6624 6640
6625 return *result; 6641 return *result;
6626 } 6642 }
6627 6643
6628 6644
6629 static Object* Runtime_FinalizeInstanceSize(RUNTIME_CALLING_CONVENTION) { 6645 static Object* Runtime_FinalizeInstanceSize(RUNTIME_CALLING_CONVENTION) {
6630 RUNTIME_GET_ISOLATE; 6646 RUNTIME_GET_ISOLATE;
6631 HandleScope scope; 6647 HandleScope scope(isolate);
6632 ASSERT(args.length() == 1); 6648 ASSERT(args.length() == 1);
6633 6649
6634 CONVERT_ARG_CHECKED(JSFunction, function, 0); 6650 CONVERT_ARG_CHECKED(JSFunction, function, 0);
6635 function->shared()->CompleteInobjectSlackTracking(); 6651 function->shared()->CompleteInobjectSlackTracking();
6636 TrySettingInlineConstructStub(function); 6652 TrySettingInlineConstructStub(isolate, function);
6637 6653
6638 return isolate->heap()->undefined_value(); 6654 return isolate->heap()->undefined_value();
6639 } 6655 }
6640 6656
6641 6657
6642 static Object* Runtime_LazyCompile(RUNTIME_CALLING_CONVENTION) { 6658 static Object* Runtime_LazyCompile(RUNTIME_CALLING_CONVENTION) {
6643 RUNTIME_GET_ISOLATE; 6659 RUNTIME_GET_ISOLATE;
6644 HandleScope scope; 6660 HandleScope scope(isolate);
6645 ASSERT(args.length() == 1); 6661 ASSERT(args.length() == 1);
6646 6662
6647 Handle<JSFunction> function = args.at<JSFunction>(0); 6663 Handle<JSFunction> function = args.at<JSFunction>(0);
6648 #ifdef DEBUG 6664 #ifdef DEBUG
6649 if (FLAG_trace_lazy && !function->shared()->is_compiled()) { 6665 if (FLAG_trace_lazy && !function->shared()->is_compiled()) {
6650 PrintF("[lazy: "); 6666 PrintF("[lazy: ");
6651 function->shared()->name()->Print(); 6667 function->shared()->name()->Print();
6652 PrintF("]\n"); 6668 PrintF("]\n");
6653 } 6669 }
6654 #endif 6670 #endif
6655 6671
6656 // Compile the target function. Here we compile using CompileLazyInLoop in 6672 // Compile the target function. Here we compile using CompileLazyInLoop in
6657 // order to get the optimized version. This helps code like delta-blue 6673 // order to get the optimized version. This helps code like delta-blue
6658 // that calls performance-critical routines through constructors. A 6674 // that calls performance-critical routines through constructors. A
6659 // constructor call doesn't use a CallIC, it uses a LoadIC followed by a 6675 // constructor call doesn't use a CallIC, it uses a LoadIC followed by a
6660 // direct call. Since the in-loop tracking takes place through CallICs 6676 // direct call. Since the in-loop tracking takes place through CallICs
6661 // this means that things called through constructors are never known to 6677 // this means that things called through constructors are never known to
6662 // be in loops. We compile them as if they are in loops here just in case. 6678 // be in loops. We compile them as if they are in loops here just in case.
6663 ASSERT(!function->is_compiled()); 6679 ASSERT(!function->is_compiled());
6664 if (!CompileLazyInLoop(function, Handle<Object>::null(), KEEP_EXCEPTION)) { 6680 if (!CompileLazyInLoop(function, Handle<Object>::null(), KEEP_EXCEPTION)) {
6665 return Failure::Exception(); 6681 return Failure::Exception();
6666 } 6682 }
6667 6683
6668 return function->code(); 6684 return function->code();
6669 } 6685 }
6670 6686
6671 6687
6672 static Object* Runtime_GetFunctionDelegate(RUNTIME_CALLING_CONVENTION) { 6688 static Object* Runtime_GetFunctionDelegate(RUNTIME_CALLING_CONVENTION) {
6673 RUNTIME_GET_ISOLATE; 6689 RUNTIME_GET_ISOLATE;
6674 HandleScope scope; 6690 HandleScope scope(isolate);
6675 ASSERT(args.length() == 1); 6691 ASSERT(args.length() == 1);
6676 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 6692 RUNTIME_ASSERT(!args[0]->IsJSFunction());
6677 return *Execution::GetFunctionDelegate(args.at<Object>(0)); 6693 return *Execution::GetFunctionDelegate(args.at<Object>(0));
6678 } 6694 }
6679 6695
6680 6696
6681 static Object* Runtime_GetConstructorDelegate(RUNTIME_CALLING_CONVENTION) { 6697 static Object* Runtime_GetConstructorDelegate(RUNTIME_CALLING_CONVENTION) {
6682 RUNTIME_GET_ISOLATE; 6698 RUNTIME_GET_ISOLATE;
6683 HandleScope scope; 6699 HandleScope scope(isolate);
6684 ASSERT(args.length() == 1); 6700 ASSERT(args.length() == 1);
6685 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 6701 RUNTIME_ASSERT(!args[0]->IsJSFunction());
6686 return *Execution::GetConstructorDelegate(args.at<Object>(0)); 6702 return *Execution::GetConstructorDelegate(args.at<Object>(0));
6687 } 6703 }
6688 6704
6689 6705
6690 static Object* Runtime_NewContext(RUNTIME_CALLING_CONVENTION) { 6706 static Object* Runtime_NewContext(RUNTIME_CALLING_CONVENTION) {
6691 RUNTIME_GET_ISOLATE; 6707 RUNTIME_GET_ISOLATE;
6692 NoHandleAllocation ha; 6708 NoHandleAllocation ha;
6693 ASSERT(args.length() == 1); 6709 ASSERT(args.length() == 1);
6694 6710
6695 CONVERT_CHECKED(JSFunction, function, args[0]); 6711 CONVERT_CHECKED(JSFunction, function, args[0]);
6696 int length = function->shared()->scope_info()->NumberOfContextSlots(); 6712 int length = function->shared()->scope_info()->NumberOfContextSlots();
6697 Object* result = isolate->heap()->AllocateFunctionContext(length, function); 6713 Object* result = isolate->heap()->AllocateFunctionContext(length, function);
6698 if (result->IsFailure()) return result; 6714 if (result->IsFailure()) return result;
6699 6715
6700 isolate->set_context(Context::cast(result)); 6716 isolate->set_context(Context::cast(result));
6701 6717
6702 return result; // non-failure 6718 return result; // non-failure
6703 } 6719 }
6704 6720
6705 static Object* PushContextHelper(Heap* heap, 6721 static Object* PushContextHelper(Isolate* isolate,
6706 Object* object, 6722 Object* object,
6707 bool is_catch_context) { 6723 bool is_catch_context) {
6708 // Convert the object to a proper JavaScript object. 6724 // Convert the object to a proper JavaScript object.
6709 Object* js_object = object; 6725 Object* js_object = object;
6710 if (!js_object->IsJSObject()) { 6726 if (!js_object->IsJSObject()) {
6711 js_object = js_object->ToObject(); 6727 js_object = js_object->ToObject();
6712 if (js_object->IsFailure()) { 6728 if (js_object->IsFailure()) {
6713 if (!Failure::cast(js_object)->IsInternalError()) return js_object; 6729 if (!Failure::cast(js_object)->IsInternalError()) return js_object;
6714 HandleScope scope; 6730 HandleScope scope(isolate);
6715 Handle<Object> handle(object); 6731 Handle<Object> handle(object, isolate);
6716 Handle<Object> result = 6732 Handle<Object> result =
6717 Factory::NewTypeError("with_expression", HandleVector(&handle, 1)); 6733 Factory::NewTypeError("with_expression", HandleVector(&handle, 1));
6718 return heap->isolate()->Throw(*result); 6734 return isolate->Throw(*result);
6719 } 6735 }
6720 } 6736 }
6721 6737
6722 Object* result = 6738 Object* result = isolate->heap()->AllocateWithContext(
6723 heap->AllocateWithContext(heap->isolate()->context(), 6739 isolate->context(), JSObject::cast(js_object), is_catch_context);
6724 JSObject::cast(js_object),
6725 is_catch_context);
6726 if (result->IsFailure()) return result; 6740 if (result->IsFailure()) return result;
6727 6741
6728 Context* context = Context::cast(result); 6742 Context* context = Context::cast(result);
6729 heap->isolate()->set_context(context); 6743 isolate->set_context(context);
6730 6744
6731 return result; 6745 return result;
6732 } 6746 }
6733 6747
6734 6748
6735 static Object* Runtime_PushContext(RUNTIME_CALLING_CONVENTION) { 6749 static Object* Runtime_PushContext(RUNTIME_CALLING_CONVENTION) {
6736 RUNTIME_GET_ISOLATE; 6750 RUNTIME_GET_ISOLATE;
6737 NoHandleAllocation ha; 6751 NoHandleAllocation ha;
6738 ASSERT(args.length() == 1); 6752 ASSERT(args.length() == 1);
6739 return PushContextHelper(isolate->heap(), args[0], false); 6753 return PushContextHelper(isolate, args[0], false);
6740 } 6754 }
6741 6755
6742 6756
6743 static Object* Runtime_PushCatchContext(RUNTIME_CALLING_CONVENTION) { 6757 static Object* Runtime_PushCatchContext(RUNTIME_CALLING_CONVENTION) {
6744 RUNTIME_GET_ISOLATE; 6758 RUNTIME_GET_ISOLATE;
6745 NoHandleAllocation ha; 6759 NoHandleAllocation ha;
6746 ASSERT(args.length() == 1); 6760 ASSERT(args.length() == 1);
6747 return PushContextHelper(isolate->heap(), args[0], true); 6761 return PushContextHelper(isolate, args[0], true);
6748 } 6762 }
6749 6763
6750 6764
6751 static Object* Runtime_LookupContext(RUNTIME_CALLING_CONVENTION) { 6765 static Object* Runtime_LookupContext(RUNTIME_CALLING_CONVENTION) {
6752 RUNTIME_GET_ISOLATE; 6766 RUNTIME_GET_ISOLATE;
6753 HandleScope scope; 6767 HandleScope scope(isolate);
6754 ASSERT(args.length() == 2); 6768 ASSERT(args.length() == 2);
6755 6769
6756 CONVERT_ARG_CHECKED(Context, context, 0); 6770 CONVERT_ARG_CHECKED(Context, context, 0);
6757 CONVERT_ARG_CHECKED(String, name, 1); 6771 CONVERT_ARG_CHECKED(String, name, 1);
6758 6772
6759 int index; 6773 int index;
6760 PropertyAttributes attributes; 6774 PropertyAttributes attributes;
6761 ContextLookupFlags flags = FOLLOW_CHAINS; 6775 ContextLookupFlags flags = FOLLOW_CHAINS;
6762 Handle<Object> holder = 6776 Handle<Object> holder =
6763 context->Lookup(name, flags, &index, &attributes); 6777 context->Lookup(name, flags, &index, &attributes);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
6826 // Fall back to using the global object as the receiver if the 6840 // Fall back to using the global object as the receiver if the
6827 // property turns out to be a local variable allocated in a context 6841 // property turns out to be a local variable allocated in a context
6828 // extension object - introduced via eval. 6842 // extension object - introduced via eval.
6829 return top->global()->global_receiver(); 6843 return top->global()->global_receiver();
6830 } 6844 }
6831 6845
6832 6846
6833 static ObjectPair LoadContextSlotHelper(Arguments args, 6847 static ObjectPair LoadContextSlotHelper(Arguments args,
6834 Isolate* isolate, 6848 Isolate* isolate,
6835 bool throw_error) { 6849 bool throw_error) {
6836 HandleScope scope; 6850 HandleScope scope(isolate);
6837 ASSERT_EQ(2, args.length()); 6851 ASSERT_EQ(2, args.length());
6838 6852
6839 if (!args[0]->IsContext() || !args[1]->IsString()) { 6853 if (!args[0]->IsContext() || !args[1]->IsString()) {
6840 return MakePair(isolate->ThrowIllegalOperation(), NULL); 6854 return MakePair(isolate->ThrowIllegalOperation(), NULL);
6841 } 6855 }
6842 Handle<Context> context = args.at<Context>(0); 6856 Handle<Context> context = args.at<Context>(0);
6843 Handle<String> name = args.at<String>(1); 6857 Handle<String> name = args.at<String>(1);
6844 6858
6845 int index; 6859 int index;
6846 PropertyAttributes attributes; 6860 PropertyAttributes attributes;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
6902 6916
6903 static ObjectPair Runtime_LoadContextSlotNoReferenceError( 6917 static ObjectPair Runtime_LoadContextSlotNoReferenceError(
6904 RUNTIME_CALLING_CONVENTION) { 6918 RUNTIME_CALLING_CONVENTION) {
6905 RUNTIME_GET_ISOLATE; 6919 RUNTIME_GET_ISOLATE;
6906 return LoadContextSlotHelper(args, isolate, false); 6920 return LoadContextSlotHelper(args, isolate, false);
6907 } 6921 }
6908 6922
6909 6923
6910 static Object* Runtime_StoreContextSlot(RUNTIME_CALLING_CONVENTION) { 6924 static Object* Runtime_StoreContextSlot(RUNTIME_CALLING_CONVENTION) {
6911 RUNTIME_GET_ISOLATE; 6925 RUNTIME_GET_ISOLATE;
6912 HandleScope scope; 6926 HandleScope scope(isolate);
6913 ASSERT(args.length() == 3); 6927 ASSERT(args.length() == 3);
6914 6928
6915 Handle<Object> value(args[0]); 6929 Handle<Object> value(args[0], isolate);
6916 CONVERT_ARG_CHECKED(Context, context, 1); 6930 CONVERT_ARG_CHECKED(Context, context, 1);
6917 CONVERT_ARG_CHECKED(String, name, 2); 6931 CONVERT_ARG_CHECKED(String, name, 2);
6918 6932
6919 int index; 6933 int index;
6920 PropertyAttributes attributes; 6934 PropertyAttributes attributes;
6921 ContextLookupFlags flags = FOLLOW_CHAINS; 6935 ContextLookupFlags flags = FOLLOW_CHAINS;
6922 Handle<Object> holder = 6936 Handle<Object> holder =
6923 context->Lookup(name, flags, &index, &attributes); 6937 context->Lookup(name, flags, &index, &attributes);
6924 6938
6925 if (index >= 0) { 6939 if (index >= 0) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6964 ASSERT(isolate->has_pending_exception()); 6978 ASSERT(isolate->has_pending_exception());
6965 return Failure::Exception(); 6979 return Failure::Exception();
6966 } 6980 }
6967 } 6981 }
6968 return *value; 6982 return *value;
6969 } 6983 }
6970 6984
6971 6985
6972 static Object* Runtime_Throw(RUNTIME_CALLING_CONVENTION) { 6986 static Object* Runtime_Throw(RUNTIME_CALLING_CONVENTION) {
6973 RUNTIME_GET_ISOLATE; 6987 RUNTIME_GET_ISOLATE;
6974 HandleScope scope; 6988 HandleScope scope(isolate);
6975 ASSERT(args.length() == 1); 6989 ASSERT(args.length() == 1);
6976 6990
6977 return isolate->Throw(args[0]); 6991 return isolate->Throw(args[0]);
6978 } 6992 }
6979 6993
6980 6994
6981 static Object* Runtime_ReThrow(RUNTIME_CALLING_CONVENTION) { 6995 static Object* Runtime_ReThrow(RUNTIME_CALLING_CONVENTION) {
6982 RUNTIME_GET_ISOLATE; 6996 RUNTIME_GET_ISOLATE;
6983 HandleScope scope; 6997 HandleScope scope(isolate);
6984 ASSERT(args.length() == 1); 6998 ASSERT(args.length() == 1);
6985 6999
6986 return isolate->ReThrow(args[0]); 7000 return isolate->ReThrow(args[0]);
6987 } 7001 }
6988 7002
6989 7003
6990 static Object* Runtime_PromoteScheduledException(RUNTIME_CALLING_CONVENTION) { 7004 static Object* Runtime_PromoteScheduledException(RUNTIME_CALLING_CONVENTION) {
6991 RUNTIME_GET_ISOLATE; 7005 RUNTIME_GET_ISOLATE;
6992 ASSERT_EQ(0, args.length()); 7006 ASSERT_EQ(0, args.length());
6993 return isolate->PromoteScheduledException(); 7007 return isolate->PromoteScheduledException();
6994 } 7008 }
6995 7009
6996 7010
6997 static Object* Runtime_ThrowReferenceError(RUNTIME_CALLING_CONVENTION) { 7011 static Object* Runtime_ThrowReferenceError(RUNTIME_CALLING_CONVENTION) {
6998 RUNTIME_GET_ISOLATE; 7012 RUNTIME_GET_ISOLATE;
6999 HandleScope scope; 7013 HandleScope scope(isolate);
7000 ASSERT(args.length() == 1); 7014 ASSERT(args.length() == 1);
7001 7015
7002 Handle<Object> name(args[0]); 7016 Handle<Object> name(args[0], isolate);
7003 Handle<Object> reference_error = 7017 Handle<Object> reference_error =
7004 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); 7018 Factory::NewReferenceError("not_defined", HandleVector(&name, 1));
7005 return isolate->Throw(*reference_error); 7019 return isolate->Throw(*reference_error);
7006 } 7020 }
7007 7021
7008 7022
7009 static Object* Runtime_StackGuard(RUNTIME_CALLING_CONVENTION) { 7023 static Object* Runtime_StackGuard(RUNTIME_CALLING_CONVENTION) {
7010 RUNTIME_GET_ISOLATE; 7024 RUNTIME_GET_ISOLATE;
7011 ASSERT(args.length() == 1); 7025 ASSERT(args.length() == 1);
7012 // First check if this is a real stack overflow. 7026 // First check if this is a real stack overflow.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
7172 // the number in a Date object representing a particular instant in 7186 // the number in a Date object representing a particular instant in
7173 // time is milliseconds. Therefore, we floor the result of getting 7187 // time is milliseconds. Therefore, we floor the result of getting
7174 // the OS time. 7188 // the OS time.
7175 double millis = floor(OS::TimeCurrentMillis()); 7189 double millis = floor(OS::TimeCurrentMillis());
7176 return isolate->heap()->NumberFromDouble(millis); 7190 return isolate->heap()->NumberFromDouble(millis);
7177 } 7191 }
7178 7192
7179 7193
7180 static Object* Runtime_DateParseString(RUNTIME_CALLING_CONVENTION) { 7194 static Object* Runtime_DateParseString(RUNTIME_CALLING_CONVENTION) {
7181 RUNTIME_GET_ISOLATE; 7195 RUNTIME_GET_ISOLATE;
7182 HandleScope scope; 7196 HandleScope scope(isolate);
7183 ASSERT(args.length() == 2); 7197 ASSERT(args.length() == 2);
7184 7198
7185 CONVERT_ARG_CHECKED(String, str, 0); 7199 CONVERT_ARG_CHECKED(String, str, 0);
7186 FlattenString(str); 7200 FlattenString(str);
7187 7201
7188 CONVERT_ARG_CHECKED(JSArray, output, 1); 7202 CONVERT_ARG_CHECKED(JSArray, output, 1);
7189 RUNTIME_ASSERT(output->HasFastElements()); 7203 RUNTIME_ASSERT(output->HasFastElements());
7190 7204
7191 AssertNoAllocation no_allocation; 7205 AssertNoAllocation no_allocation;
7192 7206
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
7242 RUNTIME_GET_ISOLATE; 7256 RUNTIME_GET_ISOLATE;
7243 ASSERT(args.length() == 1); 7257 ASSERT(args.length() == 1);
7244 Object* global = args[0]; 7258 Object* global = args[0];
7245 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); 7259 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value();
7246 return JSGlobalObject::cast(global)->global_receiver(); 7260 return JSGlobalObject::cast(global)->global_receiver();
7247 } 7261 }
7248 7262
7249 7263
7250 static Object* Runtime_CompileString(RUNTIME_CALLING_CONVENTION) { 7264 static Object* Runtime_CompileString(RUNTIME_CALLING_CONVENTION) {
7251 RUNTIME_GET_ISOLATE; 7265 RUNTIME_GET_ISOLATE;
7252 HandleScope scope; 7266 HandleScope scope(isolate);
7253 ASSERT_EQ(2, args.length()); 7267 ASSERT_EQ(2, args.length());
7254 CONVERT_ARG_CHECKED(String, source, 0); 7268 CONVERT_ARG_CHECKED(String, source, 0);
7255 CONVERT_ARG_CHECKED(Oddball, is_json, 1) 7269 CONVERT_ARG_CHECKED(Oddball, is_json, 1)
7256 7270
7257 // Compile source string in the global context. 7271 // Compile source string in the global context.
7258 Handle<Context> context(isolate->context()->global_context()); 7272 Handle<Context> context(isolate->context()->global_context());
7259 Compiler::ValidationState validate = (is_json->IsTrue()) 7273 Compiler::ValidationState validate = (is_json->IsTrue())
7260 ? Compiler::VALIDATE_JSON : Compiler::DONT_VALIDATE_JSON; 7274 ? Compiler::VALIDATE_JSON : Compiler::DONT_VALIDATE_JSON;
7261 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, 7275 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source,
7262 context, 7276 context,
(...skipping 26 matching lines...) Expand all
7289 7303
7290 7304
7291 static ObjectPair Runtime_ResolvePossiblyDirectEval( 7305 static ObjectPair Runtime_ResolvePossiblyDirectEval(
7292 RUNTIME_CALLING_CONVENTION) { 7306 RUNTIME_CALLING_CONVENTION) {
7293 RUNTIME_GET_ISOLATE; 7307 RUNTIME_GET_ISOLATE;
7294 ASSERT(args.length() == 3); 7308 ASSERT(args.length() == 3);
7295 if (!args[0]->IsJSFunction()) { 7309 if (!args[0]->IsJSFunction()) {
7296 return MakePair(isolate->ThrowIllegalOperation(), NULL); 7310 return MakePair(isolate->ThrowIllegalOperation(), NULL);
7297 } 7311 }
7298 7312
7299 HandleScope scope; 7313 HandleScope scope(isolate);
7300 Handle<JSFunction> callee = args.at<JSFunction>(0); 7314 Handle<JSFunction> callee = args.at<JSFunction>(0);
7301 Handle<Object> receiver; // Will be overwritten. 7315 Handle<Object> receiver; // Will be overwritten.
7302 7316
7303 // Compute the calling context. 7317 // Compute the calling context.
7304 Handle<Context> context = Handle<Context>(isolate->context()); 7318 Handle<Context> context = Handle<Context>(isolate->context());
7305 #ifdef DEBUG 7319 #ifdef DEBUG
7306 // Make sure Isolate::context() agrees with the old code that traversed 7320 // Make sure Isolate::context() agrees with the old code that traversed
7307 // the stack frames to compute the context. 7321 // the stack frames to compute the context.
7308 StackFrameLocator locator; 7322 StackFrameLocator locator;
7309 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 7323 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
(...skipping 24 matching lines...) Expand all
7334 Handle<Object> reference_error = 7348 Handle<Object> reference_error =
7335 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); 7349 Factory::NewReferenceError("not_defined", HandleVector(&name, 1));
7336 return MakePair(isolate->Throw(*reference_error), NULL); 7350 return MakePair(isolate->Throw(*reference_error), NULL);
7337 } 7351 }
7338 7352
7339 if (!context->IsGlobalContext()) { 7353 if (!context->IsGlobalContext()) {
7340 // 'eval' is not bound in the global context. Just call the function 7354 // 'eval' is not bound in the global context. Just call the function
7341 // with the given arguments. This is not necessarily the global eval. 7355 // with the given arguments. This is not necessarily the global eval.
7342 if (receiver->IsContext()) { 7356 if (receiver->IsContext()) {
7343 context = Handle<Context>::cast(receiver); 7357 context = Handle<Context>::cast(receiver);
7344 receiver = Handle<Object>(context->get(index)); 7358 receiver = Handle<Object>(context->get(index), isolate);
7345 } else if (receiver->IsJSContextExtensionObject()) { 7359 } else if (receiver->IsJSContextExtensionObject()) {
7346 receiver = Handle<JSObject>( 7360 receiver = Handle<JSObject>(
7347 isolate->context()->global()->global_receiver()); 7361 isolate->context()->global()->global_receiver());
7348 } 7362 }
7349 return MakePair(*callee, *receiver); 7363 return MakePair(*callee, *receiver);
7350 } 7364 }
7351 7365
7352 // 'eval' is bound in the global context, but it may have been overwritten. 7366 // 'eval' is bound in the global context, but it may have been overwritten.
7353 // Compare it to the builtin 'GlobalEval' function to make sure. 7367 // Compare it to the builtin 'GlobalEval' function to make sure.
7354 if (*callee != isolate->global_context()->global_eval_fun() || 7368 if (*callee != isolate->global_context()->global_eval_fun() ||
7355 !args[1]->IsString()) { 7369 !args[1]->IsString()) {
7356 return MakePair(*callee, 7370 return MakePair(*callee,
7357 isolate->context()->global()->global_receiver()); 7371 isolate->context()->global()->global_receiver());
7358 } 7372 }
7359 7373
7360 return CompileGlobalEval(isolate, args.at<String>(1), args.at<Object>(2)); 7374 return CompileGlobalEval(isolate, args.at<String>(1), args.at<Object>(2));
7361 } 7375 }
7362 7376
7363 7377
7364 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup( 7378 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(
7365 RUNTIME_CALLING_CONVENTION) { 7379 RUNTIME_CALLING_CONVENTION) {
7366 RUNTIME_GET_ISOLATE; 7380 RUNTIME_GET_ISOLATE;
7367 ASSERT(args.length() == 3); 7381 ASSERT(args.length() == 3);
7368 if (!args[0]->IsJSFunction()) { 7382 if (!args[0]->IsJSFunction()) {
7369 return MakePair(isolate->ThrowIllegalOperation(), NULL); 7383 return MakePair(isolate->ThrowIllegalOperation(), NULL);
7370 } 7384 }
7371 7385
7372 HandleScope scope; 7386 HandleScope scope(isolate);
7373 Handle<JSFunction> callee = args.at<JSFunction>(0); 7387 Handle<JSFunction> callee = args.at<JSFunction>(0);
7374 7388
7375 // 'eval' is bound in the global context, but it may have been overwritten. 7389 // 'eval' is bound in the global context, but it may have been overwritten.
7376 // Compare it to the builtin 'GlobalEval' function to make sure. 7390 // Compare it to the builtin 'GlobalEval' function to make sure.
7377 if (*callee != isolate->global_context()->global_eval_fun() || 7391 if (*callee != isolate->global_context()->global_eval_fun() ||
7378 !args[1]->IsString()) { 7392 !args[1]->IsString()) {
7379 return MakePair(*callee, 7393 return MakePair(*callee,
7380 isolate->context()->global()->global_receiver()); 7394 isolate->context()->global()->global_receiver());
7381 } 7395 }
7382 7396
7383 return CompileGlobalEval(isolate, args.at<String>(1), args.at<Object>(2)); 7397 return CompileGlobalEval(isolate, args.at<String>(1), args.at<Object>(2));
7384 } 7398 }
7385 7399
7386 7400
7387 static Object* Runtime_SetNewFunctionAttributes(RUNTIME_CALLING_CONVENTION) { 7401 static Object* Runtime_SetNewFunctionAttributes(RUNTIME_CALLING_CONVENTION) {
7388 RUNTIME_GET_ISOLATE; 7402 RUNTIME_GET_ISOLATE;
7389 // This utility adjusts the property attributes for newly created Function 7403 // This utility adjusts the property attributes for newly created Function
7390 // object ("new Function(...)") by changing the map. 7404 // object ("new Function(...)") by changing the map.
7391 // All it does is changing the prototype property to enumerable 7405 // All it does is changing the prototype property to enumerable
7392 // as specified in ECMA262, 15.3.5.2. 7406 // as specified in ECMA262, 15.3.5.2.
7393 HandleScope scope; 7407 HandleScope scope(isolate);
7394 ASSERT(args.length() == 1); 7408 ASSERT(args.length() == 1);
7395 CONVERT_ARG_CHECKED(JSFunction, func, 0); 7409 CONVERT_ARG_CHECKED(JSFunction, func, 0);
7396 ASSERT(func->map()->instance_type() == 7410 ASSERT(func->map()->instance_type() ==
7397 isolate->function_instance_map()->instance_type()); 7411 isolate->function_instance_map()->instance_type());
7398 ASSERT(func->map()->instance_size() == 7412 ASSERT(func->map()->instance_size() ==
7399 isolate->function_instance_map()->instance_size()); 7413 isolate->function_instance_map()->instance_size());
7400 func->set_map(*isolate->function_instance_map()); 7414 func->set_map(*isolate->function_instance_map());
7401 return *func; 7415 return *func;
7402 } 7416 }
7403 7417
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
7494 // Limit on the accepted indices. Elements with indices larger than the 7508 // Limit on the accepted indices. Elements with indices larger than the
7495 // limit are ignored by the visitor. 7509 // limit are ignored by the visitor.
7496 uint32_t index_limit_; 7510 uint32_t index_limit_;
7497 // Index after last seen index. Always less than or equal to index_limit_. 7511 // Index after last seen index. Always less than or equal to index_limit_.
7498 uint32_t index_offset_; 7512 uint32_t index_offset_;
7499 const bool fast_elements_; 7513 const bool fast_elements_;
7500 }; 7514 };
7501 7515
7502 7516
7503 template<class ExternalArrayClass, class ElementType> 7517 template<class ExternalArrayClass, class ElementType>
7504 static uint32_t IterateExternalArrayElements(Heap* heap, 7518 static uint32_t IterateExternalArrayElements(Isolate* isolate,
7505 Handle<JSObject> receiver, 7519 Handle<JSObject> receiver,
7506 bool elements_are_ints, 7520 bool elements_are_ints,
7507 bool elements_are_guaranteed_smis, 7521 bool elements_are_guaranteed_smis,
7508 uint32_t range, 7522 uint32_t range,
7509 ArrayConcatVisitor* visitor) { 7523 ArrayConcatVisitor* visitor) {
7510 Handle<ExternalArrayClass> array( 7524 Handle<ExternalArrayClass> array(
7511 ExternalArrayClass::cast(receiver->elements())); 7525 ExternalArrayClass::cast(receiver->elements()));
7512 uint32_t len = Min(static_cast<uint32_t>(array->length()), range); 7526 uint32_t len = Min(static_cast<uint32_t>(array->length()), range);
7513 7527
7514 if (visitor != NULL) { 7528 if (visitor != NULL) {
7515 if (elements_are_ints) { 7529 if (elements_are_ints) {
7516 if (elements_are_guaranteed_smis) { 7530 if (elements_are_guaranteed_smis) {
7517 for (uint32_t j = 0; j < len; j++) { 7531 for (uint32_t j = 0; j < len; j++) {
7518 Handle<Smi> e(Smi::FromInt(static_cast<int>(array->get(j)))); 7532 Handle<Smi> e(Smi::FromInt(static_cast<int>(array->get(j))));
7519 visitor->visit(j, e); 7533 visitor->visit(j, e);
7520 } 7534 }
7521 } else { 7535 } else {
7522 for (uint32_t j = 0; j < len; j++) { 7536 for (uint32_t j = 0; j < len; j++) {
7523 int64_t val = static_cast<int64_t>(array->get(j)); 7537 int64_t val = static_cast<int64_t>(array->get(j));
7524 if (Smi::IsValid(static_cast<intptr_t>(val))) { 7538 if (Smi::IsValid(static_cast<intptr_t>(val))) {
7525 Handle<Smi> e(Smi::FromInt(static_cast<int>(val))); 7539 Handle<Smi> e(Smi::FromInt(static_cast<int>(val)));
7526 visitor->visit(j, e); 7540 visitor->visit(j, e);
7527 } else { 7541 } else {
7528 Handle<Object> e( 7542 // TODO(vitalyr): fix this.
7529 heap->AllocateHeapNumber(static_cast<ElementType>(val))); 7543 Handle<Object> e =
7544 Factory::NewNumber(static_cast<ElementType>(val));
7530 visitor->visit(j, e); 7545 visitor->visit(j, e);
7531 } 7546 }
7532 } 7547 }
7533 } 7548 }
7534 } else { 7549 } else {
7535 for (uint32_t j = 0; j < len; j++) { 7550 for (uint32_t j = 0; j < len; j++) {
7536 Handle<Object> e(heap->AllocateHeapNumber(array->get(j))); 7551 Handle<Object> e = Factory::NewNumber(array->get(j));
7537 visitor->visit(j, e); 7552 visitor->visit(j, e);
7538 } 7553 }
7539 } 7554 }
7540 } 7555 }
7541 7556
7542 return len; 7557 return len;
7543 } 7558 }
7544 7559
7545 /** 7560 /**
7546 * A helper function that visits elements of a JSObject. Only elements 7561 * A helper function that visits elements of a JSObject. Only elements
7547 * whose index between 0 and range (exclusive) are visited. 7562 * whose index between 0 and range (exclusive) are visited.
7548 * 7563 *
7549 * If the third parameter, visitor, is not NULL, the visitor is called 7564 * If the third parameter, visitor, is not NULL, the visitor is called
7550 * with parameters, 'visitor_index_offset + element index' and the element. 7565 * with parameters, 'visitor_index_offset + element index' and the element.
7551 * 7566 *
7552 * It returns the number of visisted elements. 7567 * It returns the number of visisted elements.
7553 */ 7568 */
7554 static uint32_t IterateElements(Heap* heap, 7569 static uint32_t IterateElements(Isolate* isolate,
7555 Handle<JSObject> receiver, 7570 Handle<JSObject> receiver,
7556 uint32_t range, 7571 uint32_t range,
7557 ArrayConcatVisitor* visitor) { 7572 ArrayConcatVisitor* visitor) {
7558 uint32_t num_of_elements = 0; 7573 uint32_t num_of_elements = 0;
7559 7574
7560 switch (receiver->GetElementsKind()) { 7575 switch (receiver->GetElementsKind()) {
7561 case JSObject::FAST_ELEMENTS: { 7576 case JSObject::FAST_ELEMENTS: {
7562 Handle<FixedArray> elements(FixedArray::cast(receiver->elements())); 7577 Handle<FixedArray> elements(FixedArray::cast(receiver->elements()));
7563 uint32_t len = elements->length(); 7578 uint32_t len = elements->length();
7564 if (range < len) { 7579 if (range < len) {
7565 len = range; 7580 len = range;
7566 } 7581 }
7567 7582
7568 for (uint32_t j = 0; j < len; j++) { 7583 for (uint32_t j = 0; j < len; j++) {
7569 Handle<Object> e(elements->get(j)); 7584 Handle<Object> e(elements->get(j), isolate);
7570 if (!e->IsTheHole()) { 7585 if (!e->IsTheHole()) {
7571 num_of_elements++; 7586 num_of_elements++;
7572 if (visitor) { 7587 if (visitor) {
7573 visitor->visit(j, e); 7588 visitor->visit(j, e);
7574 } 7589 }
7575 } 7590 }
7576 } 7591 }
7577 break; 7592 break;
7578 } 7593 }
7579 case JSObject::PIXEL_ELEMENTS: { 7594 case JSObject::PIXEL_ELEMENTS: {
7580 Handle<PixelArray> pixels(PixelArray::cast(receiver->elements())); 7595 Handle<PixelArray> pixels(PixelArray::cast(receiver->elements()));
7581 uint32_t len = pixels->length(); 7596 uint32_t len = pixels->length();
7582 if (range < len) { 7597 if (range < len) {
7583 len = range; 7598 len = range;
7584 } 7599 }
7585 7600
7586 for (uint32_t j = 0; j < len; j++) { 7601 for (uint32_t j = 0; j < len; j++) {
7587 num_of_elements++; 7602 num_of_elements++;
7588 if (visitor != NULL) { 7603 if (visitor != NULL) {
7589 Handle<Smi> e(Smi::FromInt(pixels->get(j))); 7604 Handle<Smi> e(Smi::FromInt(pixels->get(j)));
7590 visitor->visit(j, e); 7605 visitor->visit(j, e);
7591 } 7606 }
7592 } 7607 }
7593 break; 7608 break;
7594 } 7609 }
7595 case JSObject::EXTERNAL_BYTE_ELEMENTS: { 7610 case JSObject::EXTERNAL_BYTE_ELEMENTS: {
7596 num_of_elements = 7611 num_of_elements =
7597 IterateExternalArrayElements<ExternalByteArray, int8_t>( 7612 IterateExternalArrayElements<ExternalByteArray, int8_t>(
7598 heap, receiver, true, true, range, visitor); 7613 isolate, receiver, true, true, range, visitor);
7599 break; 7614 break;
7600 } 7615 }
7601 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { 7616 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
7602 num_of_elements = 7617 num_of_elements =
7603 IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>( 7618 IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>(
7604 heap, receiver, true, true, range, visitor); 7619 isolate, receiver, true, true, range, visitor);
7605 break; 7620 break;
7606 } 7621 }
7607 case JSObject::EXTERNAL_SHORT_ELEMENTS: { 7622 case JSObject::EXTERNAL_SHORT_ELEMENTS: {
7608 num_of_elements = 7623 num_of_elements =
7609 IterateExternalArrayElements<ExternalShortArray, int16_t>( 7624 IterateExternalArrayElements<ExternalShortArray, int16_t>(
7610 heap, receiver, true, true, range, visitor); 7625 isolate, receiver, true, true, range, visitor);
7611 break; 7626 break;
7612 } 7627 }
7613 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { 7628 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
7614 num_of_elements = 7629 num_of_elements =
7615 IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>( 7630 IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>(
7616 heap, receiver, true, true, range, visitor); 7631 isolate, receiver, true, true, range, visitor);
7617 break; 7632 break;
7618 } 7633 }
7619 case JSObject::EXTERNAL_INT_ELEMENTS: { 7634 case JSObject::EXTERNAL_INT_ELEMENTS: {
7620 num_of_elements = 7635 num_of_elements =
7621 IterateExternalArrayElements<ExternalIntArray, int32_t>( 7636 IterateExternalArrayElements<ExternalIntArray, int32_t>(
7622 heap, receiver, true, false, range, visitor); 7637 isolate, receiver, true, false, range, visitor);
7623 break; 7638 break;
7624 } 7639 }
7625 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: { 7640 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: {
7626 num_of_elements = 7641 num_of_elements =
7627 IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>( 7642 IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>(
7628 heap, receiver, true, false, range, visitor); 7643 isolate, receiver, true, false, range, visitor);
7629 break; 7644 break;
7630 } 7645 }
7631 case JSObject::EXTERNAL_FLOAT_ELEMENTS: { 7646 case JSObject::EXTERNAL_FLOAT_ELEMENTS: {
7632 num_of_elements = 7647 num_of_elements =
7633 IterateExternalArrayElements<ExternalFloatArray, float>( 7648 IterateExternalArrayElements<ExternalFloatArray, float>(
7634 heap, receiver, false, false, range, visitor); 7649 isolate, receiver, false, false, range, visitor);
7635 break; 7650 break;
7636 } 7651 }
7637 case JSObject::DICTIONARY_ELEMENTS: { 7652 case JSObject::DICTIONARY_ELEMENTS: {
7638 Handle<NumberDictionary> dict(receiver->element_dictionary()); 7653 Handle<NumberDictionary> dict(receiver->element_dictionary());
7639 uint32_t capacity = dict->Capacity(); 7654 uint32_t capacity = dict->Capacity();
7640 for (uint32_t j = 0; j < capacity; j++) { 7655 for (uint32_t j = 0; j < capacity; j++) {
7641 Handle<Object> k(dict->KeyAt(j)); 7656 Handle<Object> k(dict->KeyAt(j), isolate);
7642 if (dict->IsKey(*k)) { 7657 if (dict->IsKey(*k)) {
7643 ASSERT(k->IsNumber()); 7658 ASSERT(k->IsNumber());
7644 uint32_t index = static_cast<uint32_t>(k->Number()); 7659 uint32_t index = static_cast<uint32_t>(k->Number());
7645 if (index < range) { 7660 if (index < range) {
7646 num_of_elements++; 7661 num_of_elements++;
7647 if (visitor) { 7662 if (visitor) {
7648 visitor->visit(index, Handle<Object>(dict->ValueAt(j))); 7663 visitor->visit(index, Handle<Object>(dict->ValueAt(j)));
7649 } 7664 }
7650 } 7665 }
7651 } 7666 }
(...skipping 17 matching lines...) Expand all
7669 * less than Array length are visited. 7684 * less than Array length are visited.
7670 * 7685 *
7671 * If a ArrayConcatVisitor object is given, the visitor is called with 7686 * If a ArrayConcatVisitor object is given, the visitor is called with
7672 * parameters, element's index + visitor_index_offset and the element. 7687 * parameters, element's index + visitor_index_offset and the element.
7673 * 7688 *
7674 * The returned number of elements is an upper bound on the actual number 7689 * The returned number of elements is an upper bound on the actual number
7675 * of elements added. If the same element occurs in more than one object 7690 * of elements added. If the same element occurs in more than one object
7676 * in the array's prototype chain, it will be counted more than once, but 7691 * in the array's prototype chain, it will be counted more than once, but
7677 * will only occur once in the result. 7692 * will only occur once in the result.
7678 */ 7693 */
7679 static uint32_t IterateArrayAndPrototypeElements(Heap* heap, 7694 static uint32_t IterateArrayAndPrototypeElements(Isolate* isolate,
7680 Handle<JSArray> array, 7695 Handle<JSArray> array,
7681 ArrayConcatVisitor* visitor) { 7696 ArrayConcatVisitor* visitor) {
7682 uint32_t range = static_cast<uint32_t>(array->length()->Number()); 7697 uint32_t range = static_cast<uint32_t>(array->length()->Number());
7683 Handle<Object> obj = array; 7698 Handle<Object> obj = array;
7684 7699
7685 static const int kEstimatedPrototypes = 3; 7700 static const int kEstimatedPrototypes = 3;
7686 List< Handle<JSObject> > objects(kEstimatedPrototypes); 7701 List< Handle<JSObject> > objects(kEstimatedPrototypes);
7687 7702
7688 // Visit prototype first. If an element on the prototype is shadowed by 7703 // Visit prototype first. If an element on the prototype is shadowed by
7689 // the inheritor using the same index, the ArrayConcatVisitor visits 7704 // the inheritor using the same index, the ArrayConcatVisitor visits
7690 // the prototype element before the shadowing element. 7705 // the prototype element before the shadowing element.
7691 // The visitor can simply overwrite the old value by new value using 7706 // The visitor can simply overwrite the old value by new value using
7692 // the same index. This follows Array::concat semantics. 7707 // the same index. This follows Array::concat semantics.
7693 while (!obj->IsNull()) { 7708 while (!obj->IsNull()) {
7694 objects.Add(Handle<JSObject>::cast(obj)); 7709 objects.Add(Handle<JSObject>::cast(obj));
7695 obj = Handle<Object>(obj->GetPrototype()); 7710 obj = Handle<Object>(obj->GetPrototype(), isolate);
7696 } 7711 }
7697 7712
7698 uint32_t nof_elements = 0; 7713 uint32_t nof_elements = 0;
7699 for (int i = objects.length() - 1; i >= 0; i--) { 7714 for (int i = objects.length() - 1; i >= 0; i--) {
7700 Handle<JSObject> obj = objects[i]; 7715 Handle<JSObject> obj = objects[i];
7701 uint32_t encountered_elements = 7716 uint32_t encountered_elements =
7702 IterateElements(heap, Handle<JSObject>::cast(obj), range, visitor); 7717 IterateElements(isolate, Handle<JSObject>::cast(obj), range, visitor);
7703 7718
7704 if (encountered_elements > JSObject::kMaxElementCount - nof_elements) { 7719 if (encountered_elements > JSObject::kMaxElementCount - nof_elements) {
7705 nof_elements = JSObject::kMaxElementCount; 7720 nof_elements = JSObject::kMaxElementCount;
7706 } else { 7721 } else {
7707 nof_elements += encountered_elements; 7722 nof_elements += encountered_elements;
7708 } 7723 }
7709 } 7724 }
7710 7725
7711 return nof_elements; 7726 return nof_elements;
7712 } 7727 }
7713 7728
7714 7729
7715 /** 7730 /**
7716 * A helper function of Runtime_ArrayConcat. 7731 * A helper function of Runtime_ArrayConcat.
7717 * 7732 *
7718 * The first argument is an Array of arrays and objects. It is the 7733 * The first argument is an Array of arrays and objects. It is the
7719 * same as the arguments array of Array::concat JS function. 7734 * same as the arguments array of Array::concat JS function.
7720 * 7735 *
7721 * If an argument is an Array object, the function visits array 7736 * If an argument is an Array object, the function visits array
7722 * elements. If an argument is not an Array object, the function 7737 * elements. If an argument is not an Array object, the function
7723 * visits the object as if it is an one-element array. 7738 * visits the object as if it is an one-element array.
7724 * 7739 *
7725 * If the result array index overflows 32-bit unsigned integer, the rounded 7740 * If the result array index overflows 32-bit unsigned integer, the rounded
7726 * non-negative number is used as new length. For example, if one 7741 * non-negative number is used as new length. For example, if one
7727 * array length is 2^32 - 1, second array length is 1, the 7742 * array length is 2^32 - 1, second array length is 1, the
7728 * concatenated array length is 0. 7743 * concatenated array length is 0.
7729 * TODO(lrn) Change length behavior to ECMAScript 5 specification (length 7744 * TODO(lrn) Change length behavior to ECMAScript 5 specification (length
7730 * is one more than the last array index to get a value assigned). 7745 * is one more than the last array index to get a value assigned).
7731 */ 7746 */
7732 static uint32_t IterateArguments(Heap* heap, 7747 static uint32_t IterateArguments(Isolate* isolate,
7733 Handle<JSArray> arguments, 7748 Handle<JSArray> arguments,
7734 ArrayConcatVisitor* visitor) { 7749 ArrayConcatVisitor* visitor) {
7735 uint32_t visited_elements = 0; 7750 uint32_t visited_elements = 0;
7736 uint32_t num_of_args = static_cast<uint32_t>(arguments->length()->Number()); 7751 uint32_t num_of_args = static_cast<uint32_t>(arguments->length()->Number());
7737 7752
7738 for (uint32_t i = 0; i < num_of_args; i++) { 7753 for (uint32_t i = 0; i < num_of_args; i++) {
7739 Handle<Object> obj(arguments->GetElement(i)); 7754 Handle<Object> obj(arguments->GetElement(i), isolate);
7740 if (obj->IsJSArray()) { 7755 if (obj->IsJSArray()) {
7741 Handle<JSArray> array = Handle<JSArray>::cast(obj); 7756 Handle<JSArray> array = Handle<JSArray>::cast(obj);
7742 uint32_t len = static_cast<uint32_t>(array->length()->Number()); 7757 uint32_t len = static_cast<uint32_t>(array->length()->Number());
7743 uint32_t nof_elements = 7758 uint32_t nof_elements =
7744 IterateArrayAndPrototypeElements(heap, array, visitor); 7759 IterateArrayAndPrototypeElements(isolate, array, visitor);
7745 // Total elements of array and its prototype chain can be more than 7760 // Total elements of array and its prototype chain can be more than
7746 // the array length, but ArrayConcat can only concatenate at most 7761 // the array length, but ArrayConcat can only concatenate at most
7747 // the array length number of elements. We use the length as an estimate 7762 // the array length number of elements. We use the length as an estimate
7748 // for the actual number of elements added. 7763 // for the actual number of elements added.
7749 uint32_t added_elements = (nof_elements > len) ? len : nof_elements; 7764 uint32_t added_elements = (nof_elements > len) ? len : nof_elements;
7750 if (JSArray::kMaxElementCount - visited_elements < added_elements) { 7765 if (JSArray::kMaxElementCount - visited_elements < added_elements) {
7751 visited_elements = JSArray::kMaxElementCount; 7766 visited_elements = JSArray::kMaxElementCount;
7752 } else { 7767 } else {
7753 visited_elements += added_elements; 7768 visited_elements += added_elements;
7754 } 7769 }
(...skipping 14 matching lines...) Expand all
7769 7784
7770 /** 7785 /**
7771 * Array::concat implementation. 7786 * Array::concat implementation.
7772 * See ECMAScript 262, 15.4.4.4. 7787 * See ECMAScript 262, 15.4.4.4.
7773 * TODO(lrn): Fix non-compliance for very large concatenations and update to 7788 * TODO(lrn): Fix non-compliance for very large concatenations and update to
7774 * following the ECMAScript 5 specification. 7789 * following the ECMAScript 5 specification.
7775 */ 7790 */
7776 static Object* Runtime_ArrayConcat(RUNTIME_CALLING_CONVENTION) { 7791 static Object* Runtime_ArrayConcat(RUNTIME_CALLING_CONVENTION) {
7777 RUNTIME_GET_ISOLATE; 7792 RUNTIME_GET_ISOLATE;
7778 ASSERT(args.length() == 1); 7793 ASSERT(args.length() == 1);
7779 HandleScope handle_scope; 7794 HandleScope handle_scope(isolate);
7780 7795
7781 CONVERT_CHECKED(JSArray, arg_arrays, args[0]); 7796 CONVERT_CHECKED(JSArray, arg_arrays, args[0]);
7782 Handle<JSArray> arguments(arg_arrays); 7797 Handle<JSArray> arguments(arg_arrays);
7783 7798
7784 // Pass 1: estimate the number of elements of the result 7799 // Pass 1: estimate the number of elements of the result
7785 // (it could be more than real numbers if prototype has elements). 7800 // (it could be more than real numbers if prototype has elements).
7786 uint32_t result_length = 0; 7801 uint32_t result_length = 0;
7787 uint32_t num_of_args = static_cast<uint32_t>(arguments->length()->Number()); 7802 uint32_t num_of_args = static_cast<uint32_t>(arguments->length()->Number());
7788 7803
7789 { AssertNoAllocation nogc; 7804 { AssertNoAllocation nogc;
(...skipping 10 matching lines...) Expand all
7800 result_length = JSObject::kMaxElementCount; 7815 result_length = JSObject::kMaxElementCount;
7801 break; 7816 break;
7802 } 7817 }
7803 result_length += length_estimate; 7818 result_length += length_estimate;
7804 } 7819 }
7805 } 7820 }
7806 7821
7807 // Allocate an empty array, will set length and content later. 7822 // Allocate an empty array, will set length and content later.
7808 Handle<JSArray> result = Factory::NewJSArray(0); 7823 Handle<JSArray> result = Factory::NewJSArray(0);
7809 7824
7810 uint32_t estimate_nof_elements = 7825 uint32_t estimate_nof_elements = IterateArguments(isolate, arguments, NULL);
7811 IterateArguments(isolate->heap(), arguments, NULL);
7812 // If estimated number of elements is more than half of length, a 7826 // If estimated number of elements is more than half of length, a
7813 // fixed array (fast case) is more time and space-efficient than a 7827 // fixed array (fast case) is more time and space-efficient than a
7814 // dictionary. 7828 // dictionary.
7815 bool fast_case = (estimate_nof_elements * 2) >= result_length; 7829 bool fast_case = (estimate_nof_elements * 2) >= result_length;
7816 7830
7817 Handle<FixedArray> storage; 7831 Handle<FixedArray> storage;
7818 if (fast_case) { 7832 if (fast_case) {
7819 // The backing storage array must have non-existing elements to 7833 // The backing storage array must have non-existing elements to
7820 // preserve holes across concat operations. 7834 // preserve holes across concat operations.
7821 storage = Factory::NewFixedArrayWithHoles(result_length); 7835 storage = Factory::NewFixedArrayWithHoles(result_length);
7822 result->set_map(*Factory::GetFastElementsMap(Handle<Map>(result->map()))); 7836 result->set_map(*Factory::GetFastElementsMap(Handle<Map>(result->map())));
7823 } else { 7837 } else {
7824 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate 7838 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate
7825 uint32_t at_least_space_for = estimate_nof_elements + 7839 uint32_t at_least_space_for = estimate_nof_elements +
7826 (estimate_nof_elements >> 2); 7840 (estimate_nof_elements >> 2);
7827 storage = Handle<FixedArray>::cast( 7841 storage = Handle<FixedArray>::cast(
7828 Factory::NewNumberDictionary(at_least_space_for)); 7842 Factory::NewNumberDictionary(at_least_space_for));
7829 result->set_map(*Factory::GetSlowElementsMap(Handle<Map>(result->map()))); 7843 result->set_map(*Factory::GetSlowElementsMap(Handle<Map>(result->map())));
7830 } 7844 }
7831 7845
7832 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length)); 7846 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length));
7833 7847
7834 ArrayConcatVisitor visitor(storage, result_length, fast_case); 7848 ArrayConcatVisitor visitor(storage, result_length, fast_case);
7835 7849
7836 IterateArguments(isolate->heap(), arguments, &visitor); 7850 IterateArguments(isolate, arguments, &visitor);
7837 7851
7838 result->set_length(*len); 7852 result->set_length(*len);
7839 // Please note the storage might have changed in the visitor. 7853 // Please note the storage might have changed in the visitor.
7840 result->set_elements(*visitor.storage()); 7854 result->set_elements(*visitor.storage());
7841 7855
7842 return *result; 7856 return *result;
7843 } 7857 }
7844 7858
7845 7859
7846 // This will not allocate (flatten the string), but it may run 7860 // This will not allocate (flatten the string), but it may run
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
7909 } else if (object->IsJSArray()) { 7923 } else if (object->IsJSArray()) {
7910 return JSArray::cast(object)->length(); 7924 return JSArray::cast(object)->length();
7911 } else { 7925 } else {
7912 return Smi::FromInt(FixedArray::cast(elements)->length()); 7926 return Smi::FromInt(FixedArray::cast(elements)->length());
7913 } 7927 }
7914 } 7928 }
7915 7929
7916 7930
7917 static Object* Runtime_SwapElements(RUNTIME_CALLING_CONVENTION) { 7931 static Object* Runtime_SwapElements(RUNTIME_CALLING_CONVENTION) {
7918 RUNTIME_GET_ISOLATE; 7932 RUNTIME_GET_ISOLATE;
7919 HandleScope handle_scope; 7933 HandleScope handle_scope(isolate);
7920 7934
7921 ASSERT_EQ(3, args.length()); 7935 ASSERT_EQ(3, args.length());
7922 7936
7923 CONVERT_ARG_CHECKED(JSObject, object, 0); 7937 CONVERT_ARG_CHECKED(JSObject, object, 0);
7924 Handle<Object> key1 = args.at<Object>(1); 7938 Handle<Object> key1 = args.at<Object>(1);
7925 Handle<Object> key2 = args.at<Object>(2); 7939 Handle<Object> key2 = args.at<Object>(2);
7926 7940
7927 uint32_t index1, index2; 7941 uint32_t index1, index2;
7928 if (!key1->ToArrayIndex(&index1) 7942 if (!key1->ToArrayIndex(&index1)
7929 || !key2->ToArrayIndex(&index2)) { 7943 || !key2->ToArrayIndex(&index2)) {
(...skipping 12 matching lines...) Expand all
7942 7956
7943 7957
7944 // Returns an array that tells you where in the [0, length) interval an array 7958 // Returns an array that tells you where in the [0, length) interval an array
7945 // might have elements. Can either return keys (positive integers) or 7959 // might have elements. Can either return keys (positive integers) or
7946 // intervals (pair of a negative integer (-start-1) followed by a 7960 // intervals (pair of a negative integer (-start-1) followed by a
7947 // positive (length)) or undefined values. 7961 // positive (length)) or undefined values.
7948 // Intervals can span over some keys that are not in the object. 7962 // Intervals can span over some keys that are not in the object.
7949 static Object* Runtime_GetArrayKeys(RUNTIME_CALLING_CONVENTION) { 7963 static Object* Runtime_GetArrayKeys(RUNTIME_CALLING_CONVENTION) {
7950 RUNTIME_GET_ISOLATE; 7964 RUNTIME_GET_ISOLATE;
7951 ASSERT(args.length() == 2); 7965 ASSERT(args.length() == 2);
7952 HandleScope scope; 7966 HandleScope scope(isolate);
7953 CONVERT_ARG_CHECKED(JSObject, array, 0); 7967 CONVERT_ARG_CHECKED(JSObject, array, 0);
7954 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); 7968 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]);
7955 if (array->elements()->IsDictionary()) { 7969 if (array->elements()->IsDictionary()) {
7956 // Create an array and get all the keys into it, then remove all the 7970 // Create an array and get all the keys into it, then remove all the
7957 // keys that are not integers in the range 0 to length-1. 7971 // keys that are not integers in the range 0 to length-1.
7958 Handle<FixedArray> keys = GetKeysInFixedArrayFor(array, INCLUDE_PROTOS); 7972 Handle<FixedArray> keys = GetKeysInFixedArrayFor(array, INCLUDE_PROTOS);
7959 int keys_length = keys->length(); 7973 int keys_length = keys->length();
7960 for (int i = 0; i < keys_length; i++) { 7974 for (int i = 0; i < keys_length; i++) {
7961 Object* key = keys->get(i); 7975 Object* key = keys->get(i);
7962 uint32_t index; 7976 uint32_t index;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
8124 // The array returned contains the following information: 8138 // The array returned contains the following information:
8125 // 0: Property value 8139 // 0: Property value
8126 // 1: Property details 8140 // 1: Property details
8127 // 2: Property value is exception 8141 // 2: Property value is exception
8128 // 3: Getter function if defined 8142 // 3: Getter function if defined
8129 // 4: Setter function if defined 8143 // 4: Setter function if defined
8130 // Items 2-4 are only filled if the property has either a getter or a setter 8144 // Items 2-4 are only filled if the property has either a getter or a setter
8131 // defined through __defineGetter__ and/or __defineSetter__. 8145 // defined through __defineGetter__ and/or __defineSetter__.
8132 static Object* Runtime_DebugGetPropertyDetails(RUNTIME_CALLING_CONVENTION) { 8146 static Object* Runtime_DebugGetPropertyDetails(RUNTIME_CALLING_CONVENTION) {
8133 RUNTIME_GET_ISOLATE; 8147 RUNTIME_GET_ISOLATE;
8134 HandleScope scope; 8148 HandleScope scope(isolate);
8135 8149
8136 ASSERT(args.length() == 2); 8150 ASSERT(args.length() == 2);
8137 8151
8138 CONVERT_ARG_CHECKED(JSObject, obj, 0); 8152 CONVERT_ARG_CHECKED(JSObject, obj, 0);
8139 CONVERT_ARG_CHECKED(String, name, 1); 8153 CONVERT_ARG_CHECKED(String, name, 1);
8140 8154
8141 // Make sure to set the current context to the context before the debugger was 8155 // Make sure to set the current context to the context before the debugger was
8142 // entered (if the debugger is entered). The reason for switching context here 8156 // entered (if the debugger is entered). The reason for switching context here
8143 // is that for some property lookups (accessors and interceptors) callbacks 8157 // is that for some property lookups (accessors and interceptors) callbacks
8144 // into the embedding application can occour, and the embedding application 8158 // into the embedding application can occour, and the embedding application
8145 // could have the assumption that its own global context is the current 8159 // could have the assumption that its own global context is the current
8146 // context and not some internal debugger context. 8160 // context and not some internal debugger context.
8147 SaveContext save; 8161 SaveContext save;
8148 if (isolate->debug()->InDebugger()) { 8162 if (isolate->debug()->InDebugger()) {
8149 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext()); 8163 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext());
8150 } 8164 }
8151 8165
8152 // Skip the global proxy as it has no properties and always delegates to the 8166 // Skip the global proxy as it has no properties and always delegates to the
8153 // real global object. 8167 // real global object.
8154 if (obj->IsJSGlobalProxy()) { 8168 if (obj->IsJSGlobalProxy()) {
8155 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); 8169 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
8156 } 8170 }
8157 8171
8158 8172
8159 // Check if the name is trivially convertible to an index and get the element 8173 // Check if the name is trivially convertible to an index and get the element
8160 // if so. 8174 // if so.
8161 uint32_t index; 8175 uint32_t index;
8162 if (name->AsArrayIndex(&index)) { 8176 if (name->AsArrayIndex(&index)) {
8163 Handle<FixedArray> details = Factory::NewFixedArray(2); 8177 Handle<FixedArray> details = Factory::NewFixedArray(2);
8164 Object* element_or_char = Runtime::GetElementOrCharAt(isolate->heap(), 8178 Object* element_or_char = Runtime::GetElementOrCharAt(isolate,
8165 obj, 8179 obj,
8166 index); 8180 index);
8167 details->set(0, element_or_char); 8181 details->set(0, element_or_char);
8168 details->set(1, PropertyDetails(NONE, NORMAL).AsSmi()); 8182 details->set(1, PropertyDetails(NONE, NORMAL).AsSmi());
8169 return *Factory::NewJSArrayWithElements(details); 8183 return *Factory::NewJSArrayWithElements(details);
8170 } 8184 }
8171 8185
8172 // Find the number of objects making up this. 8186 // Find the number of objects making up this.
8173 int length = LocalPrototypeChainLength(*obj); 8187 int length = LocalPrototypeChainLength(*obj);
8174 8188
8175 // Try local lookup on each of the objects. 8189 // Try local lookup on each of the objects.
8176 Handle<JSObject> jsproto = obj; 8190 Handle<JSObject> jsproto = obj;
8177 for (int i = 0; i < length; i++) { 8191 for (int i = 0; i < length; i++) {
8178 LookupResult result; 8192 LookupResult result;
8179 jsproto->LocalLookup(*name, &result); 8193 jsproto->LocalLookup(*name, &result);
8180 if (result.IsProperty()) { 8194 if (result.IsProperty()) {
8181 // LookupResult is not GC safe as it holds raw object pointers. 8195 // LookupResult is not GC safe as it holds raw object pointers.
8182 // GC can happen later in this code so put the required fields into 8196 // GC can happen later in this code so put the required fields into
8183 // local variables using handles when required for later use. 8197 // local variables using handles when required for later use.
8184 PropertyType result_type = result.type(); 8198 PropertyType result_type = result.type();
8185 Handle<Object> result_callback_obj; 8199 Handle<Object> result_callback_obj;
8186 if (result_type == CALLBACKS) { 8200 if (result_type == CALLBACKS) {
8187 result_callback_obj = Handle<Object>(result.GetCallbackObject()); 8201 result_callback_obj = Handle<Object>(result.GetCallbackObject(),
8202 isolate);
8188 } 8203 }
8189 Smi* property_details = result.GetPropertyDetails().AsSmi(); 8204 Smi* property_details = result.GetPropertyDetails().AsSmi();
8190 // DebugLookupResultValue can cause GC so details from LookupResult needs 8205 // DebugLookupResultValue can cause GC so details from LookupResult needs
8191 // to be copied to handles before this. 8206 // to be copied to handles before this.
8192 bool caught_exception = false; 8207 bool caught_exception = false;
8193 Object* raw_value = DebugLookupResultValue(isolate->heap(), *obj, *name, 8208 Object* raw_value = DebugLookupResultValue(isolate->heap(), *obj, *name,
8194 &result, &caught_exception); 8209 &result, &caught_exception);
8195 if (raw_value->IsFailure()) return raw_value; 8210 if (raw_value->IsFailure()) return raw_value;
8196 Handle<Object> value(raw_value); 8211 Handle<Object> value(raw_value, isolate);
8197 8212
8198 // If the callback object is a fixed array then it contains JavaScript 8213 // If the callback object is a fixed array then it contains JavaScript
8199 // getter and/or setter. 8214 // getter and/or setter.
8200 bool hasJavaScriptAccessors = result_type == CALLBACKS && 8215 bool hasJavaScriptAccessors = result_type == CALLBACKS &&
8201 result_callback_obj->IsFixedArray(); 8216 result_callback_obj->IsFixedArray();
8202 Handle<FixedArray> details = 8217 Handle<FixedArray> details =
8203 Factory::NewFixedArray(hasJavaScriptAccessors ? 5 : 2); 8218 Factory::NewFixedArray(hasJavaScriptAccessors ? 5 : 2);
8204 details->set(0, *value); 8219 details->set(0, *value);
8205 details->set(1, property_details); 8220 details->set(1, property_details);
8206 if (hasJavaScriptAccessors) { 8221 if (hasJavaScriptAccessors) {
(...skipping 10 matching lines...) Expand all
8217 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); 8232 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
8218 } 8233 }
8219 } 8234 }
8220 8235
8221 return isolate->heap()->undefined_value(); 8236 return isolate->heap()->undefined_value();
8222 } 8237 }
8223 8238
8224 8239
8225 static Object* Runtime_DebugGetProperty(RUNTIME_CALLING_CONVENTION) { 8240 static Object* Runtime_DebugGetProperty(RUNTIME_CALLING_CONVENTION) {
8226 RUNTIME_GET_ISOLATE; 8241 RUNTIME_GET_ISOLATE;
8227 HandleScope scope; 8242 HandleScope scope(isolate);
8228 8243
8229 ASSERT(args.length() == 2); 8244 ASSERT(args.length() == 2);
8230 8245
8231 CONVERT_ARG_CHECKED(JSObject, obj, 0); 8246 CONVERT_ARG_CHECKED(JSObject, obj, 0);
8232 CONVERT_ARG_CHECKED(String, name, 1); 8247 CONVERT_ARG_CHECKED(String, name, 1);
8233 8248
8234 LookupResult result; 8249 LookupResult result;
8235 obj->Lookup(*name, &result); 8250 obj->Lookup(*name, &result);
8236 if (result.IsProperty()) { 8251 if (result.IsProperty()) {
8237 return DebugLookupResultValue(isolate->heap(), *obj, *name, &result, NULL); 8252 return DebugLookupResultValue(isolate->heap(), *obj, *name, &result, NULL);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8275 return Smi::FromInt(index); 8290 return Smi::FromInt(index);
8276 } 8291 }
8277 8292
8278 8293
8279 // Return property value from named interceptor. 8294 // Return property value from named interceptor.
8280 // args[0]: object 8295 // args[0]: object
8281 // args[1]: property name 8296 // args[1]: property name
8282 static Object* Runtime_DebugNamedInterceptorPropertyValue( 8297 static Object* Runtime_DebugNamedInterceptorPropertyValue(
8283 RUNTIME_CALLING_CONVENTION) { 8298 RUNTIME_CALLING_CONVENTION) {
8284 RUNTIME_GET_ISOLATE; 8299 RUNTIME_GET_ISOLATE;
8285 HandleScope scope; 8300 HandleScope scope(isolate);
8286 ASSERT(args.length() == 2); 8301 ASSERT(args.length() == 2);
8287 CONVERT_ARG_CHECKED(JSObject, obj, 0); 8302 CONVERT_ARG_CHECKED(JSObject, obj, 0);
8288 RUNTIME_ASSERT(obj->HasNamedInterceptor()); 8303 RUNTIME_ASSERT(obj->HasNamedInterceptor());
8289 CONVERT_ARG_CHECKED(String, name, 1); 8304 CONVERT_ARG_CHECKED(String, name, 1);
8290 8305
8291 PropertyAttributes attributes; 8306 PropertyAttributes attributes;
8292 return obj->GetPropertyWithInterceptor(*obj, *name, &attributes); 8307 return obj->GetPropertyWithInterceptor(*obj, *name, &attributes);
8293 } 8308 }
8294 8309
8295 8310
8296 // Return element value from indexed interceptor. 8311 // Return element value from indexed interceptor.
8297 // args[0]: object 8312 // args[0]: object
8298 // args[1]: index 8313 // args[1]: index
8299 static Object* Runtime_DebugIndexedInterceptorElementValue( 8314 static Object* Runtime_DebugIndexedInterceptorElementValue(
8300 RUNTIME_CALLING_CONVENTION) { 8315 RUNTIME_CALLING_CONVENTION) {
8301 RUNTIME_GET_ISOLATE; 8316 RUNTIME_GET_ISOLATE;
8302 HandleScope scope; 8317 HandleScope scope(isolate);
8303 ASSERT(args.length() == 2); 8318 ASSERT(args.length() == 2);
8304 CONVERT_ARG_CHECKED(JSObject, obj, 0); 8319 CONVERT_ARG_CHECKED(JSObject, obj, 0);
8305 RUNTIME_ASSERT(obj->HasIndexedInterceptor()); 8320 RUNTIME_ASSERT(obj->HasIndexedInterceptor());
8306 CONVERT_NUMBER_CHECKED(uint32_t, index, Uint32, args[1]); 8321 CONVERT_NUMBER_CHECKED(uint32_t, index, Uint32, args[1]);
8307 8322
8308 return obj->GetElementWithInterceptor(*obj, index); 8323 return obj->GetElementWithInterceptor(*obj, index);
8309 } 8324 }
8310 8325
8311 8326
8312 static Object* Runtime_CheckExecutionState(RUNTIME_CALLING_CONVENTION) { 8327 static Object* Runtime_CheckExecutionState(RUNTIME_CALLING_CONVENTION) {
8313 RUNTIME_GET_ISOLATE; 8328 RUNTIME_GET_ISOLATE;
8314 ASSERT(args.length() >= 1); 8329 ASSERT(args.length() >= 1);
8315 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]); 8330 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]);
8316 // Check that the break id is valid. 8331 // Check that the break id is valid.
8317 if (isolate->debug()->break_id() == 0 || 8332 if (isolate->debug()->break_id() == 0 ||
8318 break_id != isolate->debug()->break_id()) { 8333 break_id != isolate->debug()->break_id()) {
8319 return isolate->Throw( 8334 return isolate->Throw(
8320 isolate->heap()->illegal_execution_state_symbol()); 8335 isolate->heap()->illegal_execution_state_symbol());
8321 } 8336 }
8322 8337
8323 return isolate->heap()->true_value(); 8338 return isolate->heap()->true_value();
8324 } 8339 }
8325 8340
8326 8341
8327 static Object* Runtime_GetFrameCount(RUNTIME_CALLING_CONVENTION) { 8342 static Object* Runtime_GetFrameCount(RUNTIME_CALLING_CONVENTION) {
8328 RUNTIME_GET_ISOLATE; 8343 RUNTIME_GET_ISOLATE;
8329 HandleScope scope; 8344 HandleScope scope(isolate);
8330 ASSERT(args.length() == 1); 8345 ASSERT(args.length() == 1);
8331 8346
8332 // Check arguments. 8347 // Check arguments.
8333 Object* result = Runtime_CheckExecutionState(args, isolate); 8348 Object* result = Runtime_CheckExecutionState(args, isolate);
8334 if (result->IsFailure()) return result; 8349 if (result->IsFailure()) return result;
8335 8350
8336 // Count all frames which are relevant to debugging stack trace. 8351 // Count all frames which are relevant to debugging stack trace.
8337 int n = 0; 8352 int n = 0;
8338 StackFrame::Id id = isolate->debug()->break_frame_id(); 8353 StackFrame::Id id = isolate->debug()->break_frame_id();
8339 if (id == StackFrame::NO_ID) { 8354 if (id == StackFrame::NO_ID) {
(...skipping 28 matching lines...) Expand all
8368 // 4: Local count 8383 // 4: Local count
8369 // 5: Source position 8384 // 5: Source position
8370 // 6: Constructor call 8385 // 6: Constructor call
8371 // 7: Is at return 8386 // 7: Is at return
8372 // 8: Debugger frame 8387 // 8: Debugger frame
8373 // Arguments name, value 8388 // Arguments name, value
8374 // Locals name, value 8389 // Locals name, value
8375 // Return value if any 8390 // Return value if any
8376 static Object* Runtime_GetFrameDetails(RUNTIME_CALLING_CONVENTION) { 8391 static Object* Runtime_GetFrameDetails(RUNTIME_CALLING_CONVENTION) {
8377 RUNTIME_GET_ISOLATE; 8392 RUNTIME_GET_ISOLATE;
8378 HandleScope scope; 8393 HandleScope scope(isolate);
8379 ASSERT(args.length() == 2); 8394 ASSERT(args.length() == 2);
8380 8395
8381 // Check arguments. 8396 // Check arguments.
8382 Object* check = Runtime_CheckExecutionState(args, isolate); 8397 Object* check = Runtime_CheckExecutionState(args, isolate);
8383 if (check->IsFailure()) return check; 8398 if (check->IsFailure()) return check;
8384 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); 8399 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
8385 Heap* heap = isolate->heap(); 8400 Heap* heap = isolate->heap();
8386 8401
8387 // Find the relevant frame with the requested index. 8402 // Find the relevant frame with the requested index.
8388 StackFrame::Id id = isolate->debug()->break_frame_id(); 8403 StackFrame::Id id = isolate->debug()->break_frame_id();
(...skipping 11 matching lines...) Expand all
8400 8415
8401 // Traverse the saved contexts chain to find the active context for the 8416 // Traverse the saved contexts chain to find the active context for the
8402 // selected frame. 8417 // selected frame.
8403 SaveContext* save = isolate->save_context(); 8418 SaveContext* save = isolate->save_context();
8404 while (save != NULL && !save->below(it.frame())) { 8419 while (save != NULL && !save->below(it.frame())) {
8405 save = save->prev(); 8420 save = save->prev();
8406 } 8421 }
8407 ASSERT(save != NULL); 8422 ASSERT(save != NULL);
8408 8423
8409 // Get the frame id. 8424 // Get the frame id.
8410 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); 8425 Handle<Object> frame_id(WrapFrameId(it.frame()->id()), isolate);
8411 8426
8412 // Find source position. 8427 // Find source position.
8413 int position = it.frame()->code()->SourcePosition(it.frame()->pc()); 8428 int position = it.frame()->code()->SourcePosition(it.frame()->pc());
8414 8429
8415 // Check for constructor frame. 8430 // Check for constructor frame.
8416 bool constructor = it.frame()->IsConstructor(); 8431 bool constructor = it.frame()->IsConstructor();
8417 8432
8418 // Get scope info and read from it for local variable information. 8433 // Get scope info and read from it for local variable information.
8419 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); 8434 Handle<JSFunction> function(JSFunction::cast(it.frame()->function()));
8420 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); 8435 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
8465 internal_frame_sp = it2.frame()->sp(); 8480 internal_frame_sp = it2.frame()->sp();
8466 } else { 8481 } else {
8467 if (it2.frame()->is_java_script()) { 8482 if (it2.frame()->is_java_script()) {
8468 if (it2.frame()->id() == it.frame()->id()) { 8483 if (it2.frame()->id() == it.frame()->id()) {
8469 // The internal frame just before the JavaScript frame contains the 8484 // The internal frame just before the JavaScript frame contains the
8470 // value to return on top. A debug break at return will create an 8485 // value to return on top. A debug break at return will create an
8471 // internal frame to store the return value (eax/rax/r0) before 8486 // internal frame to store the return value (eax/rax/r0) before
8472 // entering the debug break exit frame. 8487 // entering the debug break exit frame.
8473 if (internal_frame_sp != NULL) { 8488 if (internal_frame_sp != NULL) {
8474 return_value = 8489 return_value =
8475 Handle<Object>(Memory::Object_at(internal_frame_sp)); 8490 Handle<Object>(Memory::Object_at(internal_frame_sp),
8491 isolate);
8476 break; 8492 break;
8477 } 8493 }
8478 } 8494 }
8479 } 8495 }
8480 8496
8481 // Indicate that the previous frame was not an internal frame. 8497 // Indicate that the previous frame was not an internal frame.
8482 internal_frame_sp = NULL; 8498 internal_frame_sp = NULL;
8483 } 8499 }
8484 it2.Advance(); 8500 it2.Advance();
8485 } 8501 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
8561 } 8577 }
8562 8578
8563 // Add the value being returned. 8579 // Add the value being returned.
8564 if (at_return) { 8580 if (at_return) {
8565 details->set(details_index++, *return_value); 8581 details->set(details_index++, *return_value);
8566 } 8582 }
8567 8583
8568 // Add the receiver (same as in function frame). 8584 // Add the receiver (same as in function frame).
8569 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE 8585 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE
8570 // THE FRAME ITERATOR TO WRAP THE RECEIVER. 8586 // THE FRAME ITERATOR TO WRAP THE RECEIVER.
8571 Handle<Object> receiver(it.frame()->receiver()); 8587 Handle<Object> receiver(it.frame()->receiver(), isolate);
8572 if (!receiver->IsJSObject()) { 8588 if (!receiver->IsJSObject()) {
8573 // If the receiver is NOT a JSObject we have hit an optimization 8589 // If the receiver is NOT a JSObject we have hit an optimization
8574 // where a value object is not converted into a wrapped JS objects. 8590 // where a value object is not converted into a wrapped JS objects.
8575 // To hide this optimization from the debugger, we wrap the receiver 8591 // To hide this optimization from the debugger, we wrap the receiver
8576 // by creating correct wrapper object based on the calling frame's 8592 // by creating correct wrapper object based on the calling frame's
8577 // global context. 8593 // global context.
8578 it.Advance(); 8594 it.Advance();
8579 Handle<Context> calling_frames_global_context( 8595 Handle<Context> calling_frames_global_context(
8580 Context::cast(Context::cast(it.frame()->context())->global_context())); 8596 Context::cast(Context::cast(it.frame()->context())->global_context()));
8581 receiver = Factory::ToObject(receiver, calling_frames_global_context); 8597 receiver = Factory::ToObject(receiver, calling_frames_global_context);
8582 } 8598 }
8583 details->set(kFrameDetailsReceiverIndex, *receiver); 8599 details->set(kFrameDetailsReceiverIndex, *receiver);
8584 8600
8585 ASSERT_EQ(details_size, details_index); 8601 ASSERT_EQ(details_size, details_index);
8586 return *Factory::NewJSArrayWithElements(details); 8602 return *Factory::NewJSArrayWithElements(details);
8587 } 8603 }
8588 8604
8589 8605
8590 // Copy all the context locals into an object used to materialize a scope. 8606 // Copy all the context locals into an object used to materialize a scope.
8591 static void CopyContextLocalsToScopeObject( 8607 static void CopyContextLocalsToScopeObject(
8592 Heap* heap, 8608 Isolate* isolate,
8593 Handle<SerializedScopeInfo> serialized_scope_info, 8609 Handle<SerializedScopeInfo> serialized_scope_info,
8594 ScopeInfo<>& scope_info, 8610 ScopeInfo<>& scope_info,
8595 Handle<Context> context, 8611 Handle<Context> context,
8596 Handle<JSObject> scope_object) { 8612 Handle<JSObject> scope_object) {
8597 // Fill all context locals to the context extension. 8613 // Fill all context locals to the context extension.
8598 for (int i = Context::MIN_CONTEXT_SLOTS; 8614 for (int i = Context::MIN_CONTEXT_SLOTS;
8599 i < scope_info.number_of_context_slots(); 8615 i < scope_info.number_of_context_slots();
8600 i++) { 8616 i++) {
8601 int context_index = serialized_scope_info->ContextSlotIndex( 8617 int context_index = serialized_scope_info->ContextSlotIndex(
8602 *scope_info.context_slot_name(i), NULL); 8618 *scope_info.context_slot_name(i), NULL);
8603 8619
8604 // Don't include the arguments shadow (.arguments) context variable. 8620 // Don't include the arguments shadow (.arguments) context variable.
8605 if (*scope_info.context_slot_name(i) != heap->arguments_shadow_symbol()) { 8621 if (*scope_info.context_slot_name(i) !=
8622 isolate->heap()->arguments_shadow_symbol()) {
8606 SetProperty(scope_object, 8623 SetProperty(scope_object,
8607 scope_info.context_slot_name(i), 8624 scope_info.context_slot_name(i),
8608 Handle<Object>(context->get(context_index)), NONE); 8625 Handle<Object>(context->get(context_index), isolate), NONE);
8609 } 8626 }
8610 } 8627 }
8611 } 8628 }
8612 8629
8613 8630
8614 // Create a plain JSObject which materializes the local scope for the specified 8631 // Create a plain JSObject which materializes the local scope for the specified
8615 // frame. 8632 // frame.
8616 static Handle<JSObject> MaterializeLocalScope(Heap* heap, 8633 static Handle<JSObject> MaterializeLocalScope(Isolate* isolate,
8617 JavaScriptFrame* frame) { 8634 JavaScriptFrame* frame) {
8618 Handle<JSFunction> function(JSFunction::cast(frame->function())); 8635 Handle<JSFunction> function(JSFunction::cast(frame->function()));
8619 Handle<SharedFunctionInfo> shared(function->shared()); 8636 Handle<SharedFunctionInfo> shared(function->shared());
8620 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); 8637 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info());
8621 ScopeInfo<> scope_info(*serialized_scope_info); 8638 ScopeInfo<> scope_info(*serialized_scope_info);
8622 8639
8623 // Allocate and initialize a JSObject with all the arguments, stack locals 8640 // Allocate and initialize a JSObject with all the arguments, stack locals
8624 // heap locals and extension properties of the debugged function. 8641 // heap locals and extension properties of the debugged function.
8625 Handle<JSObject> local_scope = 8642 Handle<JSObject> local_scope =
8626 Factory::NewJSObject(heap->isolate()->object_function()); 8643 Factory::NewJSObject(isolate->object_function());
8627 8644
8628 // First fill all parameters. 8645 // First fill all parameters.
8629 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 8646 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
8630 SetProperty(local_scope, 8647 SetProperty(local_scope,
8631 scope_info.parameter_name(i), 8648 scope_info.parameter_name(i),
8632 Handle<Object>(frame->GetParameter(i)), NONE); 8649 Handle<Object>(frame->GetParameter(i), isolate), NONE);
8633 } 8650 }
8634 8651
8635 // Second fill all stack locals. 8652 // Second fill all stack locals.
8636 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) { 8653 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) {
8637 SetProperty(local_scope, 8654 SetProperty(local_scope,
8638 scope_info.stack_slot_name(i), 8655 scope_info.stack_slot_name(i),
8639 Handle<Object>(frame->GetExpression(i)), NONE); 8656 Handle<Object>(frame->GetExpression(i), isolate), NONE);
8640 } 8657 }
8641 8658
8642 // Third fill all context locals. 8659 // Third fill all context locals.
8643 Handle<Context> frame_context(Context::cast(frame->context())); 8660 Handle<Context> frame_context(Context::cast(frame->context()));
8644 Handle<Context> function_context(frame_context->fcontext()); 8661 Handle<Context> function_context(frame_context->fcontext());
8645 CopyContextLocalsToScopeObject(heap, serialized_scope_info, scope_info, 8662 CopyContextLocalsToScopeObject(isolate, serialized_scope_info, scope_info,
8646 function_context, local_scope); 8663 function_context, local_scope);
8647 8664
8648 // Finally copy any properties from the function context extension. This will 8665 // Finally copy any properties from the function context extension. This will
8649 // be variables introduced by eval. 8666 // be variables introduced by eval.
8650 if (function_context->closure() == *function) { 8667 if (function_context->closure() == *function) {
8651 if (function_context->has_extension() && 8668 if (function_context->has_extension() &&
8652 !function_context->IsGlobalContext()) { 8669 !function_context->IsGlobalContext()) {
8653 Handle<JSObject> ext(JSObject::cast(function_context->extension())); 8670 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
8654 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); 8671 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS);
8655 for (int i = 0; i < keys->length(); i++) { 8672 for (int i = 0; i < keys->length(); i++) {
8656 // Names of variables introduced by eval are strings. 8673 // Names of variables introduced by eval are strings.
8657 ASSERT(keys->get(i)->IsString()); 8674 ASSERT(keys->get(i)->IsString());
8658 Handle<String> key(String::cast(keys->get(i))); 8675 Handle<String> key(String::cast(keys->get(i)));
8659 SetProperty(local_scope, key, GetProperty(ext, key), NONE); 8676 SetProperty(local_scope, key, GetProperty(ext, key), NONE);
8660 } 8677 }
8661 } 8678 }
8662 } 8679 }
8663 return local_scope; 8680 return local_scope;
8664 } 8681 }
8665 8682
8666 8683
8667 // Create a plain JSObject which materializes the closure content for the 8684 // Create a plain JSObject which materializes the closure content for the
8668 // context. 8685 // context.
8669 static Handle<JSObject> MaterializeClosure(Heap* heap, 8686 static Handle<JSObject> MaterializeClosure(Isolate* isolate,
8670 Handle<Context> context) { 8687 Handle<Context> context) {
8671 ASSERT(context->is_function_context()); 8688 ASSERT(context->is_function_context());
8672 8689
8673 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 8690 Handle<SharedFunctionInfo> shared(context->closure()->shared());
8674 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); 8691 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info());
8675 ScopeInfo<> scope_info(*serialized_scope_info); 8692 ScopeInfo<> scope_info(*serialized_scope_info);
8676 8693
8677 // Allocate and initialize a JSObject with all the content of theis function 8694 // Allocate and initialize a JSObject with all the content of theis function
8678 // closure. 8695 // closure.
8679 Handle<JSObject> closure_scope = 8696 Handle<JSObject> closure_scope =
8680 Factory::NewJSObject(heap->isolate()->object_function()); 8697 Factory::NewJSObject(isolate->object_function());
8681 8698
8682 // Check whether the arguments shadow object exists. 8699 // Check whether the arguments shadow object exists.
8683 int arguments_shadow_index = 8700 int arguments_shadow_index =
8684 shared->scope_info()->ContextSlotIndex( 8701 shared->scope_info()->ContextSlotIndex(
8685 heap->arguments_shadow_symbol(), NULL); 8702 isolate->heap()->arguments_shadow_symbol(), NULL);
8686 if (arguments_shadow_index >= 0) { 8703 if (arguments_shadow_index >= 0) {
8687 // In this case all the arguments are available in the arguments shadow 8704 // In this case all the arguments are available in the arguments shadow
8688 // object. 8705 // object.
8689 Handle<JSObject> arguments_shadow( 8706 Handle<JSObject> arguments_shadow(
8690 JSObject::cast(context->get(arguments_shadow_index))); 8707 JSObject::cast(context->get(arguments_shadow_index)));
8691 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 8708 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
8692 SetProperty(closure_scope, 8709 SetProperty(closure_scope,
8693 scope_info.parameter_name(i), 8710 scope_info.parameter_name(i),
8694 Handle<Object>(arguments_shadow->GetElement(i)), NONE); 8711 Handle<Object>(arguments_shadow->GetElement(i), isolate),
8712 NONE);
8695 } 8713 }
8696 } 8714 }
8697 8715
8698 // Fill all context locals to the context extension. 8716 // Fill all context locals to the context extension.
8699 CopyContextLocalsToScopeObject(heap, serialized_scope_info, scope_info, 8717 CopyContextLocalsToScopeObject(isolate, serialized_scope_info, scope_info,
8700 context, closure_scope); 8718 context, closure_scope);
8701 8719
8702 // Finally copy any properties from the function context extension. This will 8720 // Finally copy any properties from the function context extension. This will
8703 // be variables introduced by eval. 8721 // be variables introduced by eval.
8704 if (context->has_extension()) { 8722 if (context->has_extension()) {
8705 Handle<JSObject> ext(JSObject::cast(context->extension())); 8723 Handle<JSObject> ext(JSObject::cast(context->extension()));
8706 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); 8724 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS);
8707 for (int i = 0; i < keys->length(); i++) { 8725 for (int i = 0; i < keys->length(); i++) {
8708 // Names of variables introduced by eval are strings. 8726 // Names of variables introduced by eval are strings.
8709 ASSERT(keys->get(i)->IsString()); 8727 ASSERT(keys->get(i)->IsString());
(...skipping 16 matching lines...) Expand all
8726 ScopeTypeLocal, 8744 ScopeTypeLocal,
8727 ScopeTypeWith, 8745 ScopeTypeWith,
8728 ScopeTypeClosure, 8746 ScopeTypeClosure,
8729 // Every catch block contains an implicit with block (its parameter is 8747 // Every catch block contains an implicit with block (its parameter is
8730 // a JSContextExtensionObject) that extends current scope with a variable 8748 // a JSContextExtensionObject) that extends current scope with a variable
8731 // holding exception object. Such with blocks are treated as scopes of their 8749 // holding exception object. Such with blocks are treated as scopes of their
8732 // own type. 8750 // own type.
8733 ScopeTypeCatch 8751 ScopeTypeCatch
8734 }; 8752 };
8735 8753
8736 explicit ScopeIterator(Heap* heap, JavaScriptFrame* frame) 8754 explicit ScopeIterator(Isolate* isolate, JavaScriptFrame* frame)
8737 : heap_(heap), 8755 : isolate_(isolate),
8738 frame_(frame), 8756 frame_(frame),
8739 function_(JSFunction::cast(frame->function())), 8757 function_(JSFunction::cast(frame->function())),
8740 context_(Context::cast(frame->context())), 8758 context_(Context::cast(frame->context())),
8741 local_done_(false), 8759 local_done_(false),
8742 at_local_(false) { 8760 at_local_(false) {
8743 8761
8744 // Check whether the first scope is actually a local scope. 8762 // Check whether the first scope is actually a local scope.
8745 if (context_->IsGlobalContext()) { 8763 if (context_->IsGlobalContext()) {
8746 // If there is a stack slot for .result then this local scope has been 8764 // If there is a stack slot for .result then this local scope has been
8747 // created for evaluating top level code and it is not a real local scope. 8765 // created for evaluating top level code and it is not a real local scope.
8748 // Checking for the existence of .result seems fragile, but the scope info 8766 // Checking for the existence of .result seems fragile, but the scope info
8749 // saved with the code object does not otherwise have that information. 8767 // saved with the code object does not otherwise have that information.
8750 int index = function_->shared()->scope_info()-> 8768 int index = function_->shared()->scope_info()->
8751 StackSlotIndex(heap_->result_symbol()); 8769 StackSlotIndex(isolate_->heap()->result_symbol());
8752 at_local_ = index < 0; 8770 at_local_ = index < 0;
8753 } else if (context_->is_function_context()) { 8771 } else if (context_->is_function_context()) {
8754 at_local_ = true; 8772 at_local_ = true;
8755 } 8773 }
8756 } 8774 }
8757 8775
8758 // More scopes? 8776 // More scopes?
8759 bool Done() { return context_.is_null(); } 8777 bool Done() { return context_.is_null(); }
8760 8778
8761 // Move to the next scope. 8779 // Move to the next scope.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
8819 } 8837 }
8820 8838
8821 // Return the JavaScript object with the content of the current scope. 8839 // Return the JavaScript object with the content of the current scope.
8822 Handle<JSObject> ScopeObject() { 8840 Handle<JSObject> ScopeObject() {
8823 switch (Type()) { 8841 switch (Type()) {
8824 case ScopeIterator::ScopeTypeGlobal: 8842 case ScopeIterator::ScopeTypeGlobal:
8825 return Handle<JSObject>(CurrentContext()->global()); 8843 return Handle<JSObject>(CurrentContext()->global());
8826 break; 8844 break;
8827 case ScopeIterator::ScopeTypeLocal: 8845 case ScopeIterator::ScopeTypeLocal:
8828 // Materialize the content of the local scope into a JSObject. 8846 // Materialize the content of the local scope into a JSObject.
8829 return MaterializeLocalScope(heap_, frame_); 8847 return MaterializeLocalScope(isolate_, frame_);
8830 break; 8848 break;
8831 case ScopeIterator::ScopeTypeWith: 8849 case ScopeIterator::ScopeTypeWith:
8832 case ScopeIterator::ScopeTypeCatch: 8850 case ScopeIterator::ScopeTypeCatch:
8833 // Return the with object. 8851 // Return the with object.
8834 return Handle<JSObject>(CurrentContext()->extension()); 8852 return Handle<JSObject>(CurrentContext()->extension());
8835 break; 8853 break;
8836 case ScopeIterator::ScopeTypeClosure: 8854 case ScopeIterator::ScopeTypeClosure:
8837 // Materialize the content of the closure scope into a JSObject. 8855 // Materialize the content of the closure scope into a JSObject.
8838 return MaterializeClosure(heap_, CurrentContext()); 8856 return MaterializeClosure(isolate_, CurrentContext());
8839 break; 8857 break;
8840 } 8858 }
8841 UNREACHABLE(); 8859 UNREACHABLE();
8842 return Handle<JSObject>(); 8860 return Handle<JSObject>();
8843 } 8861 }
8844 8862
8845 // Return the context for this scope. For the local context there might not 8863 // Return the context for this scope. For the local context there might not
8846 // be an actual context. 8864 // be an actual context.
8847 Handle<Context> CurrentContext() { 8865 Handle<Context> CurrentContext() {
8848 if (at_local_ && context_->closure() != *function_) { 8866 if (at_local_ && context_->closure() != *function_) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
8907 } 8925 }
8908 8926
8909 default: 8927 default:
8910 UNREACHABLE(); 8928 UNREACHABLE();
8911 } 8929 }
8912 PrintF("\n"); 8930 PrintF("\n");
8913 } 8931 }
8914 #endif 8932 #endif
8915 8933
8916 private: 8934 private:
8917 Heap* heap_; 8935 Isolate* isolate_;
8918 JavaScriptFrame* frame_; 8936 JavaScriptFrame* frame_;
8919 Handle<JSFunction> function_; 8937 Handle<JSFunction> function_;
8920 Handle<Context> context_; 8938 Handle<Context> context_;
8921 bool local_done_; 8939 bool local_done_;
8922 bool at_local_; 8940 bool at_local_;
8923 8941
8924 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); 8942 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator);
8925 }; 8943 };
8926 8944
8927 8945
8928 static Object* Runtime_GetScopeCount(RUNTIME_CALLING_CONVENTION) { 8946 static Object* Runtime_GetScopeCount(RUNTIME_CALLING_CONVENTION) {
8929 RUNTIME_GET_ISOLATE; 8947 RUNTIME_GET_ISOLATE;
8930 HandleScope scope; 8948 HandleScope scope(isolate);
8931 ASSERT(args.length() == 2); 8949 ASSERT(args.length() == 2);
8932 8950
8933 // Check arguments. 8951 // Check arguments.
8934 Object* check = Runtime_CheckExecutionState(args, isolate); 8952 Object* check = Runtime_CheckExecutionState(args, isolate);
8935 if (check->IsFailure()) return check; 8953 if (check->IsFailure()) return check;
8936 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 8954 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
8937 8955
8938 // Get the frame where the debugging is performed. 8956 // Get the frame where the debugging is performed.
8939 StackFrame::Id id = UnwrapFrameId(wrapped_id); 8957 StackFrame::Id id = UnwrapFrameId(wrapped_id);
8940 JavaScriptFrameIterator it(id); 8958 JavaScriptFrameIterator it(id);
8941 JavaScriptFrame* frame = it.frame(); 8959 JavaScriptFrame* frame = it.frame();
8942 8960
8943 // Count the visible scopes. 8961 // Count the visible scopes.
8944 int n = 0; 8962 int n = 0;
8945 for (ScopeIterator it(isolate->heap(), frame); !it.Done(); it.Next()) { 8963 for (ScopeIterator it(isolate, frame); !it.Done(); it.Next()) {
8946 n++; 8964 n++;
8947 } 8965 }
8948 8966
8949 return Smi::FromInt(n); 8967 return Smi::FromInt(n);
8950 } 8968 }
8951 8969
8952 8970
8953 static const int kScopeDetailsTypeIndex = 0; 8971 static const int kScopeDetailsTypeIndex = 0;
8954 static const int kScopeDetailsObjectIndex = 1; 8972 static const int kScopeDetailsObjectIndex = 1;
8955 static const int kScopeDetailsSize = 2; 8973 static const int kScopeDetailsSize = 2;
8956 8974
8957 // Return an array with scope details 8975 // Return an array with scope details
8958 // args[0]: number: break id 8976 // args[0]: number: break id
8959 // args[1]: number: frame index 8977 // args[1]: number: frame index
8960 // args[2]: number: scope index 8978 // args[2]: number: scope index
8961 // 8979 //
8962 // The array returned contains the following information: 8980 // The array returned contains the following information:
8963 // 0: Scope type 8981 // 0: Scope type
8964 // 1: Scope object 8982 // 1: Scope object
8965 static Object* Runtime_GetScopeDetails(RUNTIME_CALLING_CONVENTION) { 8983 static Object* Runtime_GetScopeDetails(RUNTIME_CALLING_CONVENTION) {
8966 RUNTIME_GET_ISOLATE; 8984 RUNTIME_GET_ISOLATE;
8967 HandleScope scope; 8985 HandleScope scope(isolate);
8968 ASSERT(args.length() == 3); 8986 ASSERT(args.length() == 3);
8969 8987
8970 // Check arguments. 8988 // Check arguments.
8971 Object* check = Runtime_CheckExecutionState(args, isolate); 8989 Object* check = Runtime_CheckExecutionState(args, isolate);
8972 if (check->IsFailure()) return check; 8990 if (check->IsFailure()) return check;
8973 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 8991 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
8974 CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]); 8992 CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]);
8975 8993
8976 // Get the frame where the debugging is performed. 8994 // Get the frame where the debugging is performed.
8977 StackFrame::Id id = UnwrapFrameId(wrapped_id); 8995 StackFrame::Id id = UnwrapFrameId(wrapped_id);
8978 JavaScriptFrameIterator frame_it(id); 8996 JavaScriptFrameIterator frame_it(id);
8979 JavaScriptFrame* frame = frame_it.frame(); 8997 JavaScriptFrame* frame = frame_it.frame();
8980 8998
8981 // Find the requested scope. 8999 // Find the requested scope.
8982 int n = 0; 9000 int n = 0;
8983 ScopeIterator it(isolate->heap(), frame); 9001 ScopeIterator it(isolate, frame);
8984 for (; !it.Done() && n < index; it.Next()) { 9002 for (; !it.Done() && n < index; it.Next()) {
8985 n++; 9003 n++;
8986 } 9004 }
8987 if (it.Done()) { 9005 if (it.Done()) {
8988 return isolate->heap()->undefined_value(); 9006 return isolate->heap()->undefined_value();
8989 } 9007 }
8990 9008
8991 // Calculate the size of the result. 9009 // Calculate the size of the result.
8992 int details_size = kScopeDetailsSize; 9010 int details_size = kScopeDetailsSize;
8993 Handle<FixedArray> details = Factory::NewFixedArray(details_size); 9011 Handle<FixedArray> details = Factory::NewFixedArray(details_size);
8994 9012
8995 // Fill in scope details. 9013 // Fill in scope details.
8996 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type())); 9014 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type()));
8997 Handle<JSObject> scope_object = it.ScopeObject(); 9015 Handle<JSObject> scope_object = it.ScopeObject();
8998 details->set(kScopeDetailsObjectIndex, *scope_object); 9016 details->set(kScopeDetailsObjectIndex, *scope_object);
8999 9017
9000 return *Factory::NewJSArrayWithElements(details); 9018 return *Factory::NewJSArrayWithElements(details);
9001 } 9019 }
9002 9020
9003 9021
9004 static Object* Runtime_DebugPrintScopes(RUNTIME_CALLING_CONVENTION) { 9022 static Object* Runtime_DebugPrintScopes(RUNTIME_CALLING_CONVENTION) {
9005 RUNTIME_GET_ISOLATE; 9023 RUNTIME_GET_ISOLATE;
9006 HandleScope scope; 9024 HandleScope scope(isolate);
9007 ASSERT(args.length() == 0); 9025 ASSERT(args.length() == 0);
9008 9026
9009 #ifdef DEBUG 9027 #ifdef DEBUG
9010 // Print the scopes for the top frame. 9028 // Print the scopes for the top frame.
9011 StackFrameLocator locator; 9029 StackFrameLocator locator;
9012 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 9030 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
9013 for (ScopeIterator it(isolate->heap(), frame); !it.Done(); it.Next()) { 9031 for (ScopeIterator it(isolate, frame); !it.Done(); it.Next()) {
9014 it.DebugPrint(); 9032 it.DebugPrint();
9015 } 9033 }
9016 #endif 9034 #endif
9017 return isolate->heap()->undefined_value(); 9035 return isolate->heap()->undefined_value();
9018 } 9036 }
9019 9037
9020 9038
9021 static Object* Runtime_GetCFrames(RUNTIME_CALLING_CONVENTION) { 9039 static Object* Runtime_GetCFrames(RUNTIME_CALLING_CONVENTION) {
9022 RUNTIME_GET_ISOLATE; 9040 RUNTIME_GET_ISOLATE;
9023 HandleScope scope; 9041 HandleScope scope(isolate);
9024 ASSERT(args.length() == 1); 9042 ASSERT(args.length() == 1);
9025 Object* result = Runtime_CheckExecutionState(args, isolate); 9043 Object* result = Runtime_CheckExecutionState(args, isolate);
9026 if (result->IsFailure()) return result; 9044 if (result->IsFailure()) return result;
9027 9045
9028 #if V8_HOST_ARCH_64_BIT 9046 #if V8_HOST_ARCH_64_BIT
9029 UNIMPLEMENTED(); 9047 UNIMPLEMENTED();
9030 return isolate->heap()->undefined_value(); 9048 return isolate->heap()->undefined_value();
9031 #else 9049 #else
9032 9050
9033 static const int kMaxCFramesSize = 200; 9051 static const int kMaxCFramesSize = 200;
(...skipping 28 matching lines...) Expand all
9062 9080
9063 frames_array->set(i, *frame_value); 9081 frames_array->set(i, *frame_value);
9064 } 9082 }
9065 return *Factory::NewJSArrayWithElements(frames_array); 9083 return *Factory::NewJSArrayWithElements(frames_array);
9066 #endif // V8_HOST_ARCH_64_BIT 9084 #endif // V8_HOST_ARCH_64_BIT
9067 } 9085 }
9068 9086
9069 9087
9070 static Object* Runtime_GetThreadCount(RUNTIME_CALLING_CONVENTION) { 9088 static Object* Runtime_GetThreadCount(RUNTIME_CALLING_CONVENTION) {
9071 RUNTIME_GET_ISOLATE; 9089 RUNTIME_GET_ISOLATE;
9072 HandleScope scope; 9090 HandleScope scope(isolate);
9073 ASSERT(args.length() == 1); 9091 ASSERT(args.length() == 1);
9074 9092
9075 // Check arguments. 9093 // Check arguments.
9076 Object* result = Runtime_CheckExecutionState(args, isolate); 9094 Object* result = Runtime_CheckExecutionState(args, isolate);
9077 if (result->IsFailure()) return result; 9095 if (result->IsFailure()) return result;
9078 9096
9079 // Count all archived V8 threads. 9097 // Count all archived V8 threads.
9080 int n = 0; 9098 int n = 0;
9081 for (ThreadState* thread = 9099 for (ThreadState* thread =
9082 isolate->thread_manager()->FirstThreadStateInUse(); 9100 isolate->thread_manager()->FirstThreadStateInUse();
(...skipping 13 matching lines...) Expand all
9096 9114
9097 // Return an array with thread details 9115 // Return an array with thread details
9098 // args[0]: number: break id 9116 // args[0]: number: break id
9099 // args[1]: number: thread index 9117 // args[1]: number: thread index
9100 // 9118 //
9101 // The array returned contains the following information: 9119 // The array returned contains the following information:
9102 // 0: Is current thread? 9120 // 0: Is current thread?
9103 // 1: Thread id 9121 // 1: Thread id
9104 static Object* Runtime_GetThreadDetails(RUNTIME_CALLING_CONVENTION) { 9122 static Object* Runtime_GetThreadDetails(RUNTIME_CALLING_CONVENTION) {
9105 RUNTIME_GET_ISOLATE; 9123 RUNTIME_GET_ISOLATE;
9106 HandleScope scope; 9124 HandleScope scope(isolate);
9107 ASSERT(args.length() == 2); 9125 ASSERT(args.length() == 2);
9108 9126
9109 // Check arguments. 9127 // Check arguments.
9110 Object* check = Runtime_CheckExecutionState(args, isolate); 9128 Object* check = Runtime_CheckExecutionState(args, isolate);
9111 if (check->IsFailure()) return check; 9129 if (check->IsFailure()) return check;
9112 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); 9130 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
9113 9131
9114 // Allocate array for result. 9132 // Allocate array for result.
9115 Handle<FixedArray> details = Factory::NewFixedArray(kThreadDetailsSize); 9133 Handle<FixedArray> details = Factory::NewFixedArray(kThreadDetailsSize);
9116 9134
(...skipping 26 matching lines...) Expand all
9143 9161
9144 // Convert to JS array and return. 9162 // Convert to JS array and return.
9145 return *Factory::NewJSArrayWithElements(details); 9163 return *Factory::NewJSArrayWithElements(details);
9146 } 9164 }
9147 9165
9148 9166
9149 // Sets the disable break state 9167 // Sets the disable break state
9150 // args[0]: disable break state 9168 // args[0]: disable break state
9151 static Object* Runtime_SetDisableBreak(RUNTIME_CALLING_CONVENTION) { 9169 static Object* Runtime_SetDisableBreak(RUNTIME_CALLING_CONVENTION) {
9152 RUNTIME_GET_ISOLATE; 9170 RUNTIME_GET_ISOLATE;
9153 HandleScope scope; 9171 HandleScope scope(isolate);
9154 ASSERT(args.length() == 1); 9172 ASSERT(args.length() == 1);
9155 CONVERT_BOOLEAN_CHECKED(disable_break, args[0]); 9173 CONVERT_BOOLEAN_CHECKED(disable_break, args[0]);
9156 isolate->debug()->set_disable_break(disable_break); 9174 isolate->debug()->set_disable_break(disable_break);
9157 return isolate->heap()->undefined_value(); 9175 return isolate->heap()->undefined_value();
9158 } 9176 }
9159 9177
9160 9178
9161 static Object* Runtime_GetBreakLocations(RUNTIME_CALLING_CONVENTION) { 9179 static Object* Runtime_GetBreakLocations(RUNTIME_CALLING_CONVENTION) {
9162 RUNTIME_GET_ISOLATE; 9180 RUNTIME_GET_ISOLATE;
9163 HandleScope scope; 9181 HandleScope scope(isolate);
9164 ASSERT(args.length() == 1); 9182 ASSERT(args.length() == 1);
9165 9183
9166 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 9184 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
9167 Handle<SharedFunctionInfo> shared(fun->shared()); 9185 Handle<SharedFunctionInfo> shared(fun->shared());
9168 // Find the number of break points 9186 // Find the number of break points
9169 Handle<Object> break_locations = Debug::GetSourceBreakLocations(shared); 9187 Handle<Object> break_locations = Debug::GetSourceBreakLocations(shared);
9170 if (break_locations->IsUndefined()) return isolate->heap()->undefined_value(); 9188 if (break_locations->IsUndefined()) return isolate->heap()->undefined_value();
9171 // Return array as JS array 9189 // Return array as JS array
9172 return *Factory::NewJSArrayWithElements( 9190 return *Factory::NewJSArrayWithElements(
9173 Handle<FixedArray>::cast(break_locations)); 9191 Handle<FixedArray>::cast(break_locations));
9174 } 9192 }
9175 9193
9176 9194
9177 // Set a break point in a function 9195 // Set a break point in a function
9178 // args[0]: function 9196 // args[0]: function
9179 // args[1]: number: break source position (within the function source) 9197 // args[1]: number: break source position (within the function source)
9180 // args[2]: number: break point object 9198 // args[2]: number: break point object
9181 static Object* Runtime_SetFunctionBreakPoint(RUNTIME_CALLING_CONVENTION) { 9199 static Object* Runtime_SetFunctionBreakPoint(RUNTIME_CALLING_CONVENTION) {
9182 RUNTIME_GET_ISOLATE; 9200 RUNTIME_GET_ISOLATE;
9183 HandleScope scope; 9201 HandleScope scope(isolate);
9184 ASSERT(args.length() == 3); 9202 ASSERT(args.length() == 3);
9185 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 9203 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
9186 Handle<SharedFunctionInfo> shared(fun->shared()); 9204 Handle<SharedFunctionInfo> shared(fun->shared());
9187 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 9205 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
9188 RUNTIME_ASSERT(source_position >= 0); 9206 RUNTIME_ASSERT(source_position >= 0);
9189 Handle<Object> break_point_object_arg = args.at<Object>(2); 9207 Handle<Object> break_point_object_arg = args.at<Object>(2);
9190 9208
9191 // Set break point. 9209 // Set break point.
9192 isolate->debug()->SetBreakPoint(shared, break_point_object_arg, 9210 isolate->debug()->SetBreakPoint(shared, break_point_object_arg,
9193 &source_position); 9211 &source_position);
9194 9212
9195 return Smi::FromInt(source_position); 9213 return Smi::FromInt(source_position);
9196 } 9214 }
9197 9215
9198 9216
9199 Object* Runtime::FindSharedFunctionInfoInScript(Heap* heap, 9217 Object* Runtime::FindSharedFunctionInfoInScript(Isolate* isolate,
9200 Handle<Script> script, 9218 Handle<Script> script,
9201 int position) { 9219 int position) {
9202 // Iterate the heap looking for SharedFunctionInfo generated from the 9220 // Iterate the heap looking for SharedFunctionInfo generated from the
9203 // script. The inner most SharedFunctionInfo containing the source position 9221 // script. The inner most SharedFunctionInfo containing the source position
9204 // for the requested break point is found. 9222 // for the requested break point is found.
9205 // NOTE: This might reqire several heap iterations. If the SharedFunctionInfo 9223 // NOTE: This might reqire several heap iterations. If the SharedFunctionInfo
9206 // which is found is not compiled it is compiled and the heap is iterated 9224 // which is found is not compiled it is compiled and the heap is iterated
9207 // again as the compilation might create inner functions from the newly 9225 // again as the compilation might create inner functions from the newly
9208 // compiled function and the actual requested break point might be in one of 9226 // compiled function and the actual requested break point might be in one of
9209 // these functions. 9227 // these functions.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
9249 target_start_position = start_position; 9267 target_start_position = start_position;
9250 target = shared; 9268 target = shared;
9251 } 9269 }
9252 } 9270 }
9253 } 9271 }
9254 } 9272 }
9255 } 9273 }
9256 } 9274 }
9257 9275
9258 if (target.is_null()) { 9276 if (target.is_null()) {
9259 return heap->undefined_value(); 9277 return isolate->heap()->undefined_value();
9260 } 9278 }
9261 9279
9262 // If the candidate found is compiled we are done. NOTE: when lazy 9280 // If the candidate found is compiled we are done. NOTE: when lazy
9263 // compilation of inner functions is introduced some additional checking 9281 // compilation of inner functions is introduced some additional checking
9264 // needs to be done here to compile inner functions. 9282 // needs to be done here to compile inner functions.
9265 done = target->is_compiled(); 9283 done = target->is_compiled();
9266 if (!done) { 9284 if (!done) {
9267 // If the candidate is not compiled compile it to reveal any inner 9285 // If the candidate is not compiled compile it to reveal any inner
9268 // functions which might contain the requested source position. 9286 // functions which might contain the requested source position.
9269 CompileLazyShared(target, KEEP_EXCEPTION); 9287 CompileLazyShared(target, KEEP_EXCEPTION);
9270 } 9288 }
9271 } 9289 }
9272 9290
9273 return *target; 9291 return *target;
9274 } 9292 }
9275 9293
9276 9294
9277 // Changes the state of a break point in a script and returns source position 9295 // Changes the state of a break point in a script and returns source position
9278 // where break point was set. NOTE: Regarding performance see the NOTE for 9296 // where break point was set. NOTE: Regarding performance see the NOTE for
9279 // GetScriptFromScriptData. 9297 // GetScriptFromScriptData.
9280 // args[0]: script to set break point in 9298 // args[0]: script to set break point in
9281 // args[1]: number: break source position (within the script source) 9299 // args[1]: number: break source position (within the script source)
9282 // args[2]: number: break point object 9300 // args[2]: number: break point object
9283 static Object* Runtime_SetScriptBreakPoint(RUNTIME_CALLING_CONVENTION) { 9301 static Object* Runtime_SetScriptBreakPoint(RUNTIME_CALLING_CONVENTION) {
9284 RUNTIME_GET_ISOLATE; 9302 RUNTIME_GET_ISOLATE;
9285 HandleScope scope; 9303 HandleScope scope(isolate);
9286 ASSERT(args.length() == 3); 9304 ASSERT(args.length() == 3);
9287 CONVERT_ARG_CHECKED(JSValue, wrapper, 0); 9305 CONVERT_ARG_CHECKED(JSValue, wrapper, 0);
9288 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 9306 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
9289 RUNTIME_ASSERT(source_position >= 0); 9307 RUNTIME_ASSERT(source_position >= 0);
9290 Handle<Object> break_point_object_arg = args.at<Object>(2); 9308 Handle<Object> break_point_object_arg = args.at<Object>(2);
9291 9309
9292 // Get the script from the script wrapper. 9310 // Get the script from the script wrapper.
9293 RUNTIME_ASSERT(wrapper->value()->IsScript()); 9311 RUNTIME_ASSERT(wrapper->value()->IsScript());
9294 Handle<Script> script(Script::cast(wrapper->value())); 9312 Handle<Script> script(Script::cast(wrapper->value()));
9295 9313
9296 Object* result = Runtime::FindSharedFunctionInfoInScript( 9314 Object* result = Runtime::FindSharedFunctionInfoInScript(
9297 isolate->heap(), script, source_position); 9315 isolate, script, source_position);
9298 if (!result->IsUndefined()) { 9316 if (!result->IsUndefined()) {
9299 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); 9317 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result));
9300 // Find position within function. The script position might be before the 9318 // Find position within function. The script position might be before the
9301 // source position of the first function. 9319 // source position of the first function.
9302 int position; 9320 int position;
9303 if (shared->start_position() > source_position) { 9321 if (shared->start_position() > source_position) {
9304 position = 0; 9322 position = 0;
9305 } else { 9323 } else {
9306 position = source_position - shared->start_position(); 9324 position = source_position - shared->start_position();
9307 } 9325 }
9308 isolate->debug()->SetBreakPoint(shared, break_point_object_arg, &position); 9326 isolate->debug()->SetBreakPoint(shared, break_point_object_arg, &position);
9309 position += shared->start_position(); 9327 position += shared->start_position();
9310 return Smi::FromInt(position); 9328 return Smi::FromInt(position);
9311 } 9329 }
9312 return isolate->heap()->undefined_value(); 9330 return isolate->heap()->undefined_value();
9313 } 9331 }
9314 9332
9315 9333
9316 // Clear a break point 9334 // Clear a break point
9317 // args[0]: number: break point object 9335 // args[0]: number: break point object
9318 static Object* Runtime_ClearBreakPoint(RUNTIME_CALLING_CONVENTION) { 9336 static Object* Runtime_ClearBreakPoint(RUNTIME_CALLING_CONVENTION) {
9319 RUNTIME_GET_ISOLATE; 9337 RUNTIME_GET_ISOLATE;
9320 HandleScope scope; 9338 HandleScope scope(isolate);
9321 ASSERT(args.length() == 1); 9339 ASSERT(args.length() == 1);
9322 Handle<Object> break_point_object_arg = args.at<Object>(0); 9340 Handle<Object> break_point_object_arg = args.at<Object>(0);
9323 9341
9324 // Clear break point. 9342 // Clear break point.
9325 isolate->debug()->ClearBreakPoint(break_point_object_arg); 9343 isolate->debug()->ClearBreakPoint(break_point_object_arg);
9326 9344
9327 return isolate->heap()->undefined_value(); 9345 return isolate->heap()->undefined_value();
9328 } 9346 }
9329 9347
9330 9348
9331 // Change the state of break on exceptions. 9349 // Change the state of break on exceptions.
9332 // args[0]: Enum value indicating whether to affect caught/uncaught exceptions. 9350 // args[0]: Enum value indicating whether to affect caught/uncaught exceptions.
9333 // args[1]: Boolean indicating on/off. 9351 // args[1]: Boolean indicating on/off.
9334 static Object* Runtime_ChangeBreakOnException(RUNTIME_CALLING_CONVENTION) { 9352 static Object* Runtime_ChangeBreakOnException(RUNTIME_CALLING_CONVENTION) {
9335 RUNTIME_GET_ISOLATE; 9353 RUNTIME_GET_ISOLATE;
9336 HandleScope scope; 9354 HandleScope scope(isolate);
9337 ASSERT(args.length() == 2); 9355 ASSERT(args.length() == 2);
9338 RUNTIME_ASSERT(args[0]->IsNumber()); 9356 RUNTIME_ASSERT(args[0]->IsNumber());
9339 CONVERT_BOOLEAN_CHECKED(enable, args[1]); 9357 CONVERT_BOOLEAN_CHECKED(enable, args[1]);
9340 9358
9341 // If the number doesn't match an enum value, the ChangeBreakOnException 9359 // If the number doesn't match an enum value, the ChangeBreakOnException
9342 // function will default to affecting caught exceptions. 9360 // function will default to affecting caught exceptions.
9343 ExceptionBreakType type = 9361 ExceptionBreakType type =
9344 static_cast<ExceptionBreakType>(NumberToUint32(args[0])); 9362 static_cast<ExceptionBreakType>(NumberToUint32(args[0]));
9345 // Update break point state. 9363 // Update break point state.
9346 isolate->debug()->ChangeBreakOnException(type, enable); 9364 isolate->debug()->ChangeBreakOnException(type, enable);
9347 return isolate->heap()->undefined_value(); 9365 return isolate->heap()->undefined_value();
9348 } 9366 }
9349 9367
9350 9368
9351 // Returns the state of break on exceptions 9369 // Returns the state of break on exceptions
9352 // args[0]: boolean indicating uncaught exceptions 9370 // args[0]: boolean indicating uncaught exceptions
9353 static Object* Runtime_IsBreakOnException(RUNTIME_CALLING_CONVENTION) { 9371 static Object* Runtime_IsBreakOnException(RUNTIME_CALLING_CONVENTION) {
9354 RUNTIME_GET_ISOLATE; 9372 RUNTIME_GET_ISOLATE;
9355 HandleScope scope; 9373 HandleScope scope(isolate);
9356 ASSERT(args.length() == 1); 9374 ASSERT(args.length() == 1);
9357 RUNTIME_ASSERT(args[0]->IsNumber()); 9375 RUNTIME_ASSERT(args[0]->IsNumber());
9358 9376
9359 ExceptionBreakType type = 9377 ExceptionBreakType type =
9360 static_cast<ExceptionBreakType>(NumberToUint32(args[0])); 9378 static_cast<ExceptionBreakType>(NumberToUint32(args[0]));
9361 bool result = isolate->debug()->IsBreakOnException(type); 9379 bool result = isolate->debug()->IsBreakOnException(type);
9362 return Smi::FromInt(result); 9380 return Smi::FromInt(result);
9363 } 9381 }
9364 9382
9365 9383
9366 // Prepare for stepping 9384 // Prepare for stepping
9367 // args[0]: break id for checking execution state 9385 // args[0]: break id for checking execution state
9368 // args[1]: step action from the enumeration StepAction 9386 // args[1]: step action from the enumeration StepAction
9369 // args[2]: number of times to perform the step, for step out it is the number 9387 // args[2]: number of times to perform the step, for step out it is the number
9370 // of frames to step down. 9388 // of frames to step down.
9371 static Object* Runtime_PrepareStep(RUNTIME_CALLING_CONVENTION) { 9389 static Object* Runtime_PrepareStep(RUNTIME_CALLING_CONVENTION) {
9372 RUNTIME_GET_ISOLATE; 9390 RUNTIME_GET_ISOLATE;
9373 HandleScope scope; 9391 HandleScope scope(isolate);
9374 ASSERT(args.length() == 3); 9392 ASSERT(args.length() == 3);
9375 // Check arguments. 9393 // Check arguments.
9376 Object* check = Runtime_CheckExecutionState(args, isolate); 9394 Object* check = Runtime_CheckExecutionState(args, isolate);
9377 if (check->IsFailure()) return check; 9395 if (check->IsFailure()) return check;
9378 if (!args[1]->IsNumber() || !args[2]->IsNumber()) { 9396 if (!args[1]->IsNumber() || !args[2]->IsNumber()) {
9379 return isolate->Throw(isolate->heap()->illegal_argument_symbol()); 9397 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
9380 } 9398 }
9381 9399
9382 // Get the step action and check validity. 9400 // Get the step action and check validity.
9383 StepAction step_action = static_cast<StepAction>(NumberToInt32(args[1])); 9401 StepAction step_action = static_cast<StepAction>(NumberToInt32(args[1]));
(...skipping 17 matching lines...) Expand all
9401 // Prepare step. 9419 // Prepare step.
9402 isolate->debug()->PrepareStep(static_cast<StepAction>(step_action), 9420 isolate->debug()->PrepareStep(static_cast<StepAction>(step_action),
9403 step_count); 9421 step_count);
9404 return isolate->heap()->undefined_value(); 9422 return isolate->heap()->undefined_value();
9405 } 9423 }
9406 9424
9407 9425
9408 // Clear all stepping set by PrepareStep. 9426 // Clear all stepping set by PrepareStep.
9409 static Object* Runtime_ClearStepping(RUNTIME_CALLING_CONVENTION) { 9427 static Object* Runtime_ClearStepping(RUNTIME_CALLING_CONVENTION) {
9410 RUNTIME_GET_ISOLATE; 9428 RUNTIME_GET_ISOLATE;
9411 HandleScope scope; 9429 HandleScope scope(isolate);
9412 ASSERT(args.length() == 0); 9430 ASSERT(args.length() == 0);
9413 isolate->debug()->ClearStepping(); 9431 isolate->debug()->ClearStepping();
9414 return isolate->heap()->undefined_value(); 9432 return isolate->heap()->undefined_value();
9415 } 9433 }
9416 9434
9417 9435
9418 // Creates a copy of the with context chain. The copy of the context chain is 9436 // Creates a copy of the with context chain. The copy of the context chain is
9419 // is linked to the function context supplied. 9437 // is linked to the function context supplied.
9420 static Handle<Context> CopyWithContextChain(Handle<Context> context_chain, 9438 static Handle<Context> CopyWithContextChain(Handle<Context> context_chain,
9421 Handle<Context> function_context) { 9439 Handle<Context> function_context) {
9422 // At the bottom of the chain. Return the function context to link to. 9440 // At the bottom of the chain. Return the function context to link to.
9423 if (context_chain->is_function_context()) { 9441 if (context_chain->is_function_context()) {
9424 return function_context; 9442 return function_context;
9425 } 9443 }
9426 9444
9427 // Recursively copy the with contexts. 9445 // Recursively copy the with contexts.
9428 Handle<Context> previous(context_chain->previous()); 9446 Handle<Context> previous(context_chain->previous());
9429 Handle<JSObject> extension(JSObject::cast(context_chain->extension())); 9447 Handle<JSObject> extension(JSObject::cast(context_chain->extension()));
9430 return Factory::NewWithContext( 9448 return Factory::NewWithContext(
9431 CopyWithContextChain(function_context, previous), 9449 CopyWithContextChain(function_context, previous),
9432 extension, 9450 extension,
9433 context_chain->IsCatchContext()); 9451 context_chain->IsCatchContext());
9434 } 9452 }
9435 9453
9436 9454
9437 // Helper function to find or create the arguments object for 9455 // Helper function to find or create the arguments object for
9438 // Runtime_DebugEvaluate. 9456 // Runtime_DebugEvaluate.
9439 static Handle<Object> GetArgumentsObject(Heap* heap, 9457 static Handle<Object> GetArgumentsObject(Isolate* isolate,
9440 JavaScriptFrame* frame, 9458 JavaScriptFrame* frame,
9441 Handle<JSFunction> function, 9459 Handle<JSFunction> function,
9442 Handle<SerializedScopeInfo> scope_info, 9460 Handle<SerializedScopeInfo> scope_info,
9443 const ScopeInfo<>* sinfo, 9461 const ScopeInfo<>* sinfo,
9444 Handle<Context> function_context) { 9462 Handle<Context> function_context) {
9445 // Try to find the value of 'arguments' to pass as parameter. If it is not 9463 // Try to find the value of 'arguments' to pass as parameter. If it is not
9446 // found (that is the debugged function does not reference 'arguments' and 9464 // found (that is the debugged function does not reference 'arguments' and
9447 // does not support eval) then create an 'arguments' object. 9465 // does not support eval) then create an 'arguments' object.
9448 int index; 9466 int index;
9449 if (sinfo->number_of_stack_slots() > 0) { 9467 if (sinfo->number_of_stack_slots() > 0) {
9450 index = scope_info->StackSlotIndex(heap->arguments_symbol()); 9468 index = scope_info->StackSlotIndex(isolate->heap()->arguments_symbol());
9451 if (index != -1) { 9469 if (index != -1) {
9452 return Handle<Object>(frame->GetExpression(index)); 9470 return Handle<Object>(frame->GetExpression(index), isolate);
9453 } 9471 }
9454 } 9472 }
9455 9473
9456 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { 9474 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) {
9457 index = scope_info->ContextSlotIndex(heap->arguments_symbol(), NULL); 9475 index = scope_info->ContextSlotIndex(isolate->heap()->arguments_symbol(),
9476 NULL);
9458 if (index != -1) { 9477 if (index != -1) {
9459 return Handle<Object>(function_context->get(index)); 9478 return Handle<Object>(function_context->get(index), isolate);
9460 } 9479 }
9461 } 9480 }
9462 9481
9463 const int length = frame->GetProvidedParametersCount(); 9482 const int length = frame->GetProvidedParametersCount();
9464 Handle<JSObject> arguments = Factory::NewArgumentsObject(function, length); 9483 Handle<JSObject> arguments = Factory::NewArgumentsObject(function, length);
9465 Handle<FixedArray> array = Factory::NewFixedArray(length); 9484 Handle<FixedArray> array = Factory::NewFixedArray(length);
9466 9485
9467 AssertNoAllocation no_gc; 9486 AssertNoAllocation no_gc;
9468 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); 9487 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc);
9469 for (int i = 0; i < length; i++) { 9488 for (int i = 0; i < length; i++) {
(...skipping 15 matching lines...) Expand all
9485 // stack frame. A function which calls eval with the code to evaluate is then 9504 // stack frame. A function which calls eval with the code to evaluate is then
9486 // compiled in this context and called in this context. As this context 9505 // compiled in this context and called in this context. As this context
9487 // replaces the context of the function on the stack frame a new (empty) 9506 // replaces the context of the function on the stack frame a new (empty)
9488 // function is created as well to be used as the closure for the context. 9507 // function is created as well to be used as the closure for the context.
9489 // This function and the context acts as replacements for the function on the 9508 // This function and the context acts as replacements for the function on the
9490 // stack frame presenting the same view of the values of parameters and 9509 // stack frame presenting the same view of the values of parameters and
9491 // local variables as if the piece of JavaScript was evaluated at the point 9510 // local variables as if the piece of JavaScript was evaluated at the point
9492 // where the function on the stack frame is currently stopped. 9511 // where the function on the stack frame is currently stopped.
9493 static Object* Runtime_DebugEvaluate(RUNTIME_CALLING_CONVENTION) { 9512 static Object* Runtime_DebugEvaluate(RUNTIME_CALLING_CONVENTION) {
9494 RUNTIME_GET_ISOLATE; 9513 RUNTIME_GET_ISOLATE;
9495 HandleScope scope; 9514 HandleScope scope(isolate);
9496 9515
9497 // Check the execution state and decode arguments frame and source to be 9516 // Check the execution state and decode arguments frame and source to be
9498 // evaluated. 9517 // evaluated.
9499 ASSERT(args.length() == 4); 9518 ASSERT(args.length() == 4);
9500 Object* check_result = Runtime_CheckExecutionState(args, isolate); 9519 Object* check_result = Runtime_CheckExecutionState(args, isolate);
9501 if (check_result->IsFailure()) return check_result; 9520 if (check_result->IsFailure()) return check_result;
9502 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 9521 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
9503 CONVERT_ARG_CHECKED(String, source, 2); 9522 CONVERT_ARG_CHECKED(String, source, 2);
9504 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); 9523 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]);
9505 9524
(...skipping 27 matching lines...) Expand all
9533 Handle<JSFunction> go_between = 9552 Handle<JSFunction> go_between =
9534 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value()); 9553 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value());
9535 go_between->set_context(function->context()); 9554 go_between->set_context(function->context());
9536 #ifdef DEBUG 9555 #ifdef DEBUG
9537 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info()); 9556 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info());
9538 ASSERT(go_between_sinfo.number_of_parameters() == 0); 9557 ASSERT(go_between_sinfo.number_of_parameters() == 0);
9539 ASSERT(go_between_sinfo.number_of_context_slots() == 0); 9558 ASSERT(go_between_sinfo.number_of_context_slots() == 0);
9540 #endif 9559 #endif
9541 9560
9542 // Materialize the content of the local scope into a JSObject. 9561 // Materialize the content of the local scope into a JSObject.
9543 Handle<JSObject> local_scope = MaterializeLocalScope(isolate->heap(), frame); 9562 Handle<JSObject> local_scope = MaterializeLocalScope(isolate, frame);
9544 9563
9545 // Allocate a new context for the debug evaluation and set the extension 9564 // Allocate a new context for the debug evaluation and set the extension
9546 // object build. 9565 // object build.
9547 Handle<Context> context = 9566 Handle<Context> context =
9548 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); 9567 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between);
9549 context->set_extension(*local_scope); 9568 context->set_extension(*local_scope);
9550 // Copy any with contexts present and chain them in front of this context. 9569 // Copy any with contexts present and chain them in front of this context.
9551 Handle<Context> frame_context(Context::cast(frame->context())); 9570 Handle<Context> frame_context(Context::cast(frame->context()));
9552 Handle<Context> function_context(frame_context->fcontext()); 9571 Handle<Context> function_context(frame_context->fcontext());
9553 context = CopyWithContextChain(frame_context, context); 9572 context = CopyWithContextChain(frame_context, context);
(...skipping 12 matching lines...) Expand all
9566 Compiler::CompileEval(function_source, 9585 Compiler::CompileEval(function_source,
9567 context, 9586 context,
9568 context->IsGlobalContext(), 9587 context->IsGlobalContext(),
9569 Compiler::DONT_VALIDATE_JSON); 9588 Compiler::DONT_VALIDATE_JSON);
9570 if (shared.is_null()) return Failure::Exception(); 9589 if (shared.is_null()) return Failure::Exception();
9571 Handle<JSFunction> compiled_function = 9590 Handle<JSFunction> compiled_function =
9572 Factory::NewFunctionFromSharedFunctionInfo(shared, context); 9591 Factory::NewFunctionFromSharedFunctionInfo(shared, context);
9573 9592
9574 // Invoke the result of the compilation to get the evaluation function. 9593 // Invoke the result of the compilation to get the evaluation function.
9575 bool has_pending_exception; 9594 bool has_pending_exception;
9576 Handle<Object> receiver(frame->receiver()); 9595 Handle<Object> receiver(frame->receiver(), isolate);
9577 Handle<Object> evaluation_function = 9596 Handle<Object> evaluation_function =
9578 Execution::Call(compiled_function, receiver, 0, NULL, 9597 Execution::Call(compiled_function, receiver, 0, NULL,
9579 &has_pending_exception); 9598 &has_pending_exception);
9580 if (has_pending_exception) return Failure::Exception(); 9599 if (has_pending_exception) return Failure::Exception();
9581 9600
9582 Handle<Object> arguments = GetArgumentsObject(isolate->heap(), frame, 9601 Handle<Object> arguments = GetArgumentsObject(isolate, frame,
9583 function, scope_info, 9602 function, scope_info,
9584 &sinfo, function_context); 9603 &sinfo, function_context);
9585 9604
9586 // Invoke the evaluation function and return the result. 9605 // Invoke the evaluation function and return the result.
9587 const int argc = 2; 9606 const int argc = 2;
9588 Object** argv[argc] = { arguments.location(), 9607 Object** argv[argc] = { arguments.location(),
9589 Handle<Object>::cast(source).location() }; 9608 Handle<Object>::cast(source).location() };
9590 Handle<Object> result = 9609 Handle<Object> result =
9591 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver, 9610 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver,
9592 argc, argv, &has_pending_exception); 9611 argc, argv, &has_pending_exception);
9593 if (has_pending_exception) return Failure::Exception(); 9612 if (has_pending_exception) return Failure::Exception();
9594 9613
9595 // Skip the global proxy as it has no properties and always delegates to the 9614 // Skip the global proxy as it has no properties and always delegates to the
9596 // real global object. 9615 // real global object.
9597 if (result->IsJSGlobalProxy()) { 9616 if (result->IsJSGlobalProxy()) {
9598 result = Handle<JSObject>(JSObject::cast(result->GetPrototype())); 9617 result = Handle<JSObject>(JSObject::cast(result->GetPrototype()));
9599 } 9618 }
9600 9619
9601 return *result; 9620 return *result;
9602 } 9621 }
9603 9622
9604 9623
9605 static Object* Runtime_DebugEvaluateGlobal(RUNTIME_CALLING_CONVENTION) { 9624 static Object* Runtime_DebugEvaluateGlobal(RUNTIME_CALLING_CONVENTION) {
9606 RUNTIME_GET_ISOLATE; 9625 RUNTIME_GET_ISOLATE;
9607 HandleScope scope; 9626 HandleScope scope(isolate);
9608 9627
9609 // Check the execution state and decode arguments frame and source to be 9628 // Check the execution state and decode arguments frame and source to be
9610 // evaluated. 9629 // evaluated.
9611 ASSERT(args.length() == 3); 9630 ASSERT(args.length() == 3);
9612 Object* check_result = Runtime_CheckExecutionState(args, isolate); 9631 Object* check_result = Runtime_CheckExecutionState(args, isolate);
9613 if (check_result->IsFailure()) return check_result; 9632 if (check_result->IsFailure()) return check_result;
9614 CONVERT_ARG_CHECKED(String, source, 1); 9633 CONVERT_ARG_CHECKED(String, source, 1);
9615 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); 9634 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]);
9616 9635
9617 // Handle the processing of break. 9636 // Handle the processing of break.
(...skipping 30 matching lines...) Expand all
9648 Handle<Object> result = 9667 Handle<Object> result =
9649 Execution::Call(compiled_function, receiver, 0, NULL, 9668 Execution::Call(compiled_function, receiver, 0, NULL,
9650 &has_pending_exception); 9669 &has_pending_exception);
9651 if (has_pending_exception) return Failure::Exception(); 9670 if (has_pending_exception) return Failure::Exception();
9652 return *result; 9671 return *result;
9653 } 9672 }
9654 9673
9655 9674
9656 static Object* Runtime_DebugGetLoadedScripts(RUNTIME_CALLING_CONVENTION) { 9675 static Object* Runtime_DebugGetLoadedScripts(RUNTIME_CALLING_CONVENTION) {
9657 RUNTIME_GET_ISOLATE; 9676 RUNTIME_GET_ISOLATE;
9658 HandleScope scope; 9677 HandleScope scope(isolate);
9659 ASSERT(args.length() == 0); 9678 ASSERT(args.length() == 0);
9660 9679
9661 // Fill the script objects. 9680 // Fill the script objects.
9662 Handle<FixedArray> instances = isolate->debug()->GetLoadedScripts(); 9681 Handle<FixedArray> instances = isolate->debug()->GetLoadedScripts();
9663 9682
9664 // Convert the script objects to proper JS objects. 9683 // Convert the script objects to proper JS objects.
9665 for (int i = 0; i < instances->length(); i++) { 9684 for (int i = 0; i < instances->length(); i++) {
9666 Handle<Script> script = Handle<Script>(Script::cast(instances->get(i))); 9685 Handle<Script> script = Handle<Script>(Script::cast(instances->get(i)));
9667 // Get the script wrapper in a local handle before calling GetScriptWrapper, 9686 // Get the script wrapper in a local handle before calling GetScriptWrapper,
9668 // because using 9687 // because using
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
9881 RUNTIME_GET_ISOLATE; 9900 RUNTIME_GET_ISOLATE;
9882 ASSERT(args.length() == 0); 9901 ASSERT(args.length() == 0);
9883 CPU::DebugBreak(); 9902 CPU::DebugBreak();
9884 return isolate->heap()->undefined_value(); 9903 return isolate->heap()->undefined_value();
9885 } 9904 }
9886 9905
9887 9906
9888 static Object* Runtime_DebugDisassembleFunction(RUNTIME_CALLING_CONVENTION) { 9907 static Object* Runtime_DebugDisassembleFunction(RUNTIME_CALLING_CONVENTION) {
9889 RUNTIME_GET_ISOLATE; 9908 RUNTIME_GET_ISOLATE;
9890 #ifdef DEBUG 9909 #ifdef DEBUG
9891 HandleScope scope; 9910 HandleScope scope(isolate);
9892 ASSERT(args.length() == 1); 9911 ASSERT(args.length() == 1);
9893 // Get the function and make sure it is compiled. 9912 // Get the function and make sure it is compiled.
9894 CONVERT_ARG_CHECKED(JSFunction, func, 0); 9913 CONVERT_ARG_CHECKED(JSFunction, func, 0);
9895 Handle<SharedFunctionInfo> shared(func->shared()); 9914 Handle<SharedFunctionInfo> shared(func->shared());
9896 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { 9915 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) {
9897 return Failure::Exception(); 9916 return Failure::Exception();
9898 } 9917 }
9899 func->code()->PrintLn(); 9918 func->code()->PrintLn();
9900 #endif // DEBUG 9919 #endif // DEBUG
9901 return isolate->heap()->undefined_value(); 9920 return isolate->heap()->undefined_value();
9902 } 9921 }
9903 9922
9904 9923
9905 static Object* Runtime_DebugDisassembleConstructor(RUNTIME_CALLING_CONVENTION) { 9924 static Object* Runtime_DebugDisassembleConstructor(RUNTIME_CALLING_CONVENTION) {
9906 RUNTIME_GET_ISOLATE; 9925 RUNTIME_GET_ISOLATE;
9907 #ifdef DEBUG 9926 #ifdef DEBUG
9908 HandleScope scope; 9927 HandleScope scope(isolate);
9909 ASSERT(args.length() == 1); 9928 ASSERT(args.length() == 1);
9910 // Get the function and make sure it is compiled. 9929 // Get the function and make sure it is compiled.
9911 CONVERT_ARG_CHECKED(JSFunction, func, 0); 9930 CONVERT_ARG_CHECKED(JSFunction, func, 0);
9912 Handle<SharedFunctionInfo> shared(func->shared()); 9931 Handle<SharedFunctionInfo> shared(func->shared());
9913 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { 9932 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) {
9914 return Failure::Exception(); 9933 return Failure::Exception();
9915 } 9934 }
9916 shared->construct_stub()->PrintLn(); 9935 shared->construct_stub()->PrintLn();
9917 #endif // DEBUG 9936 #endif // DEBUG
9918 return isolate->heap()->undefined_value(); 9937 return isolate->heap()->undefined_value();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
9953 return counter; 9972 return counter;
9954 } 9973 }
9955 9974
9956 // For a script finds all SharedFunctionInfo's in the heap that points 9975 // For a script finds all SharedFunctionInfo's in the heap that points
9957 // to this script. Returns JSArray of SharedFunctionInfo wrapped 9976 // to this script. Returns JSArray of SharedFunctionInfo wrapped
9958 // in OpaqueReferences. 9977 // in OpaqueReferences.
9959 static Object* Runtime_LiveEditFindSharedFunctionInfosForScript( 9978 static Object* Runtime_LiveEditFindSharedFunctionInfosForScript(
9960 RUNTIME_CALLING_CONVENTION) { 9979 RUNTIME_CALLING_CONVENTION) {
9961 RUNTIME_GET_ISOLATE; 9980 RUNTIME_GET_ISOLATE;
9962 ASSERT(args.length() == 1); 9981 ASSERT(args.length() == 1);
9963 HandleScope scope; 9982 HandleScope scope(isolate);
9964 CONVERT_CHECKED(JSValue, script_value, args[0]); 9983 CONVERT_CHECKED(JSValue, script_value, args[0]);
9965 9984
9966 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); 9985 Handle<Script> script = Handle<Script>(Script::cast(script_value->value()));
9967 9986
9968 const int kBufferSize = 32; 9987 const int kBufferSize = 32;
9969 9988
9970 Handle<FixedArray> array; 9989 Handle<FixedArray> array;
9971 array = Factory::NewFixedArray(kBufferSize); 9990 array = Factory::NewFixedArray(kBufferSize);
9972 int number = FindSharedFunctionInfosForScript(*script, *array); 9991 int number = FindSharedFunctionInfosForScript(*script, *array);
9973 if (number > kBufferSize) { 9992 if (number > kBufferSize) {
(...skipping 12 matching lines...) Expand all
9986 // For a script calculates compilation information about all its functions. 10005 // For a script calculates compilation information about all its functions.
9987 // The script source is explicitly specified by the second argument. 10006 // The script source is explicitly specified by the second argument.
9988 // The source of the actual script is not used, however it is important that 10007 // The source of the actual script is not used, however it is important that
9989 // all generated code keeps references to this particular instance of script. 10008 // all generated code keeps references to this particular instance of script.
9990 // Returns a JSArray of compilation infos. The array is ordered so that 10009 // Returns a JSArray of compilation infos. The array is ordered so that
9991 // each function with all its descendant is always stored in a continues range 10010 // each function with all its descendant is always stored in a continues range
9992 // with the function itself going first. The root function is a script function. 10011 // with the function itself going first. The root function is a script function.
9993 static Object* Runtime_LiveEditGatherCompileInfo(RUNTIME_CALLING_CONVENTION) { 10012 static Object* Runtime_LiveEditGatherCompileInfo(RUNTIME_CALLING_CONVENTION) {
9994 RUNTIME_GET_ISOLATE; 10013 RUNTIME_GET_ISOLATE;
9995 ASSERT(args.length() == 2); 10014 ASSERT(args.length() == 2);
9996 HandleScope scope; 10015 HandleScope scope(isolate);
9997 CONVERT_CHECKED(JSValue, script, args[0]); 10016 CONVERT_CHECKED(JSValue, script, args[0]);
9998 CONVERT_ARG_CHECKED(String, source, 1); 10017 CONVERT_ARG_CHECKED(String, source, 1);
9999 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 10018 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
10000 10019
10001 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source); 10020 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source);
10002 10021
10003 if (isolate->has_pending_exception()) { 10022 if (isolate->has_pending_exception()) {
10004 return Failure::Exception(); 10023 return Failure::Exception();
10005 } 10024 }
10006 10025
10007 return result; 10026 return result;
10008 } 10027 }
10009 10028
10010 // Changes the source of the script to a new_source. 10029 // Changes the source of the script to a new_source.
10011 // If old_script_name is provided (i.e. is a String), also creates a copy of 10030 // If old_script_name is provided (i.e. is a String), also creates a copy of
10012 // the script with its original source and sends notification to debugger. 10031 // the script with its original source and sends notification to debugger.
10013 static Object* Runtime_LiveEditReplaceScript(RUNTIME_CALLING_CONVENTION) { 10032 static Object* Runtime_LiveEditReplaceScript(RUNTIME_CALLING_CONVENTION) {
10014 RUNTIME_GET_ISOLATE; 10033 RUNTIME_GET_ISOLATE;
10015 ASSERT(args.length() == 3); 10034 ASSERT(args.length() == 3);
10016 HandleScope scope; 10035 HandleScope scope(isolate);
10017 CONVERT_CHECKED(JSValue, original_script_value, args[0]); 10036 CONVERT_CHECKED(JSValue, original_script_value, args[0]);
10018 CONVERT_ARG_CHECKED(String, new_source, 1); 10037 CONVERT_ARG_CHECKED(String, new_source, 1);
10019 Handle<Object> old_script_name(args[2]); 10038 Handle<Object> old_script_name(args[2], isolate);
10020 10039
10021 CONVERT_CHECKED(Script, original_script_pointer, 10040 CONVERT_CHECKED(Script, original_script_pointer,
10022 original_script_value->value()); 10041 original_script_value->value());
10023 Handle<Script> original_script(original_script_pointer); 10042 Handle<Script> original_script(original_script_pointer);
10024 10043
10025 Object* old_script = LiveEdit::ChangeScriptSource(original_script, 10044 Object* old_script = LiveEdit::ChangeScriptSource(original_script,
10026 new_source, 10045 new_source,
10027 old_script_name); 10046 old_script_name);
10028 10047
10029 if (old_script->IsScript()) { 10048 if (old_script->IsScript()) {
10030 Handle<Script> script_handle(Script::cast(old_script)); 10049 Handle<Script> script_handle(Script::cast(old_script));
10031 return *(GetScriptWrapper(script_handle)); 10050 return *(GetScriptWrapper(script_handle));
10032 } else { 10051 } else {
10033 return isolate->heap()->null_value(); 10052 return isolate->heap()->null_value();
10034 } 10053 }
10035 } 10054 }
10036 10055
10037 // Replaces code of SharedFunctionInfo with a new one. 10056 // Replaces code of SharedFunctionInfo with a new one.
10038 static Object* Runtime_LiveEditReplaceFunctionCode(RUNTIME_CALLING_CONVENTION) { 10057 static Object* Runtime_LiveEditReplaceFunctionCode(RUNTIME_CALLING_CONVENTION) {
10039 RUNTIME_GET_ISOLATE; 10058 RUNTIME_GET_ISOLATE;
10040 ASSERT(args.length() == 2); 10059 ASSERT(args.length() == 2);
10041 HandleScope scope; 10060 HandleScope scope(isolate);
10042 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0); 10061 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0);
10043 CONVERT_ARG_CHECKED(JSArray, shared_info, 1); 10062 CONVERT_ARG_CHECKED(JSArray, shared_info, 1);
10044 10063
10045 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info); 10064 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info);
10046 } 10065 }
10047 10066
10048 // Connects SharedFunctionInfo to another script. 10067 // Connects SharedFunctionInfo to another script.
10049 static Object* Runtime_LiveEditFunctionSetScript(RUNTIME_CALLING_CONVENTION) { 10068 static Object* Runtime_LiveEditFunctionSetScript(RUNTIME_CALLING_CONVENTION) {
10050 RUNTIME_GET_ISOLATE; 10069 RUNTIME_GET_ISOLATE;
10051 ASSERT(args.length() == 2); 10070 ASSERT(args.length() == 2);
10052 HandleScope scope; 10071 HandleScope scope(isolate);
10053 Handle<Object> function_object(args[0]); 10072 Handle<Object> function_object(args[0], isolate);
10054 Handle<Object> script_object(args[1]); 10073 Handle<Object> script_object(args[1], isolate);
10055 10074
10056 if (function_object->IsJSValue()) { 10075 if (function_object->IsJSValue()) {
10057 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object); 10076 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object);
10058 if (script_object->IsJSValue()) { 10077 if (script_object->IsJSValue()) {
10059 CONVERT_CHECKED(Script, script, JSValue::cast(*script_object)->value()); 10078 CONVERT_CHECKED(Script, script, JSValue::cast(*script_object)->value());
10060 script_object = Handle<Object>(script); 10079 script_object = Handle<Object>(script, isolate);
10061 } 10080 }
10062 10081
10063 LiveEdit::SetFunctionScript(function_wrapper, script_object); 10082 LiveEdit::SetFunctionScript(function_wrapper, script_object);
10064 } else { 10083 } else {
10065 // Just ignore this. We may not have a SharedFunctionInfo for some functions 10084 // Just ignore this. We may not have a SharedFunctionInfo for some functions
10066 // and we check it in this function. 10085 // and we check it in this function.
10067 } 10086 }
10068 10087
10069 return isolate->heap()->undefined_value(); 10088 return isolate->heap()->undefined_value();
10070 } 10089 }
10071 10090
10072 10091
10073 // In a code of a parent function replaces original function as embedded object 10092 // In a code of a parent function replaces original function as embedded object
10074 // with a substitution one. 10093 // with a substitution one.
10075 static Object* Runtime_LiveEditReplaceRefToNestedFunction( 10094 static Object* Runtime_LiveEditReplaceRefToNestedFunction(
10076 RUNTIME_CALLING_CONVENTION) { 10095 RUNTIME_CALLING_CONVENTION) {
10077 RUNTIME_GET_ISOLATE; 10096 RUNTIME_GET_ISOLATE;
10078 ASSERT(args.length() == 3); 10097 ASSERT(args.length() == 3);
10079 HandleScope scope; 10098 HandleScope scope(isolate);
10080 10099
10081 CONVERT_ARG_CHECKED(JSValue, parent_wrapper, 0); 10100 CONVERT_ARG_CHECKED(JSValue, parent_wrapper, 0);
10082 CONVERT_ARG_CHECKED(JSValue, orig_wrapper, 1); 10101 CONVERT_ARG_CHECKED(JSValue, orig_wrapper, 1);
10083 CONVERT_ARG_CHECKED(JSValue, subst_wrapper, 2); 10102 CONVERT_ARG_CHECKED(JSValue, subst_wrapper, 2);
10084 10103
10085 LiveEdit::ReplaceRefToNestedFunction(parent_wrapper, orig_wrapper, 10104 LiveEdit::ReplaceRefToNestedFunction(parent_wrapper, orig_wrapper,
10086 subst_wrapper); 10105 subst_wrapper);
10087 10106
10088 return isolate->heap()->undefined_value(); 10107 return isolate->heap()->undefined_value();
10089 } 10108 }
10090 10109
10091 10110
10092 // Updates positions of a shared function info (first parameter) according 10111 // Updates positions of a shared function info (first parameter) according
10093 // to script source change. Text change is described in second parameter as 10112 // to script source change. Text change is described in second parameter as
10094 // array of groups of 3 numbers: 10113 // array of groups of 3 numbers:
10095 // (change_begin, change_end, change_end_new_position). 10114 // (change_begin, change_end, change_end_new_position).
10096 // Each group describes a change in text; groups are sorted by change_begin. 10115 // Each group describes a change in text; groups are sorted by change_begin.
10097 static Object* Runtime_LiveEditPatchFunctionPositions( 10116 static Object* Runtime_LiveEditPatchFunctionPositions(
10098 RUNTIME_CALLING_CONVENTION) { 10117 RUNTIME_CALLING_CONVENTION) {
10099 RUNTIME_GET_ISOLATE; 10118 RUNTIME_GET_ISOLATE;
10100 ASSERT(args.length() == 2); 10119 ASSERT(args.length() == 2);
10101 HandleScope scope; 10120 HandleScope scope(isolate);
10102 CONVERT_ARG_CHECKED(JSArray, shared_array, 0); 10121 CONVERT_ARG_CHECKED(JSArray, shared_array, 0);
10103 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1); 10122 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1);
10104 10123
10105 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array); 10124 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array);
10106 } 10125 }
10107 10126
10108 10127
10109 // For array of SharedFunctionInfo's (each wrapped in JSValue) 10128 // For array of SharedFunctionInfo's (each wrapped in JSValue)
10110 // checks that none of them have activations on stacks (of any thread). 10129 // checks that none of them have activations on stacks (of any thread).
10111 // Returns array of the same length with corresponding results of 10130 // Returns array of the same length with corresponding results of
10112 // LiveEdit::FunctionPatchabilityStatus type. 10131 // LiveEdit::FunctionPatchabilityStatus type.
10113 static Object* Runtime_LiveEditCheckAndDropActivations( 10132 static Object* Runtime_LiveEditCheckAndDropActivations(
10114 RUNTIME_CALLING_CONVENTION) { 10133 RUNTIME_CALLING_CONVENTION) {
10115 RUNTIME_GET_ISOLATE; 10134 RUNTIME_GET_ISOLATE;
10116 ASSERT(args.length() == 2); 10135 ASSERT(args.length() == 2);
10117 HandleScope scope; 10136 HandleScope scope(isolate);
10118 CONVERT_ARG_CHECKED(JSArray, shared_array, 0); 10137 CONVERT_ARG_CHECKED(JSArray, shared_array, 0);
10119 CONVERT_BOOLEAN_CHECKED(do_drop, args[1]); 10138 CONVERT_BOOLEAN_CHECKED(do_drop, args[1]);
10120 10139
10121 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop); 10140 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop);
10122 } 10141 }
10123 10142
10124 // Compares 2 strings line-by-line and returns diff in form of JSArray of 10143 // Compares 2 strings line-by-line and returns diff in form of JSArray of
10125 // triplets (pos1, pos1_end, pos2_end) describing list of diff chunks. 10144 // triplets (pos1, pos1_end, pos2_end) describing list of diff chunks.
10126 static Object* Runtime_LiveEditCompareStringsLinewise( 10145 static Object* Runtime_LiveEditCompareStringsLinewise(
10127 RUNTIME_CALLING_CONVENTION) { 10146 RUNTIME_CALLING_CONVENTION) {
10128 RUNTIME_GET_ISOLATE; 10147 RUNTIME_GET_ISOLATE;
10129 ASSERT(args.length() == 2); 10148 ASSERT(args.length() == 2);
10130 HandleScope scope; 10149 HandleScope scope(isolate);
10131 CONVERT_ARG_CHECKED(String, s1, 0); 10150 CONVERT_ARG_CHECKED(String, s1, 0);
10132 CONVERT_ARG_CHECKED(String, s2, 1); 10151 CONVERT_ARG_CHECKED(String, s2, 1);
10133 10152
10134 return *LiveEdit::CompareStringsLinewise(s1, s2); 10153 return *LiveEdit::CompareStringsLinewise(s1, s2);
10135 } 10154 }
10136 10155
10137 10156
10138 10157
10139 // A testing entry. Returns statement position which is the closest to 10158 // A testing entry. Returns statement position which is the closest to
10140 // source_position. 10159 // source_position.
10141 static Object* Runtime_GetFunctionCodePositionFromSource( 10160 static Object* Runtime_GetFunctionCodePositionFromSource(
10142 RUNTIME_CALLING_CONVENTION) { 10161 RUNTIME_CALLING_CONVENTION) {
10143 RUNTIME_GET_ISOLATE; 10162 RUNTIME_GET_ISOLATE;
10144 ASSERT(args.length() == 2); 10163 ASSERT(args.length() == 2);
10145 HandleScope scope; 10164 HandleScope scope(isolate);
10146 CONVERT_ARG_CHECKED(JSFunction, function, 0); 10165 CONVERT_ARG_CHECKED(JSFunction, function, 0);
10147 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 10166 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
10148 10167
10149 Handle<Code> code(function->code()); 10168 Handle<Code> code(function->code());
10150 10169
10151 RelocIterator it(*code, 1 << RelocInfo::STATEMENT_POSITION); 10170 RelocIterator it(*code, 1 << RelocInfo::STATEMENT_POSITION);
10152 int closest_pc = 0; 10171 int closest_pc = 0;
10153 int distance = kMaxInt; 10172 int distance = kMaxInt;
10154 while (!it.done()) { 10173 while (!it.done()) {
10155 int statement_position = static_cast<int>(it.rinfo()->data()); 10174 int statement_position = static_cast<int>(it.rinfo()->data());
(...skipping 12 matching lines...) Expand all
10168 return Smi::FromInt(closest_pc); 10187 return Smi::FromInt(closest_pc);
10169 } 10188 }
10170 10189
10171 10190
10172 // Calls specified function with or without entering the debugger. 10191 // Calls specified function with or without entering the debugger.
10173 // This is used in unit tests to run code as if debugger is entered or simply 10192 // This is used in unit tests to run code as if debugger is entered or simply
10174 // to have a stack with C++ frame in the middle. 10193 // to have a stack with C++ frame in the middle.
10175 static Object* Runtime_ExecuteInDebugContext(RUNTIME_CALLING_CONVENTION) { 10194 static Object* Runtime_ExecuteInDebugContext(RUNTIME_CALLING_CONVENTION) {
10176 RUNTIME_GET_ISOLATE; 10195 RUNTIME_GET_ISOLATE;
10177 ASSERT(args.length() == 2); 10196 ASSERT(args.length() == 2);
10178 HandleScope scope; 10197 HandleScope scope(isolate);
10179 CONVERT_ARG_CHECKED(JSFunction, function, 0); 10198 CONVERT_ARG_CHECKED(JSFunction, function, 0);
10180 CONVERT_BOOLEAN_CHECKED(without_debugger, args[1]); 10199 CONVERT_BOOLEAN_CHECKED(without_debugger, args[1]);
10181 10200
10182 Handle<Object> result; 10201 Handle<Object> result;
10183 bool pending_exception; 10202 bool pending_exception;
10184 { 10203 {
10185 if (without_debugger) { 10204 if (without_debugger) {
10186 result = Execution::Call(function, isolate->global(), 0, NULL, 10205 result = Execution::Call(function, isolate->global(), 0, NULL,
10187 &pending_exception); 10206 &pending_exception);
10188 } else { 10207 } else {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
10258 // Return the script found. 10277 // Return the script found.
10259 return GetScriptWrapper(script); 10278 return GetScriptWrapper(script);
10260 } 10279 }
10261 10280
10262 10281
10263 // Get the script object from script data. NOTE: Regarding performance 10282 // Get the script object from script data. NOTE: Regarding performance
10264 // see the NOTE for GetScriptFromScriptData. 10283 // see the NOTE for GetScriptFromScriptData.
10265 // args[0]: script data for the script to find the source for 10284 // args[0]: script data for the script to find the source for
10266 static Object* Runtime_GetScript(RUNTIME_CALLING_CONVENTION) { 10285 static Object* Runtime_GetScript(RUNTIME_CALLING_CONVENTION) {
10267 RUNTIME_GET_ISOLATE; 10286 RUNTIME_GET_ISOLATE;
10268 HandleScope scope; 10287 HandleScope scope(isolate);
10269 10288
10270 ASSERT(args.length() == 1); 10289 ASSERT(args.length() == 1);
10271 10290
10272 CONVERT_CHECKED(String, script_name, args[0]); 10291 CONVERT_CHECKED(String, script_name, args[0]);
10273 10292
10274 // Find the requested script. 10293 // Find the requested script.
10275 Handle<Object> result = 10294 Handle<Object> result =
10276 Runtime_GetScriptFromScriptName(Handle<String>(script_name)); 10295 Runtime_GetScriptFromScriptName(Handle<String>(script_name));
10277 return *result; 10296 return *result;
10278 } 10297 }
(...skipping 29 matching lines...) Expand all
10308 10327
10309 // Collect the raw data for a stack trace. Returns an array of three 10328 // Collect the raw data for a stack trace. Returns an array of three
10310 // element segments each containing a receiver, function and native 10329 // element segments each containing a receiver, function and native
10311 // code offset. 10330 // code offset.
10312 static Object* Runtime_CollectStackTrace(RUNTIME_CALLING_CONVENTION) { 10331 static Object* Runtime_CollectStackTrace(RUNTIME_CALLING_CONVENTION) {
10313 RUNTIME_GET_ISOLATE; 10332 RUNTIME_GET_ISOLATE;
10314 ASSERT_EQ(args.length(), 2); 10333 ASSERT_EQ(args.length(), 2);
10315 Handle<Object> caller = args.at<Object>(0); 10334 Handle<Object> caller = args.at<Object>(0);
10316 CONVERT_NUMBER_CHECKED(int32_t, limit, Int32, args[1]); 10335 CONVERT_NUMBER_CHECKED(int32_t, limit, Int32, args[1]);
10317 10336
10318 HandleScope scope; 10337 HandleScope scope(isolate);
10319 10338
10320 limit = Max(limit, 0); // Ensure that limit is not negative. 10339 limit = Max(limit, 0); // Ensure that limit is not negative.
10321 int initial_size = Min(limit, 10); 10340 int initial_size = Min(limit, 10);
10322 Handle<JSArray> result = Factory::NewJSArray(initial_size * 3); 10341 Handle<JSArray> result = Factory::NewJSArray(initial_size * 3);
10323 10342
10324 StackFrameIterator iter; 10343 StackFrameIterator iter;
10325 // If the caller parameter is a function we skip frames until we're 10344 // If the caller parameter is a function we skip frames until we're
10326 // under it before starting to collect. 10345 // under it before starting to collect.
10327 bool seen_caller = !caller->IsJSFunction(); 10346 bool seen_caller = !caller->IsJSFunction();
10328 int cursor = 0; 10347 int cursor = 0;
10329 int frames_seen = 0; 10348 int frames_seen = 0;
10330 while (!iter.done() && frames_seen < limit) { 10349 while (!iter.done() && frames_seen < limit) {
10331 StackFrame* raw_frame = iter.frame(); 10350 StackFrame* raw_frame = iter.frame();
10332 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) { 10351 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) {
10333 frames_seen++; 10352 frames_seen++;
10334 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); 10353 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame);
10335 Object* recv = frame->receiver(); 10354 Object* recv = frame->receiver();
10336 Object* fun = frame->function(); 10355 Object* fun = frame->function();
10337 Address pc = frame->pc(); 10356 Address pc = frame->pc();
10338 Address start = frame->code()->address(); 10357 Address start = frame->code()->address();
10339 Smi* offset = Smi::FromInt(static_cast<int>(pc - start)); 10358 Smi* offset = Smi::FromInt(static_cast<int>(pc - start));
10340 FixedArray* elements = FixedArray::cast(result->elements()); 10359 FixedArray* elements = FixedArray::cast(result->elements());
10341 if (cursor + 2 < elements->length()) { 10360 if (cursor + 2 < elements->length()) {
10342 elements->set(cursor++, recv); 10361 elements->set(cursor++, recv);
10343 elements->set(cursor++, fun); 10362 elements->set(cursor++, fun);
10344 elements->set(cursor++, offset); 10363 elements->set(cursor++, offset);
10345 } else { 10364 } else {
10346 HandleScope scope; 10365 HandleScope scope(isolate);
10347 Handle<Object> recv_handle(recv); 10366 Handle<Object> recv_handle(recv, isolate);
10348 Handle<Object> fun_handle(fun); 10367 Handle<Object> fun_handle(fun, isolate);
10349 SetElement(result, cursor++, recv_handle); 10368 SetElement(result, cursor++, recv_handle);
10350 SetElement(result, cursor++, fun_handle); 10369 SetElement(result, cursor++, fun_handle);
10351 SetElement(result, cursor++, Handle<Smi>(offset)); 10370 SetElement(result, cursor++, Handle<Smi>(offset));
10352 } 10371 }
10353 } 10372 }
10354 iter.Advance(); 10373 iter.Advance();
10355 } 10374 }
10356 10375
10357 result->set_length(Smi::FromInt(cursor)); 10376 result->set_length(Smi::FromInt(cursor));
10358 return *result; 10377 return *result;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
10394 10413
10395 10414
10396 static Object* CacheMiss(Isolate* isolate, 10415 static Object* CacheMiss(Isolate* isolate,
10397 FixedArray* cache_obj, 10416 FixedArray* cache_obj,
10398 int index, 10417 int index,
10399 Object* key_obj) { 10418 Object* key_obj) {
10400 ASSERT(index % 2 == 0); // index of the key 10419 ASSERT(index % 2 == 0); // index of the key
10401 ASSERT(index >= JSFunctionResultCache::kEntriesIndex); 10420 ASSERT(index >= JSFunctionResultCache::kEntriesIndex);
10402 ASSERT(index < cache_obj->length()); 10421 ASSERT(index < cache_obj->length());
10403 10422
10404 HandleScope scope; 10423 HandleScope scope(isolate);
10405 10424
10406 Handle<FixedArray> cache(cache_obj); 10425 Handle<FixedArray> cache(cache_obj);
10407 Handle<Object> key(key_obj); 10426 Handle<Object> key(key_obj, isolate);
10408 Handle<JSFunction> factory(JSFunction::cast( 10427 Handle<JSFunction> factory(JSFunction::cast(
10409 cache->get(JSFunctionResultCache::kFactoryIndex))); 10428 cache->get(JSFunctionResultCache::kFactoryIndex)));
10410 // TODO(antonm): consider passing a receiver when constructing a cache. 10429 // TODO(antonm): consider passing a receiver when constructing a cache.
10411 Handle<Object> receiver(isolate->global_context()->global()); 10430 Handle<Object> receiver(isolate->global_context()->global(), isolate);
10412 10431
10413 Handle<Object> value; 10432 Handle<Object> value;
10414 { 10433 {
10415 // This handle is nor shared, nor used later, so it's safe. 10434 // This handle is nor shared, nor used later, so it's safe.
10416 Object** argv[] = { key.location() }; 10435 Object** argv[] = { key.location() };
10417 bool pending_exception = false; 10436 bool pending_exception = false;
10418 value = Execution::Call(factory, 10437 value = Execution::Call(factory,
10419 receiver, 10438 receiver,
10420 1, 10439 1,
10421 argv, 10440 argv,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
10481 return CacheMiss(isolate, cache, target_index, key); 10500 return CacheMiss(isolate, cache, target_index, key);
10482 } 10501 }
10483 } 10502 }
10484 10503
10485 #ifdef DEBUG 10504 #ifdef DEBUG
10486 // ListNatives is ONLY used by the fuzz-natives.js in debug mode 10505 // ListNatives is ONLY used by the fuzz-natives.js in debug mode
10487 // Exclude the code in release mode. 10506 // Exclude the code in release mode.
10488 static Object* Runtime_ListNatives(RUNTIME_CALLING_CONVENTION) { 10507 static Object* Runtime_ListNatives(RUNTIME_CALLING_CONVENTION) {
10489 RUNTIME_GET_ISOLATE; 10508 RUNTIME_GET_ISOLATE;
10490 ASSERT(args.length() == 0); 10509 ASSERT(args.length() == 0);
10491 HandleScope scope; 10510 HandleScope scope(isolate);
10492 Handle<JSArray> result = Factory::NewJSArray(0); 10511 Handle<JSArray> result = Factory::NewJSArray(0);
10493 int index = 0; 10512 int index = 0;
10494 bool inline_runtime_functions = false; 10513 bool inline_runtime_functions = false;
10495 #define ADD_ENTRY(Name, argc, ressize) \ 10514 #define ADD_ENTRY(Name, argc, ressize) \
10496 { \ 10515 { \
10497 HandleScope inner; \ 10516 HandleScope inner; \
10498 Handle<String> name; \ 10517 Handle<String> name; \
10499 /* Inline runtime functions have an underscore in front of the name. */ \ 10518 /* Inline runtime functions have an underscore in front of the name. */ \
10500 if (inline_runtime_functions) { \ 10519 if (inline_runtime_functions) { \
10501 name = Factory::NewStringFromAscii( \ 10520 name = Factory::NewStringFromAscii( \
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
10615 #define SETUP_RUNTIME_ENTRIES(Name, argc, resize) \ 10634 #define SETUP_RUNTIME_ENTRIES(Name, argc, resize) \
10616 entries_[lut_index].method = &CodeGenerator::Generate##Name; \ 10635 entries_[lut_index].method = &CodeGenerator::Generate##Name; \
10617 entries_[lut_index].name = "_" #Name; \ 10636 entries_[lut_index].name = "_" #Name; \
10618 entries_[lut_index++].nargs = argc; 10637 entries_[lut_index++].nargs = argc;
10619 INLINE_RUNTIME_FUNCTION_LIST(SETUP_RUNTIME_ENTRIES); 10638 INLINE_RUNTIME_FUNCTION_LIST(SETUP_RUNTIME_ENTRIES);
10620 #undef SETUP_RUNTIME_ENTRIES 10639 #undef SETUP_RUNTIME_ENTRIES
10621 } 10640 }
10622 10641
10623 10642
10624 } } // namespace v8::internal 10643 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/cctest/test-func-name-inference.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698