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

Side by Side Diff: src/runtime.cc

Issue 6880010: Merge (7265, 7271] from bleeding_edge to experimental/gc branch.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "smart-pointer.h" 52 #include "smart-pointer.h"
53 #include "stub-cache.h" 53 #include "stub-cache.h"
54 #include "v8threads.h" 54 #include "v8threads.h"
55 #include "string-search.h" 55 #include "string-search.h"
56 56
57 namespace v8 { 57 namespace v8 {
58 namespace internal { 58 namespace internal {
59 59
60 60
61 #define RUNTIME_ASSERT(value) \ 61 #define RUNTIME_ASSERT(value) \
62 if (!(value)) return Top::ThrowIllegalOperation(); 62 if (!(value)) return isolate->ThrowIllegalOperation();
63 63
64 // Cast the given object to a value of the specified type and store 64 // Cast the given object to a value of the specified type and store
65 // it in a variable with the given name. If the object is not of the 65 // it in a variable with the given name. If the object is not of the
66 // expected type call IllegalOperation and return. 66 // expected type call IllegalOperation and return.
67 #define CONVERT_CHECKED(Type, name, obj) \ 67 #define CONVERT_CHECKED(Type, name, obj) \
68 RUNTIME_ASSERT(obj->Is##Type()); \ 68 RUNTIME_ASSERT(obj->Is##Type()); \
69 Type* name = Type::cast(obj); 69 Type* name = Type::cast(obj);
70 70
71 #define CONVERT_ARG_CHECKED(Type, name, index) \ 71 #define CONVERT_ARG_CHECKED(Type, name, index) \
72 RUNTIME_ASSERT(args[index]->Is##Type()); \ 72 RUNTIME_ASSERT(args[index]->Is##Type()); \
(...skipping 20 matching lines...) Expand all
93 RUNTIME_ASSERT(obj->IsNumber()); \ 93 RUNTIME_ASSERT(obj->IsNumber()); \
94 double name = (obj)->Number(); 94 double name = (obj)->Number();
95 95
96 // Call the specified converter on the object *comand store the result in 96 // Call the specified converter on the object *comand store the result in
97 // a variable of the specified type with the given name. If the 97 // a variable of the specified type with the given name. If the
98 // object is not a Number call IllegalOperation and return. 98 // object is not a Number call IllegalOperation and return.
99 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \ 99 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \
100 RUNTIME_ASSERT(obj->IsNumber()); \ 100 RUNTIME_ASSERT(obj->IsNumber()); \
101 type name = NumberTo##Type(obj); 101 type name = NumberTo##Type(obj);
102 102
103 // Non-reentrant string buffer for efficient general use in this file.
104 static StaticResource<StringInputBuffer> runtime_string_input_buffer;
105 103
104 MUST_USE_RESULT static MaybeObject* DeepCopyBoilerplate(Isolate* isolate,
105 JSObject* boilerplate) {
106 StackLimitCheck check(isolate);
107 if (check.HasOverflowed()) return isolate->StackOverflow();
106 108
107 MUST_USE_RESULT static MaybeObject* DeepCopyBoilerplate(JSObject* boilerplate) { 109 Heap* heap = isolate->heap();
108 StackLimitCheck check;
109 if (check.HasOverflowed()) return Top::StackOverflow();
110
111 Object* result; 110 Object* result;
112 { MaybeObject* maybe_result = Heap::CopyJSObject(boilerplate); 111 { MaybeObject* maybe_result = heap->CopyJSObject(boilerplate);
113 if (!maybe_result->ToObject(&result)) return maybe_result; 112 if (!maybe_result->ToObject(&result)) return maybe_result;
114 } 113 }
115 JSObject* copy = JSObject::cast(result); 114 JSObject* copy = JSObject::cast(result);
116 115
117 // Deep copy local properties. 116 // Deep copy local properties.
118 if (copy->HasFastProperties()) { 117 if (copy->HasFastProperties()) {
119 FixedArray* properties = copy->properties(); 118 FixedArray* properties = copy->properties();
120 for (int i = 0; i < properties->length(); i++) { 119 for (int i = 0; i < properties->length(); i++) {
121 Object* value = properties->get(i); 120 Object* value = properties->get(i);
122 if (value->IsJSObject()) { 121 if (value->IsJSObject()) {
123 JSObject* js_object = JSObject::cast(value); 122 JSObject* js_object = JSObject::cast(value);
124 { MaybeObject* maybe_result = DeepCopyBoilerplate(js_object); 123 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, js_object);
125 if (!maybe_result->ToObject(&result)) return maybe_result; 124 if (!maybe_result->ToObject(&result)) return maybe_result;
126 } 125 }
127 properties->set(i, result); 126 properties->set(i, result);
128 } 127 }
129 } 128 }
130 int nof = copy->map()->inobject_properties(); 129 int nof = copy->map()->inobject_properties();
131 for (int i = 0; i < nof; i++) { 130 for (int i = 0; i < nof; i++) {
132 Object* value = copy->InObjectPropertyAt(i); 131 Object* value = copy->InObjectPropertyAt(i);
133 if (value->IsJSObject()) { 132 if (value->IsJSObject()) {
134 JSObject* js_object = JSObject::cast(value); 133 JSObject* js_object = JSObject::cast(value);
135 { MaybeObject* maybe_result = DeepCopyBoilerplate(js_object); 134 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, js_object);
136 if (!maybe_result->ToObject(&result)) return maybe_result; 135 if (!maybe_result->ToObject(&result)) return maybe_result;
137 } 136 }
138 copy->InObjectPropertyAtPut(i, result); 137 copy->InObjectPropertyAtPut(i, result);
139 } 138 }
140 } 139 }
141 } else { 140 } else {
142 { MaybeObject* maybe_result = 141 { MaybeObject* maybe_result =
143 Heap::AllocateFixedArray(copy->NumberOfLocalProperties(NONE)); 142 heap->AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
144 if (!maybe_result->ToObject(&result)) return maybe_result; 143 if (!maybe_result->ToObject(&result)) return maybe_result;
145 } 144 }
146 FixedArray* names = FixedArray::cast(result); 145 FixedArray* names = FixedArray::cast(result);
147 copy->GetLocalPropertyNames(names, 0); 146 copy->GetLocalPropertyNames(names, 0);
148 for (int i = 0; i < names->length(); i++) { 147 for (int i = 0; i < names->length(); i++) {
149 ASSERT(names->get(i)->IsString()); 148 ASSERT(names->get(i)->IsString());
150 String* key_string = String::cast(names->get(i)); 149 String* key_string = String::cast(names->get(i));
151 PropertyAttributes attributes = 150 PropertyAttributes attributes =
152 copy->GetLocalPropertyAttribute(key_string); 151 copy->GetLocalPropertyAttribute(key_string);
153 // Only deep copy fields from the object literal expression. 152 // Only deep copy fields from the object literal expression.
154 // In particular, don't try to copy the length attribute of 153 // In particular, don't try to copy the length attribute of
155 // an array. 154 // an array.
156 if (attributes != NONE) continue; 155 if (attributes != NONE) continue;
157 Object* value = 156 Object* value =
158 copy->GetProperty(key_string, &attributes)->ToObjectUnchecked(); 157 copy->GetProperty(key_string, &attributes)->ToObjectUnchecked();
159 if (value->IsJSObject()) { 158 if (value->IsJSObject()) {
160 JSObject* js_object = JSObject::cast(value); 159 JSObject* js_object = JSObject::cast(value);
161 { MaybeObject* maybe_result = DeepCopyBoilerplate(js_object); 160 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, js_object);
162 if (!maybe_result->ToObject(&result)) return maybe_result; 161 if (!maybe_result->ToObject(&result)) return maybe_result;
163 } 162 }
164 { MaybeObject* maybe_result = 163 { MaybeObject* maybe_result =
165 // Creating object copy for literals. No strict mode needed. 164 // Creating object copy for literals. No strict mode needed.
166 copy->SetProperty(key_string, result, NONE, kNonStrictMode); 165 copy->SetProperty(key_string, result, NONE, kNonStrictMode);
167 if (!maybe_result->ToObject(&result)) return maybe_result; 166 if (!maybe_result->ToObject(&result)) return maybe_result;
168 } 167 }
169 } 168 }
170 } 169 }
171 } 170 }
172 171
173 // Deep copy local elements. 172 // Deep copy local elements.
174 // Pixel elements cannot be created using an object literal. 173 // Pixel elements cannot be created using an object literal.
175 ASSERT(!copy->HasExternalArrayElements()); 174 ASSERT(!copy->HasExternalArrayElements());
176 switch (copy->GetElementsKind()) { 175 switch (copy->GetElementsKind()) {
177 case JSObject::FAST_ELEMENTS: { 176 case JSObject::FAST_ELEMENTS: {
178 FixedArray* elements = FixedArray::cast(copy->elements()); 177 FixedArray* elements = FixedArray::cast(copy->elements());
179 if (elements->map() == Heap::fixed_cow_array_map()) { 178 if (elements->map() == heap->fixed_cow_array_map()) {
180 Counters::cow_arrays_created_runtime.Increment(); 179 isolate->counters()->cow_arrays_created_runtime()->Increment();
181 #ifdef DEBUG 180 #ifdef DEBUG
182 for (int i = 0; i < elements->length(); i++) { 181 for (int i = 0; i < elements->length(); i++) {
183 ASSERT(!elements->get(i)->IsJSObject()); 182 ASSERT(!elements->get(i)->IsJSObject());
184 } 183 }
185 #endif 184 #endif
186 } else { 185 } else {
187 for (int i = 0; i < elements->length(); i++) { 186 for (int i = 0; i < elements->length(); i++) {
188 Object* value = elements->get(i); 187 Object* value = elements->get(i);
189 if (value->IsJSObject()) { 188 if (value->IsJSObject()) {
190 JSObject* js_object = JSObject::cast(value); 189 JSObject* js_object = JSObject::cast(value);
191 { MaybeObject* maybe_result = DeepCopyBoilerplate(js_object); 190 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate,
191 js_object);
192 if (!maybe_result->ToObject(&result)) return maybe_result; 192 if (!maybe_result->ToObject(&result)) return maybe_result;
193 } 193 }
194 elements->set(i, result); 194 elements->set(i, result);
195 } 195 }
196 } 196 }
197 } 197 }
198 break; 198 break;
199 } 199 }
200 case JSObject::DICTIONARY_ELEMENTS: { 200 case JSObject::DICTIONARY_ELEMENTS: {
201 NumberDictionary* element_dictionary = copy->element_dictionary(); 201 NumberDictionary* element_dictionary = copy->element_dictionary();
202 int capacity = element_dictionary->Capacity(); 202 int capacity = element_dictionary->Capacity();
203 for (int i = 0; i < capacity; i++) { 203 for (int i = 0; i < capacity; i++) {
204 Object* k = element_dictionary->KeyAt(i); 204 Object* k = element_dictionary->KeyAt(i);
205 if (element_dictionary->IsKey(k)) { 205 if (element_dictionary->IsKey(k)) {
206 Object* value = element_dictionary->ValueAt(i); 206 Object* value = element_dictionary->ValueAt(i);
207 if (value->IsJSObject()) { 207 if (value->IsJSObject()) {
208 JSObject* js_object = JSObject::cast(value); 208 JSObject* js_object = JSObject::cast(value);
209 { MaybeObject* maybe_result = DeepCopyBoilerplate(js_object); 209 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate,
210 js_object);
210 if (!maybe_result->ToObject(&result)) return maybe_result; 211 if (!maybe_result->ToObject(&result)) return maybe_result;
211 } 212 }
212 element_dictionary->ValueAtPut(i, result); 213 element_dictionary->ValueAtPut(i, result);
213 } 214 }
214 } 215 }
215 } 216 }
216 break; 217 break;
217 } 218 }
218 default: 219 default:
219 UNREACHABLE(); 220 UNREACHABLE();
220 break; 221 break;
221 } 222 }
222 return copy; 223 return copy;
223 } 224 }
224 225
225 226
226 static MaybeObject* Runtime_CloneLiteralBoilerplate(Arguments args) { 227 static MaybeObject* Runtime_CloneLiteralBoilerplate(
228 RUNTIME_CALLING_CONVENTION) {
229 RUNTIME_GET_ISOLATE;
227 CONVERT_CHECKED(JSObject, boilerplate, args[0]); 230 CONVERT_CHECKED(JSObject, boilerplate, args[0]);
228 return DeepCopyBoilerplate(boilerplate); 231 return DeepCopyBoilerplate(isolate, boilerplate);
229 } 232 }
230 233
231 234
232 static MaybeObject* Runtime_CloneShallowLiteralBoilerplate(Arguments args) { 235 static MaybeObject* Runtime_CloneShallowLiteralBoilerplate(
236 RUNTIME_CALLING_CONVENTION) {
237 RUNTIME_GET_ISOLATE;
233 CONVERT_CHECKED(JSObject, boilerplate, args[0]); 238 CONVERT_CHECKED(JSObject, boilerplate, args[0]);
234 return Heap::CopyJSObject(boilerplate); 239 return isolate->heap()->CopyJSObject(boilerplate);
235 } 240 }
236 241
237 242
238 static Handle<Map> ComputeObjectLiteralMap( 243 static Handle<Map> ComputeObjectLiteralMap(
239 Handle<Context> context, 244 Handle<Context> context,
240 Handle<FixedArray> constant_properties, 245 Handle<FixedArray> constant_properties,
241 bool* is_result_from_cache) { 246 bool* is_result_from_cache) {
247 Isolate* isolate = context->GetIsolate();
242 int properties_length = constant_properties->length(); 248 int properties_length = constant_properties->length();
243 int number_of_properties = properties_length / 2; 249 int number_of_properties = properties_length / 2;
244 if (FLAG_canonicalize_object_literal_maps) { 250 if (FLAG_canonicalize_object_literal_maps) {
245 // Check that there are only symbols and array indices among keys. 251 // Check that there are only symbols and array indices among keys.
246 int number_of_symbol_keys = 0; 252 int number_of_symbol_keys = 0;
247 for (int p = 0; p != properties_length; p += 2) { 253 for (int p = 0; p != properties_length; p += 2) {
248 Object* key = constant_properties->get(p); 254 Object* key = constant_properties->get(p);
249 uint32_t element_index = 0; 255 uint32_t element_index = 0;
250 if (key->IsSymbol()) { 256 if (key->IsSymbol()) {
251 number_of_symbol_keys++; 257 number_of_symbol_keys++;
252 } else if (key->ToArrayIndex(&element_index)) { 258 } else if (key->ToArrayIndex(&element_index)) {
253 // An index key does not require space in the property backing store. 259 // An index key does not require space in the property backing store.
254 number_of_properties--; 260 number_of_properties--;
255 } else { 261 } else {
256 // Bail out as a non-symbol non-index key makes caching impossible. 262 // Bail out as a non-symbol non-index key makes caching impossible.
257 // ASSERT to make sure that the if condition after the loop is false. 263 // ASSERT to make sure that the if condition after the loop is false.
258 ASSERT(number_of_symbol_keys != number_of_properties); 264 ASSERT(number_of_symbol_keys != number_of_properties);
259 break; 265 break;
260 } 266 }
261 } 267 }
262 // If we only have symbols and array indices among keys then we can 268 // If we only have symbols and array indices among keys then we can
263 // use the map cache in the global context. 269 // use the map cache in the global context.
264 const int kMaxKeys = 10; 270 const int kMaxKeys = 10;
265 if ((number_of_symbol_keys == number_of_properties) && 271 if ((number_of_symbol_keys == number_of_properties) &&
266 (number_of_symbol_keys < kMaxKeys)) { 272 (number_of_symbol_keys < kMaxKeys)) {
267 // Create the fixed array with the key. 273 // Create the fixed array with the key.
268 Handle<FixedArray> keys = Factory::NewFixedArray(number_of_symbol_keys); 274 Handle<FixedArray> keys =
275 isolate->factory()->NewFixedArray(number_of_symbol_keys);
269 if (number_of_symbol_keys > 0) { 276 if (number_of_symbol_keys > 0) {
270 int index = 0; 277 int index = 0;
271 for (int p = 0; p < properties_length; p += 2) { 278 for (int p = 0; p < properties_length; p += 2) {
272 Object* key = constant_properties->get(p); 279 Object* key = constant_properties->get(p);
273 if (key->IsSymbol()) { 280 if (key->IsSymbol()) {
274 keys->set(index++, key); 281 keys->set(index++, key);
275 } 282 }
276 } 283 }
277 ASSERT(index == number_of_symbol_keys); 284 ASSERT(index == number_of_symbol_keys);
278 } 285 }
279 *is_result_from_cache = true; 286 *is_result_from_cache = true;
280 return Factory::ObjectLiteralMapFromCache(context, keys); 287 return isolate->factory()->ObjectLiteralMapFromCache(context, keys);
281 } 288 }
282 } 289 }
283 *is_result_from_cache = false; 290 *is_result_from_cache = false;
284 return Factory::CopyMap( 291 return isolate->factory()->CopyMap(
285 Handle<Map>(context->object_function()->initial_map()), 292 Handle<Map>(context->object_function()->initial_map()),
286 number_of_properties); 293 number_of_properties);
287 } 294 }
288 295
289 296
290 static Handle<Object> CreateLiteralBoilerplate( 297 static Handle<Object> CreateLiteralBoilerplate(
298 Isolate* isolate,
291 Handle<FixedArray> literals, 299 Handle<FixedArray> literals,
292 Handle<FixedArray> constant_properties); 300 Handle<FixedArray> constant_properties);
293 301
294 302
295 static Handle<Object> CreateObjectLiteralBoilerplate( 303 static Handle<Object> CreateObjectLiteralBoilerplate(
304 Isolate* isolate,
296 Handle<FixedArray> literals, 305 Handle<FixedArray> literals,
297 Handle<FixedArray> constant_properties, 306 Handle<FixedArray> constant_properties,
298 bool should_have_fast_elements) { 307 bool should_have_fast_elements) {
299 // Get the global context from the literals array. This is the 308 // Get the global context from the literals array. This is the
300 // context in which the function was created and we use the object 309 // context in which the function was created and we use the object
301 // function from this context to create the object literal. We do 310 // function from this context to create the object literal. We do
302 // not use the object function from the current global context 311 // not use the object function from the current global context
303 // because this might be the object function from another context 312 // because this might be the object function from another context
304 // which we should not have access to. 313 // which we should not have access to.
305 Handle<Context> context = 314 Handle<Context> context =
306 Handle<Context>(JSFunction::GlobalContextFromLiterals(*literals)); 315 Handle<Context>(JSFunction::GlobalContextFromLiterals(*literals));
307 316
308 bool is_result_from_cache; 317 bool is_result_from_cache;
309 Handle<Map> map = ComputeObjectLiteralMap(context, 318 Handle<Map> map = ComputeObjectLiteralMap(context,
310 constant_properties, 319 constant_properties,
311 &is_result_from_cache); 320 &is_result_from_cache);
312 321
313 Handle<JSObject> boilerplate = Factory::NewJSObjectFromMap(map); 322 Handle<JSObject> boilerplate = isolate->factory()->NewJSObjectFromMap(map);
314 323
315 // Normalize the elements of the boilerplate to save space if needed. 324 // Normalize the elements of the boilerplate to save space if needed.
316 if (!should_have_fast_elements) NormalizeElements(boilerplate); 325 if (!should_have_fast_elements) NormalizeElements(boilerplate);
317 326
318 { // Add the constant properties to the boilerplate. 327 { // Add the constant properties to the boilerplate.
319 int length = constant_properties->length(); 328 int length = constant_properties->length();
320 OptimizedObjectForAddingMultipleProperties opt(boilerplate, 329 OptimizedObjectForAddingMultipleProperties opt(boilerplate,
321 length / 2, 330 length / 2,
322 !is_result_from_cache); 331 !is_result_from_cache);
323 for (int index = 0; index < length; index +=2) { 332 for (int index = 0; index < length; index +=2) {
324 Handle<Object> key(constant_properties->get(index+0)); 333 Handle<Object> key(constant_properties->get(index+0), isolate);
325 Handle<Object> value(constant_properties->get(index+1)); 334 Handle<Object> value(constant_properties->get(index+1), isolate);
326 if (value->IsFixedArray()) { 335 if (value->IsFixedArray()) {
327 // The value contains the constant_properties of a 336 // The value contains the constant_properties of a
328 // simple object literal. 337 // simple object literal.
329 Handle<FixedArray> array = Handle<FixedArray>::cast(value); 338 Handle<FixedArray> array = Handle<FixedArray>::cast(value);
330 value = CreateLiteralBoilerplate(literals, array); 339 value = CreateLiteralBoilerplate(isolate, literals, array);
331 if (value.is_null()) return value; 340 if (value.is_null()) return value;
332 } 341 }
333 Handle<Object> result; 342 Handle<Object> result;
334 uint32_t element_index = 0; 343 uint32_t element_index = 0;
335 if (key->IsSymbol()) { 344 if (key->IsSymbol()) {
336 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { 345 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) {
337 // Array index as string (uint32). 346 // Array index as string (uint32).
338 result = SetOwnElement(boilerplate, 347 result = SetOwnElement(boilerplate,
339 element_index, 348 element_index,
340 value, 349 value,
(...skipping 10 matching lines...) Expand all
351 element_index, 360 element_index,
352 value, 361 value,
353 kNonStrictMode); 362 kNonStrictMode);
354 } else { 363 } else {
355 // Non-uint32 number. 364 // Non-uint32 number.
356 ASSERT(key->IsNumber()); 365 ASSERT(key->IsNumber());
357 double num = key->Number(); 366 double num = key->Number();
358 char arr[100]; 367 char arr[100];
359 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 368 Vector<char> buffer(arr, ARRAY_SIZE(arr));
360 const char* str = DoubleToCString(num, buffer); 369 const char* str = DoubleToCString(num, buffer);
361 Handle<String> name = Factory::NewStringFromAscii(CStrVector(str)); 370 Handle<String> name =
371 isolate->factory()->NewStringFromAscii(CStrVector(str));
362 result = SetLocalPropertyIgnoreAttributes(boilerplate, name, 372 result = SetLocalPropertyIgnoreAttributes(boilerplate, name,
363 value, NONE); 373 value, NONE);
364 } 374 }
365 // If setting the property on the boilerplate throws an 375 // If setting the property on the boilerplate throws an
366 // exception, the exception is converted to an empty handle in 376 // exception, the exception is converted to an empty handle in
367 // the handle based operations. In that case, we need to 377 // the handle based operations. In that case, we need to
368 // convert back to an exception. 378 // convert back to an exception.
369 if (result.is_null()) return result; 379 if (result.is_null()) return result;
370 } 380 }
371 } 381 }
372 382
373 return boilerplate; 383 return boilerplate;
374 } 384 }
375 385
376 386
377 static Handle<Object> CreateArrayLiteralBoilerplate( 387 static Handle<Object> CreateArrayLiteralBoilerplate(
388 Isolate* isolate,
378 Handle<FixedArray> literals, 389 Handle<FixedArray> literals,
379 Handle<FixedArray> elements) { 390 Handle<FixedArray> elements) {
380 // Create the JSArray. 391 // Create the JSArray.
381 Handle<JSFunction> constructor( 392 Handle<JSFunction> constructor(
382 JSFunction::GlobalContextFromLiterals(*literals)->array_function()); 393 JSFunction::GlobalContextFromLiterals(*literals)->array_function());
383 Handle<Object> object = Factory::NewJSObject(constructor); 394 Handle<Object> object = isolate->factory()->NewJSObject(constructor);
384 395
385 const bool is_cow = (elements->map() == Heap::fixed_cow_array_map()); 396 const bool is_cow =
397 (elements->map() == isolate->heap()->fixed_cow_array_map());
386 Handle<FixedArray> copied_elements = 398 Handle<FixedArray> copied_elements =
387 is_cow ? elements : Factory::CopyFixedArray(elements); 399 is_cow ? elements : isolate->factory()->CopyFixedArray(elements);
388 400
389 Handle<FixedArray> content = Handle<FixedArray>::cast(copied_elements); 401 Handle<FixedArray> content = Handle<FixedArray>::cast(copied_elements);
390 if (is_cow) { 402 if (is_cow) {
391 #ifdef DEBUG 403 #ifdef DEBUG
392 // Copy-on-write arrays must be shallow (and simple). 404 // Copy-on-write arrays must be shallow (and simple).
393 for (int i = 0; i < content->length(); i++) { 405 for (int i = 0; i < content->length(); i++) {
394 ASSERT(!content->get(i)->IsFixedArray()); 406 ASSERT(!content->get(i)->IsFixedArray());
395 } 407 }
396 #endif 408 #endif
397 } else { 409 } else {
398 for (int i = 0; i < content->length(); i++) { 410 for (int i = 0; i < content->length(); i++) {
399 if (content->get(i)->IsFixedArray()) { 411 if (content->get(i)->IsFixedArray()) {
400 // The value contains the constant_properties of a 412 // The value contains the constant_properties of a
401 // simple object literal. 413 // simple object literal.
402 Handle<FixedArray> fa(FixedArray::cast(content->get(i))); 414 Handle<FixedArray> fa(FixedArray::cast(content->get(i)));
403 Handle<Object> result = 415 Handle<Object> result =
404 CreateLiteralBoilerplate(literals, fa); 416 CreateLiteralBoilerplate(isolate, literals, fa);
405 if (result.is_null()) return result; 417 if (result.is_null()) return result;
406 content->set(i, *result); 418 content->set(i, *result);
407 } 419 }
408 } 420 }
409 } 421 }
410 422
411 // Set the elements. 423 // Set the elements.
412 Handle<JSArray>::cast(object)->SetContent(*content); 424 Handle<JSArray>::cast(object)->SetContent(*content);
413 return object; 425 return object;
414 } 426 }
415 427
416 428
417 static Handle<Object> CreateLiteralBoilerplate( 429 static Handle<Object> CreateLiteralBoilerplate(
430 Isolate* isolate,
418 Handle<FixedArray> literals, 431 Handle<FixedArray> literals,
419 Handle<FixedArray> array) { 432 Handle<FixedArray> array) {
420 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); 433 Handle<FixedArray> elements = CompileTimeValue::GetElements(array);
421 switch (CompileTimeValue::GetType(array)) { 434 switch (CompileTimeValue::GetType(array)) {
422 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: 435 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS:
423 return CreateObjectLiteralBoilerplate(literals, elements, true); 436 return CreateObjectLiteralBoilerplate(isolate, literals, elements, true);
424 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: 437 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS:
425 return CreateObjectLiteralBoilerplate(literals, elements, false); 438 return CreateObjectLiteralBoilerplate(isolate, literals, elements, false);
426 case CompileTimeValue::ARRAY_LITERAL: 439 case CompileTimeValue::ARRAY_LITERAL:
427 return CreateArrayLiteralBoilerplate(literals, elements); 440 return CreateArrayLiteralBoilerplate(isolate, literals, elements);
428 default: 441 default:
429 UNREACHABLE(); 442 UNREACHABLE();
430 return Handle<Object>::null(); 443 return Handle<Object>::null();
431 } 444 }
432 } 445 }
433 446
434 447
435 static MaybeObject* Runtime_CreateArrayLiteralBoilerplate(Arguments args) { 448 static MaybeObject* Runtime_CreateArrayLiteralBoilerplate(
449 RUNTIME_CALLING_CONVENTION) {
450 RUNTIME_GET_ISOLATE;
436 // Takes a FixedArray of elements containing the literal elements of 451 // Takes a FixedArray of elements containing the literal elements of
437 // the array literal and produces JSArray with those elements. 452 // the array literal and produces JSArray with those elements.
438 // Additionally takes the literals array of the surrounding function 453 // Additionally takes the literals array of the surrounding function
439 // which contains the context from which to get the Array function 454 // which contains the context from which to get the Array function
440 // to use for creating the array literal. 455 // to use for creating the array literal.
441 HandleScope scope; 456 HandleScope scope(isolate);
442 ASSERT(args.length() == 3); 457 ASSERT(args.length() == 3);
443 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 458 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
444 CONVERT_SMI_CHECKED(literals_index, args[1]); 459 CONVERT_SMI_CHECKED(literals_index, args[1]);
445 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 460 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
446 461
447 Handle<Object> object = CreateArrayLiteralBoilerplate(literals, elements); 462 Handle<Object> object =
463 CreateArrayLiteralBoilerplate(isolate, literals, elements);
448 if (object.is_null()) return Failure::Exception(); 464 if (object.is_null()) return Failure::Exception();
449 465
450 // Update the functions literal and return the boilerplate. 466 // Update the functions literal and return the boilerplate.
451 literals->set(literals_index, *object); 467 literals->set(literals_index, *object);
452 return *object; 468 return *object;
453 } 469 }
454 470
455 471
456 static MaybeObject* Runtime_CreateObjectLiteral(Arguments args) { 472 static MaybeObject* Runtime_CreateObjectLiteral(RUNTIME_CALLING_CONVENTION) {
457 HandleScope scope; 473 RUNTIME_GET_ISOLATE;
474 HandleScope scope(isolate);
458 ASSERT(args.length() == 4); 475 ASSERT(args.length() == 4);
459 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 476 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
460 CONVERT_SMI_CHECKED(literals_index, args[1]); 477 CONVERT_SMI_CHECKED(literals_index, args[1]);
461 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2); 478 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2);
462 CONVERT_SMI_CHECKED(fast_elements, args[3]); 479 CONVERT_SMI_CHECKED(fast_elements, args[3]);
463 bool should_have_fast_elements = fast_elements == 1; 480 bool should_have_fast_elements = fast_elements == 1;
464 481
465 // Check if boilerplate exists. If not, create it first. 482 // Check if boilerplate exists. If not, create it first.
466 Handle<Object> boilerplate(literals->get(literals_index)); 483 Handle<Object> boilerplate(literals->get(literals_index), isolate);
467 if (*boilerplate == Heap::undefined_value()) { 484 if (*boilerplate == isolate->heap()->undefined_value()) {
468 boilerplate = CreateObjectLiteralBoilerplate(literals, 485 boilerplate = CreateObjectLiteralBoilerplate(isolate,
486 literals,
469 constant_properties, 487 constant_properties,
470 should_have_fast_elements); 488 should_have_fast_elements);
471 if (boilerplate.is_null()) return Failure::Exception(); 489 if (boilerplate.is_null()) return Failure::Exception();
472 // Update the functions literal and return the boilerplate. 490 // Update the functions literal and return the boilerplate.
473 literals->set(literals_index, *boilerplate); 491 literals->set(literals_index, *boilerplate);
474 } 492 }
475 return DeepCopyBoilerplate(JSObject::cast(*boilerplate)); 493 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate));
476 } 494 }
477 495
478 496
479 static MaybeObject* Runtime_CreateObjectLiteralShallow(Arguments args) { 497 static MaybeObject* Runtime_CreateObjectLiteralShallow(
480 HandleScope scope; 498 RUNTIME_CALLING_CONVENTION) {
499 RUNTIME_GET_ISOLATE;
500 HandleScope scope(isolate);
481 ASSERT(args.length() == 4); 501 ASSERT(args.length() == 4);
482 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 502 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
483 CONVERT_SMI_CHECKED(literals_index, args[1]); 503 CONVERT_SMI_CHECKED(literals_index, args[1]);
484 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2); 504 CONVERT_ARG_CHECKED(FixedArray, constant_properties, 2);
485 CONVERT_SMI_CHECKED(fast_elements, args[3]); 505 CONVERT_SMI_CHECKED(fast_elements, args[3]);
486 bool should_have_fast_elements = fast_elements == 1; 506 bool should_have_fast_elements = fast_elements == 1;
487 507
488 // Check if boilerplate exists. If not, create it first. 508 // Check if boilerplate exists. If not, create it first.
489 Handle<Object> boilerplate(literals->get(literals_index)); 509 Handle<Object> boilerplate(literals->get(literals_index), isolate);
490 if (*boilerplate == Heap::undefined_value()) { 510 if (*boilerplate == isolate->heap()->undefined_value()) {
491 boilerplate = CreateObjectLiteralBoilerplate(literals, 511 boilerplate = CreateObjectLiteralBoilerplate(isolate,
512 literals,
492 constant_properties, 513 constant_properties,
493 should_have_fast_elements); 514 should_have_fast_elements);
494 if (boilerplate.is_null()) return Failure::Exception(); 515 if (boilerplate.is_null()) return Failure::Exception();
495 // Update the functions literal and return the boilerplate. 516 // Update the functions literal and return the boilerplate.
496 literals->set(literals_index, *boilerplate); 517 literals->set(literals_index, *boilerplate);
497 } 518 }
498 return Heap::CopyJSObject(JSObject::cast(*boilerplate)); 519 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate));
499 } 520 }
500 521
501 522
502 static MaybeObject* Runtime_CreateArrayLiteral(Arguments args) { 523 static MaybeObject* Runtime_CreateArrayLiteral(RUNTIME_CALLING_CONVENTION) {
503 HandleScope scope; 524 RUNTIME_GET_ISOLATE;
525 HandleScope scope(isolate);
504 ASSERT(args.length() == 3); 526 ASSERT(args.length() == 3);
505 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 527 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
506 CONVERT_SMI_CHECKED(literals_index, args[1]); 528 CONVERT_SMI_CHECKED(literals_index, args[1]);
507 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 529 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
508 530
509 // Check if boilerplate exists. If not, create it first. 531 // Check if boilerplate exists. If not, create it first.
510 Handle<Object> boilerplate(literals->get(literals_index)); 532 Handle<Object> boilerplate(literals->get(literals_index), isolate);
511 if (*boilerplate == Heap::undefined_value()) { 533 if (*boilerplate == isolate->heap()->undefined_value()) {
512 boilerplate = CreateArrayLiteralBoilerplate(literals, elements); 534 boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements);
513 if (boilerplate.is_null()) return Failure::Exception(); 535 if (boilerplate.is_null()) return Failure::Exception();
514 // Update the functions literal and return the boilerplate. 536 // Update the functions literal and return the boilerplate.
515 literals->set(literals_index, *boilerplate); 537 literals->set(literals_index, *boilerplate);
516 } 538 }
517 return DeepCopyBoilerplate(JSObject::cast(*boilerplate)); 539 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate));
518 } 540 }
519 541
520 542
521 static MaybeObject* Runtime_CreateArrayLiteralShallow(Arguments args) { 543 static MaybeObject* Runtime_CreateArrayLiteralShallow(
522 HandleScope scope; 544 RUNTIME_CALLING_CONVENTION) {
545 RUNTIME_GET_ISOLATE;
546 HandleScope scope(isolate);
523 ASSERT(args.length() == 3); 547 ASSERT(args.length() == 3);
524 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 548 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
525 CONVERT_SMI_CHECKED(literals_index, args[1]); 549 CONVERT_SMI_CHECKED(literals_index, args[1]);
526 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 550 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
527 551
528 // Check if boilerplate exists. If not, create it first. 552 // Check if boilerplate exists. If not, create it first.
529 Handle<Object> boilerplate(literals->get(literals_index)); 553 Handle<Object> boilerplate(literals->get(literals_index), isolate);
530 if (*boilerplate == Heap::undefined_value()) { 554 if (*boilerplate == isolate->heap()->undefined_value()) {
531 boilerplate = CreateArrayLiteralBoilerplate(literals, elements); 555 boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements);
532 if (boilerplate.is_null()) return Failure::Exception(); 556 if (boilerplate.is_null()) return Failure::Exception();
533 // Update the functions literal and return the boilerplate. 557 // Update the functions literal and return the boilerplate.
534 literals->set(literals_index, *boilerplate); 558 literals->set(literals_index, *boilerplate);
535 } 559 }
536 if (JSObject::cast(*boilerplate)->elements()->map() == 560 if (JSObject::cast(*boilerplate)->elements()->map() ==
537 Heap::fixed_cow_array_map()) { 561 isolate->heap()->fixed_cow_array_map()) {
538 Counters::cow_arrays_created_runtime.Increment(); 562 COUNTERS->cow_arrays_created_runtime()->Increment();
539 } 563 }
540 return Heap::CopyJSObject(JSObject::cast(*boilerplate)); 564 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate));
541 } 565 }
542 566
543 567
544 static MaybeObject* Runtime_CreateCatchExtensionObject(Arguments args) { 568 static MaybeObject* Runtime_CreateCatchExtensionObject(
569 RUNTIME_CALLING_CONVENTION) {
570 RUNTIME_GET_ISOLATE;
545 ASSERT(args.length() == 2); 571 ASSERT(args.length() == 2);
546 CONVERT_CHECKED(String, key, args[0]); 572 CONVERT_CHECKED(String, key, args[0]);
547 Object* value = args[1]; 573 Object* value = args[1];
548 // Create a catch context extension object. 574 // Create a catch context extension object.
549 JSFunction* constructor = 575 JSFunction* constructor =
550 Top::context()->global_context()->context_extension_function(); 576 isolate->context()->global_context()->
577 context_extension_function();
551 Object* object; 578 Object* object;
552 { MaybeObject* maybe_object = Heap::AllocateJSObject(constructor); 579 { MaybeObject* maybe_object = isolate->heap()->AllocateJSObject(constructor);
553 if (!maybe_object->ToObject(&object)) return maybe_object; 580 if (!maybe_object->ToObject(&object)) return maybe_object;
554 } 581 }
555 // Assign the exception value to the catch variable and make sure 582 // Assign the exception value to the catch variable and make sure
556 // that the catch variable is DontDelete. 583 // that the catch variable is DontDelete.
557 { MaybeObject* maybe_value = 584 { MaybeObject* maybe_value =
558 // Passing non-strict per ECMA-262 5th Ed. 12.14. Catch, bullet #4. 585 // Passing non-strict per ECMA-262 5th Ed. 12.14. Catch, bullet #4.
559 JSObject::cast(object)->SetProperty( 586 JSObject::cast(object)->SetProperty(
560 key, value, DONT_DELETE, kNonStrictMode); 587 key, value, DONT_DELETE, kNonStrictMode);
561 if (!maybe_value->ToObject(&value)) return maybe_value; 588 if (!maybe_value->ToObject(&value)) return maybe_value;
562 } 589 }
563 return object; 590 return object;
564 } 591 }
565 592
566 593
567 static MaybeObject* Runtime_ClassOf(Arguments args) { 594 static MaybeObject* Runtime_ClassOf(RUNTIME_CALLING_CONVENTION) {
595 RUNTIME_GET_ISOLATE;
568 NoHandleAllocation ha; 596 NoHandleAllocation ha;
569 ASSERT(args.length() == 1); 597 ASSERT(args.length() == 1);
570 Object* obj = args[0]; 598 Object* obj = args[0];
571 if (!obj->IsJSObject()) return Heap::null_value(); 599 if (!obj->IsJSObject()) return isolate->heap()->null_value();
572 return JSObject::cast(obj)->class_name(); 600 return JSObject::cast(obj)->class_name();
573 } 601 }
574 602
575 603
576 static MaybeObject* Runtime_IsInPrototypeChain(Arguments args) { 604 static MaybeObject* Runtime_IsInPrototypeChain(RUNTIME_CALLING_CONVENTION) {
605 RUNTIME_GET_ISOLATE;
577 NoHandleAllocation ha; 606 NoHandleAllocation ha;
578 ASSERT(args.length() == 2); 607 ASSERT(args.length() == 2);
579 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8). 608 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8).
580 Object* O = args[0]; 609 Object* O = args[0];
581 Object* V = args[1]; 610 Object* V = args[1];
582 while (true) { 611 while (true) {
583 Object* prototype = V->GetPrototype(); 612 Object* prototype = V->GetPrototype();
584 if (prototype->IsNull()) return Heap::false_value(); 613 if (prototype->IsNull()) return isolate->heap()->false_value();
585 if (O == prototype) return Heap::true_value(); 614 if (O == prototype) return isolate->heap()->true_value();
586 V = prototype; 615 V = prototype;
587 } 616 }
588 } 617 }
589 618
590 619
591 // Inserts an object as the hidden prototype of another object. 620 // Inserts an object as the hidden prototype of another object.
592 static MaybeObject* Runtime_SetHiddenPrototype(Arguments args) { 621 static MaybeObject* Runtime_SetHiddenPrototype(RUNTIME_CALLING_CONVENTION) {
622 RUNTIME_GET_ISOLATE;
593 NoHandleAllocation ha; 623 NoHandleAllocation ha;
594 ASSERT(args.length() == 2); 624 ASSERT(args.length() == 2);
595 CONVERT_CHECKED(JSObject, jsobject, args[0]); 625 CONVERT_CHECKED(JSObject, jsobject, args[0]);
596 CONVERT_CHECKED(JSObject, proto, args[1]); 626 CONVERT_CHECKED(JSObject, proto, args[1]);
597 627
598 // Sanity checks. The old prototype (that we are replacing) could 628 // Sanity checks. The old prototype (that we are replacing) could
599 // theoretically be null, but if it is not null then check that we 629 // theoretically be null, but if it is not null then check that we
600 // didn't already install a hidden prototype here. 630 // didn't already install a hidden prototype here.
601 RUNTIME_ASSERT(!jsobject->GetPrototype()->IsHeapObject() || 631 RUNTIME_ASSERT(!jsobject->GetPrototype()->IsHeapObject() ||
602 !HeapObject::cast(jsobject->GetPrototype())->map()->is_hidden_prototype()); 632 !HeapObject::cast(jsobject->GetPrototype())->map()->is_hidden_prototype());
(...skipping 17 matching lines...) Expand all
620 650
621 // Set proto's prototype to be the old prototype of the object. 651 // Set proto's prototype to be the old prototype of the object.
622 new_proto_map->set_prototype(jsobject->GetPrototype()); 652 new_proto_map->set_prototype(jsobject->GetPrototype());
623 proto->set_map(new_proto_map); 653 proto->set_map(new_proto_map);
624 new_proto_map->set_is_hidden_prototype(); 654 new_proto_map->set_is_hidden_prototype();
625 655
626 // Set the object's prototype to proto. 656 // Set the object's prototype to proto.
627 new_map->set_prototype(proto); 657 new_map->set_prototype(proto);
628 jsobject->set_map(new_map); 658 jsobject->set_map(new_map);
629 659
630 return Heap::undefined_value(); 660 return isolate->heap()->undefined_value();
631 } 661 }
632 662
633 663
634 static MaybeObject* Runtime_IsConstructCall(Arguments args) { 664 static MaybeObject* Runtime_IsConstructCall(RUNTIME_CALLING_CONVENTION) {
665 RUNTIME_GET_ISOLATE;
635 NoHandleAllocation ha; 666 NoHandleAllocation ha;
636 ASSERT(args.length() == 0); 667 ASSERT(args.length() == 0);
637 JavaScriptFrameIterator it; 668 JavaScriptFrameIterator it;
638 return Heap::ToBoolean(it.frame()->IsConstructor()); 669 return isolate->heap()->ToBoolean(it.frame()->IsConstructor());
639 } 670 }
640 671
641 672
642 // Recursively traverses hidden prototypes if property is not found 673 // Recursively traverses hidden prototypes if property is not found
643 static void GetOwnPropertyImplementation(JSObject* obj, 674 static void GetOwnPropertyImplementation(JSObject* obj,
644 String* name, 675 String* name,
645 LookupResult* result) { 676 LookupResult* result) {
646 obj->LocalLookupRealNamedProperty(name, result); 677 obj->LocalLookupRealNamedProperty(name, result);
647 678
648 if (!result->IsProperty()) { 679 if (!result->IsProperty()) {
(...skipping 26 matching lines...) Expand all
675 706
676 707
677 static bool CheckAccess(JSObject* obj, 708 static bool CheckAccess(JSObject* obj,
678 String* name, 709 String* name,
679 LookupResult* result, 710 LookupResult* result,
680 v8::AccessType access_type) { 711 v8::AccessType access_type) {
681 ASSERT(result->IsProperty()); 712 ASSERT(result->IsProperty());
682 713
683 JSObject* holder = result->holder(); 714 JSObject* holder = result->holder();
684 JSObject* current = obj; 715 JSObject* current = obj;
716 Isolate* isolate = obj->GetIsolate();
685 while (true) { 717 while (true) {
686 if (current->IsAccessCheckNeeded() && 718 if (current->IsAccessCheckNeeded() &&
687 !Top::MayNamedAccess(current, name, access_type)) { 719 !isolate->MayNamedAccess(current, name, access_type)) {
688 // Access check callback denied the access, but some properties 720 // Access check callback denied the access, but some properties
689 // can have a special permissions which override callbacks descision 721 // can have a special permissions which override callbacks descision
690 // (currently see v8::AccessControl). 722 // (currently see v8::AccessControl).
691 break; 723 break;
692 } 724 }
693 725
694 if (current == holder) { 726 if (current == holder) {
695 return true; 727 return true;
696 } 728 }
697 729
(...skipping 16 matching lines...) Expand all
714 if (CheckAccessException(result, access_type)) { 746 if (CheckAccessException(result, access_type)) {
715 return true; 747 return true;
716 } 748 }
717 } 749 }
718 break; 750 break;
719 } 751 }
720 default: 752 default:
721 break; 753 break;
722 } 754 }
723 755
724 Top::ReportFailedAccessCheck(current, access_type); 756 isolate->ReportFailedAccessCheck(current, access_type);
725 return false; 757 return false;
726 } 758 }
727 759
728 760
729 // TODO(1095): we should traverse hidden prototype hierachy as well. 761 // TODO(1095): we should traverse hidden prototype hierachy as well.
730 static bool CheckElementAccess(JSObject* obj, 762 static bool CheckElementAccess(JSObject* obj,
731 uint32_t index, 763 uint32_t index,
732 v8::AccessType access_type) { 764 v8::AccessType access_type) {
733 if (obj->IsAccessCheckNeeded() && 765 if (obj->IsAccessCheckNeeded() &&
734 !Top::MayIndexedAccess(obj, index, access_type)) { 766 !obj->GetIsolate()->MayIndexedAccess(obj, index, access_type)) {
735 return false; 767 return false;
736 } 768 }
737 769
738 return true; 770 return true;
739 } 771 }
740 772
741 773
742 // Enumerator used as indices into the array returned from GetOwnProperty 774 // Enumerator used as indices into the array returned from GetOwnProperty
743 enum PropertyDescriptorIndices { 775 enum PropertyDescriptorIndices {
744 IS_ACCESSOR_INDEX, 776 IS_ACCESSOR_INDEX,
745 VALUE_INDEX, 777 VALUE_INDEX,
746 GETTER_INDEX, 778 GETTER_INDEX,
747 SETTER_INDEX, 779 SETTER_INDEX,
748 WRITABLE_INDEX, 780 WRITABLE_INDEX,
749 ENUMERABLE_INDEX, 781 ENUMERABLE_INDEX,
750 CONFIGURABLE_INDEX, 782 CONFIGURABLE_INDEX,
751 DESCRIPTOR_SIZE 783 DESCRIPTOR_SIZE
752 }; 784 };
753 785
754 // Returns an array with the property description: 786 // Returns an array with the property description:
755 // if args[1] is not a property on args[0] 787 // if args[1] is not a property on args[0]
756 // returns undefined 788 // returns undefined
757 // if args[1] is a data property on args[0] 789 // if args[1] is a data property on args[0]
758 // [false, value, Writeable, Enumerable, Configurable] 790 // [false, value, Writeable, Enumerable, Configurable]
759 // if args[1] is an accessor on args[0] 791 // if args[1] is an accessor on args[0]
760 // [true, GetFunction, SetFunction, Enumerable, Configurable] 792 // [true, GetFunction, SetFunction, Enumerable, Configurable]
761 static MaybeObject* Runtime_GetOwnProperty(Arguments args) { 793 static MaybeObject* Runtime_GetOwnProperty(RUNTIME_CALLING_CONVENTION) {
794 RUNTIME_GET_ISOLATE;
762 ASSERT(args.length() == 2); 795 ASSERT(args.length() == 2);
763 HandleScope scope; 796 Heap* heap = isolate->heap();
764 Handle<FixedArray> elms = Factory::NewFixedArray(DESCRIPTOR_SIZE); 797 HandleScope scope(isolate);
765 Handle<JSArray> desc = Factory::NewJSArrayWithElements(elms); 798 Handle<FixedArray> elms = isolate->factory()->NewFixedArray(DESCRIPTOR_SIZE);
799 Handle<JSArray> desc = isolate->factory()->NewJSArrayWithElements(elms);
766 LookupResult result; 800 LookupResult result;
767 CONVERT_ARG_CHECKED(JSObject, obj, 0); 801 CONVERT_ARG_CHECKED(JSObject, obj, 0);
768 CONVERT_ARG_CHECKED(String, name, 1); 802 CONVERT_ARG_CHECKED(String, name, 1);
769 803
770 // This could be an element. 804 // This could be an element.
771 uint32_t index; 805 uint32_t index;
772 if (name->AsArrayIndex(&index)) { 806 if (name->AsArrayIndex(&index)) {
773 switch (obj->HasLocalElement(index)) { 807 switch (obj->HasLocalElement(index)) {
774 case JSObject::UNDEFINED_ELEMENT: 808 case JSObject::UNDEFINED_ELEMENT:
775 return Heap::undefined_value(); 809 return heap->undefined_value();
776 810
777 case JSObject::STRING_CHARACTER_ELEMENT: { 811 case JSObject::STRING_CHARACTER_ELEMENT: {
778 // Special handling of string objects according to ECMAScript 5 812 // Special handling of string objects according to ECMAScript 5
779 // 15.5.5.2. Note that this might be a string object with elements 813 // 15.5.5.2. Note that this might be a string object with elements
780 // other than the actual string value. This is covered by the 814 // other than the actual string value. This is covered by the
781 // subsequent cases. 815 // subsequent cases.
782 Handle<JSValue> js_value = Handle<JSValue>::cast(obj); 816 Handle<JSValue> js_value = Handle<JSValue>::cast(obj);
783 Handle<String> str(String::cast(js_value->value())); 817 Handle<String> str(String::cast(js_value->value()));
784 Handle<String> substr = SubString(str, index, index + 1, NOT_TENURED); 818 Handle<String> substr = SubString(str, index, index + 1, NOT_TENURED);
785 819
786 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 820 elms->set(IS_ACCESSOR_INDEX, heap->false_value());
787 elms->set(VALUE_INDEX, *substr); 821 elms->set(VALUE_INDEX, *substr);
788 elms->set(WRITABLE_INDEX, Heap::false_value()); 822 elms->set(WRITABLE_INDEX, heap->false_value());
789 elms->set(ENUMERABLE_INDEX, Heap::false_value()); 823 elms->set(ENUMERABLE_INDEX, heap->false_value());
790 elms->set(CONFIGURABLE_INDEX, Heap::false_value()); 824 elms->set(CONFIGURABLE_INDEX, heap->false_value());
791 return *desc; 825 return *desc;
792 } 826 }
793 827
794 case JSObject::INTERCEPTED_ELEMENT: 828 case JSObject::INTERCEPTED_ELEMENT:
795 case JSObject::FAST_ELEMENT: { 829 case JSObject::FAST_ELEMENT: {
796 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 830 elms->set(IS_ACCESSOR_INDEX, heap->false_value());
797 Handle<Object> value = GetElement(obj, index); 831 Handle<Object> value = GetElement(obj, index);
798 RETURN_IF_EMPTY_HANDLE(value); 832 RETURN_IF_EMPTY_HANDLE(isolate, value);
799 elms->set(VALUE_INDEX, *value); 833 elms->set(VALUE_INDEX, *value);
800 elms->set(WRITABLE_INDEX, Heap::true_value()); 834 elms->set(WRITABLE_INDEX, heap->true_value());
801 elms->set(ENUMERABLE_INDEX, Heap::true_value()); 835 elms->set(ENUMERABLE_INDEX, heap->true_value());
802 elms->set(CONFIGURABLE_INDEX, Heap::true_value()); 836 elms->set(CONFIGURABLE_INDEX, heap->true_value());
803 return *desc; 837 return *desc;
804 } 838 }
805 839
806 case JSObject::DICTIONARY_ELEMENT: { 840 case JSObject::DICTIONARY_ELEMENT: {
807 Handle<JSObject> holder = obj; 841 Handle<JSObject> holder = obj;
808 if (obj->IsJSGlobalProxy()) { 842 if (obj->IsJSGlobalProxy()) {
809 Object* proto = obj->GetPrototype(); 843 Object* proto = obj->GetPrototype();
810 if (proto->IsNull()) return Heap::undefined_value(); 844 if (proto->IsNull()) return heap->undefined_value();
811 ASSERT(proto->IsJSGlobalObject()); 845 ASSERT(proto->IsJSGlobalObject());
812 holder = Handle<JSObject>(JSObject::cast(proto)); 846 holder = Handle<JSObject>(JSObject::cast(proto));
813 } 847 }
814 NumberDictionary* dictionary = holder->element_dictionary(); 848 NumberDictionary* dictionary = holder->element_dictionary();
815 int entry = dictionary->FindEntry(index); 849 int entry = dictionary->FindEntry(index);
816 ASSERT(entry != NumberDictionary::kNotFound); 850 ASSERT(entry != NumberDictionary::kNotFound);
817 PropertyDetails details = dictionary->DetailsAt(entry); 851 PropertyDetails details = dictionary->DetailsAt(entry);
818 switch (details.type()) { 852 switch (details.type()) {
819 case CALLBACKS: { 853 case CALLBACKS: {
820 // This is an accessor property with getter and/or setter. 854 // This is an accessor property with getter and/or setter.
821 FixedArray* callbacks = 855 FixedArray* callbacks =
822 FixedArray::cast(dictionary->ValueAt(entry)); 856 FixedArray::cast(dictionary->ValueAt(entry));
823 elms->set(IS_ACCESSOR_INDEX, Heap::true_value()); 857 elms->set(IS_ACCESSOR_INDEX, heap->true_value());
824 if (CheckElementAccess(*obj, index, v8::ACCESS_GET)) { 858 if (CheckElementAccess(*obj, index, v8::ACCESS_GET)) {
825 elms->set(GETTER_INDEX, callbacks->get(0)); 859 elms->set(GETTER_INDEX, callbacks->get(0));
826 } 860 }
827 if (CheckElementAccess(*obj, index, v8::ACCESS_SET)) { 861 if (CheckElementAccess(*obj, index, v8::ACCESS_SET)) {
828 elms->set(SETTER_INDEX, callbacks->get(1)); 862 elms->set(SETTER_INDEX, callbacks->get(1));
829 } 863 }
830 break; 864 break;
831 } 865 }
832 case NORMAL: { 866 case NORMAL: {
833 // This is a data property. 867 // This is a data property.
834 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 868 elms->set(IS_ACCESSOR_INDEX, heap->false_value());
835 Handle<Object> value = GetElement(obj, index); 869 Handle<Object> value = GetElement(obj, index);
836 ASSERT(!value.is_null()); 870 ASSERT(!value.is_null());
837 elms->set(VALUE_INDEX, *value); 871 elms->set(VALUE_INDEX, *value);
838 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!details.IsReadOnly())); 872 elms->set(WRITABLE_INDEX, heap->ToBoolean(!details.IsReadOnly()));
839 break; 873 break;
840 } 874 }
841 default: 875 default:
842 UNREACHABLE(); 876 UNREACHABLE();
843 break; 877 break;
844 } 878 }
845 elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!details.IsDontEnum())); 879 elms->set(ENUMERABLE_INDEX, heap->ToBoolean(!details.IsDontEnum()));
846 elms->set(CONFIGURABLE_INDEX, Heap::ToBoolean(!details.IsDontDelete())); 880 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean(!details.IsDontDelete()));
847 return *desc; 881 return *desc;
848 } 882 }
849 } 883 }
850 } 884 }
851 885
852 // Use recursive implementation to also traverse hidden prototypes 886 // Use recursive implementation to also traverse hidden prototypes
853 GetOwnPropertyImplementation(*obj, *name, &result); 887 GetOwnPropertyImplementation(*obj, *name, &result);
854 888
855 if (!result.IsProperty()) { 889 if (!result.IsProperty()) {
856 return Heap::undefined_value(); 890 return heap->undefined_value();
857 } 891 }
858 892
859 if (!CheckAccess(*obj, *name, &result, v8::ACCESS_HAS)) { 893 if (!CheckAccess(*obj, *name, &result, v8::ACCESS_HAS)) {
860 return Heap::false_value(); 894 return heap->false_value();
861 } 895 }
862 896
863 elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!result.IsDontEnum())); 897 elms->set(ENUMERABLE_INDEX, heap->ToBoolean(!result.IsDontEnum()));
864 elms->set(CONFIGURABLE_INDEX, Heap::ToBoolean(!result.IsDontDelete())); 898 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean(!result.IsDontDelete()));
865 899
866 bool is_js_accessor = (result.type() == CALLBACKS) && 900 bool is_js_accessor = (result.type() == CALLBACKS) &&
867 (result.GetCallbackObject()->IsFixedArray()); 901 (result.GetCallbackObject()->IsFixedArray());
868 902
869 if (is_js_accessor) { 903 if (is_js_accessor) {
870 // __defineGetter__/__defineSetter__ callback. 904 // __defineGetter__/__defineSetter__ callback.
871 elms->set(IS_ACCESSOR_INDEX, Heap::true_value()); 905 elms->set(IS_ACCESSOR_INDEX, heap->true_value());
872 906
873 FixedArray* structure = FixedArray::cast(result.GetCallbackObject()); 907 FixedArray* structure = FixedArray::cast(result.GetCallbackObject());
874 if (CheckAccess(*obj, *name, &result, v8::ACCESS_GET)) { 908 if (CheckAccess(*obj, *name, &result, v8::ACCESS_GET)) {
875 elms->set(GETTER_INDEX, structure->get(0)); 909 elms->set(GETTER_INDEX, structure->get(0));
876 } 910 }
877 if (CheckAccess(*obj, *name, &result, v8::ACCESS_SET)) { 911 if (CheckAccess(*obj, *name, &result, v8::ACCESS_SET)) {
878 elms->set(SETTER_INDEX, structure->get(1)); 912 elms->set(SETTER_INDEX, structure->get(1));
879 } 913 }
880 } else { 914 } else {
881 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 915 elms->set(IS_ACCESSOR_INDEX, heap->false_value());
882 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!result.IsReadOnly())); 916 elms->set(WRITABLE_INDEX, heap->ToBoolean(!result.IsReadOnly()));
883 917
884 PropertyAttributes attrs; 918 PropertyAttributes attrs;
885 Object* value; 919 Object* value;
886 // GetProperty will check access and report any violations. 920 // GetProperty will check access and report any violations.
887 { MaybeObject* maybe_value = obj->GetProperty(*obj, &result, *name, &attrs); 921 { MaybeObject* maybe_value = obj->GetProperty(*obj, &result, *name, &attrs);
888 if (!maybe_value->ToObject(&value)) return maybe_value; 922 if (!maybe_value->ToObject(&value)) return maybe_value;
889 } 923 }
890 elms->set(VALUE_INDEX, value); 924 elms->set(VALUE_INDEX, value);
891 } 925 }
892 926
893 return *desc; 927 return *desc;
894 } 928 }
895 929
896 930
897 static MaybeObject* Runtime_PreventExtensions(Arguments args) { 931 static MaybeObject* Runtime_PreventExtensions(RUNTIME_CALLING_CONVENTION) {
932 RUNTIME_GET_ISOLATE;
898 ASSERT(args.length() == 1); 933 ASSERT(args.length() == 1);
899 CONVERT_CHECKED(JSObject, obj, args[0]); 934 CONVERT_CHECKED(JSObject, obj, args[0]);
900 return obj->PreventExtensions(); 935 return obj->PreventExtensions();
901 } 936 }
902 937
903 938
904 static MaybeObject* Runtime_IsExtensible(Arguments args) { 939 static MaybeObject* Runtime_IsExtensible(RUNTIME_CALLING_CONVENTION) {
940 RUNTIME_GET_ISOLATE;
905 ASSERT(args.length() == 1); 941 ASSERT(args.length() == 1);
906 CONVERT_CHECKED(JSObject, obj, args[0]); 942 CONVERT_CHECKED(JSObject, obj, args[0]);
907 if (obj->IsJSGlobalProxy()) { 943 if (obj->IsJSGlobalProxy()) {
908 Object* proto = obj->GetPrototype(); 944 Object* proto = obj->GetPrototype();
909 if (proto->IsNull()) return Heap::false_value(); 945 if (proto->IsNull()) return isolate->heap()->false_value();
910 ASSERT(proto->IsJSGlobalObject()); 946 ASSERT(proto->IsJSGlobalObject());
911 obj = JSObject::cast(proto); 947 obj = JSObject::cast(proto);
912 } 948 }
913 return obj->map()->is_extensible() ? Heap::true_value() 949 return obj->map()->is_extensible() ? isolate->heap()->true_value()
914 : Heap::false_value(); 950 : isolate->heap()->false_value();
915 } 951 }
916 952
917 953
918 static MaybeObject* Runtime_RegExpCompile(Arguments args) { 954 static MaybeObject* Runtime_RegExpCompile(RUNTIME_CALLING_CONVENTION) {
919 HandleScope scope; 955 RUNTIME_GET_ISOLATE;
956 HandleScope scope(isolate);
920 ASSERT(args.length() == 3); 957 ASSERT(args.length() == 3);
921 CONVERT_ARG_CHECKED(JSRegExp, re, 0); 958 CONVERT_ARG_CHECKED(JSRegExp, re, 0);
922 CONVERT_ARG_CHECKED(String, pattern, 1); 959 CONVERT_ARG_CHECKED(String, pattern, 1);
923 CONVERT_ARG_CHECKED(String, flags, 2); 960 CONVERT_ARG_CHECKED(String, flags, 2);
924 Handle<Object> result = RegExpImpl::Compile(re, pattern, flags); 961 Handle<Object> result = RegExpImpl::Compile(re, pattern, flags);
925 if (result.is_null()) return Failure::Exception(); 962 if (result.is_null()) return Failure::Exception();
926 return *result; 963 return *result;
927 } 964 }
928 965
929 966
930 static MaybeObject* Runtime_CreateApiFunction(Arguments args) { 967 static MaybeObject* Runtime_CreateApiFunction(RUNTIME_CALLING_CONVENTION) {
931 HandleScope scope; 968 RUNTIME_GET_ISOLATE;
969 HandleScope scope(isolate);
932 ASSERT(args.length() == 1); 970 ASSERT(args.length() == 1);
933 CONVERT_ARG_CHECKED(FunctionTemplateInfo, data, 0); 971 CONVERT_ARG_CHECKED(FunctionTemplateInfo, data, 0);
934 return *Factory::CreateApiFunction(data); 972 return *isolate->factory()->CreateApiFunction(data);
935 } 973 }
936 974
937 975
938 static MaybeObject* Runtime_IsTemplate(Arguments args) { 976 static MaybeObject* Runtime_IsTemplate(RUNTIME_CALLING_CONVENTION) {
977 RUNTIME_GET_ISOLATE;
939 ASSERT(args.length() == 1); 978 ASSERT(args.length() == 1);
940 Object* arg = args[0]; 979 Object* arg = args[0];
941 bool result = arg->IsObjectTemplateInfo() || arg->IsFunctionTemplateInfo(); 980 bool result = arg->IsObjectTemplateInfo() || arg->IsFunctionTemplateInfo();
942 return Heap::ToBoolean(result); 981 return isolate->heap()->ToBoolean(result);
943 } 982 }
944 983
945 984
946 static MaybeObject* Runtime_GetTemplateField(Arguments args) { 985 static MaybeObject* Runtime_GetTemplateField(RUNTIME_CALLING_CONVENTION) {
986 RUNTIME_GET_ISOLATE;
947 ASSERT(args.length() == 2); 987 ASSERT(args.length() == 2);
948 CONVERT_CHECKED(HeapObject, templ, args[0]); 988 CONVERT_CHECKED(HeapObject, templ, args[0]);
949 CONVERT_CHECKED(Smi, field, args[1]); 989 CONVERT_CHECKED(Smi, field, args[1]);
950 int index = field->value(); 990 int index = field->value();
951 int offset = index * kPointerSize + HeapObject::kHeaderSize; 991 int offset = index * kPointerSize + HeapObject::kHeaderSize;
952 InstanceType type = templ->map()->instance_type(); 992 InstanceType type = templ->map()->instance_type();
953 RUNTIME_ASSERT(type == FUNCTION_TEMPLATE_INFO_TYPE || 993 RUNTIME_ASSERT(type == FUNCTION_TEMPLATE_INFO_TYPE ||
954 type == OBJECT_TEMPLATE_INFO_TYPE); 994 type == OBJECT_TEMPLATE_INFO_TYPE);
955 RUNTIME_ASSERT(offset > 0); 995 RUNTIME_ASSERT(offset > 0);
956 if (type == FUNCTION_TEMPLATE_INFO_TYPE) { 996 if (type == FUNCTION_TEMPLATE_INFO_TYPE) {
957 RUNTIME_ASSERT(offset < FunctionTemplateInfo::kSize); 997 RUNTIME_ASSERT(offset < FunctionTemplateInfo::kSize);
958 } else { 998 } else {
959 RUNTIME_ASSERT(offset < ObjectTemplateInfo::kSize); 999 RUNTIME_ASSERT(offset < ObjectTemplateInfo::kSize);
960 } 1000 }
961 return *HeapObject::RawField(templ, offset); 1001 return *HeapObject::RawField(templ, offset);
962 } 1002 }
963 1003
964 1004
965 static MaybeObject* Runtime_DisableAccessChecks(Arguments args) { 1005 static MaybeObject* Runtime_DisableAccessChecks(RUNTIME_CALLING_CONVENTION) {
1006 RUNTIME_GET_ISOLATE;
966 ASSERT(args.length() == 1); 1007 ASSERT(args.length() == 1);
967 CONVERT_CHECKED(HeapObject, object, args[0]); 1008 CONVERT_CHECKED(HeapObject, object, args[0]);
968 Map* old_map = object->map(); 1009 Map* old_map = object->map();
969 bool needs_access_checks = old_map->is_access_check_needed(); 1010 bool needs_access_checks = old_map->is_access_check_needed();
970 if (needs_access_checks) { 1011 if (needs_access_checks) {
971 // Copy map so it won't interfere constructor's initial map. 1012 // Copy map so it won't interfere constructor's initial map.
972 Object* new_map; 1013 Object* new_map;
973 { MaybeObject* maybe_new_map = old_map->CopyDropTransitions(); 1014 { MaybeObject* maybe_new_map = old_map->CopyDropTransitions();
974 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; 1015 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map;
975 } 1016 }
976 1017
977 Map::cast(new_map)->set_is_access_check_needed(false); 1018 Map::cast(new_map)->set_is_access_check_needed(false);
978 object->set_map(Map::cast(new_map)); 1019 object->set_map(Map::cast(new_map));
979 } 1020 }
980 return needs_access_checks ? Heap::true_value() : Heap::false_value(); 1021 return needs_access_checks ? isolate->heap()->true_value()
1022 : isolate->heap()->false_value();
981 } 1023 }
982 1024
983 1025
984 static MaybeObject* Runtime_EnableAccessChecks(Arguments args) { 1026 static MaybeObject* Runtime_EnableAccessChecks(RUNTIME_CALLING_CONVENTION) {
1027 RUNTIME_GET_ISOLATE;
985 ASSERT(args.length() == 1); 1028 ASSERT(args.length() == 1);
986 CONVERT_CHECKED(HeapObject, object, args[0]); 1029 CONVERT_CHECKED(HeapObject, object, args[0]);
987 Map* old_map = object->map(); 1030 Map* old_map = object->map();
988 if (!old_map->is_access_check_needed()) { 1031 if (!old_map->is_access_check_needed()) {
989 // Copy map so it won't interfere constructor's initial map. 1032 // Copy map so it won't interfere constructor's initial map.
990 Object* new_map; 1033 Object* new_map;
991 { MaybeObject* maybe_new_map = old_map->CopyDropTransitions(); 1034 { MaybeObject* maybe_new_map = old_map->CopyDropTransitions();
992 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; 1035 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map;
993 } 1036 }
994 1037
995 Map::cast(new_map)->set_is_access_check_needed(true); 1038 Map::cast(new_map)->set_is_access_check_needed(true);
996 object->set_map(Map::cast(new_map)); 1039 object->set_map(Map::cast(new_map));
997 } 1040 }
998 return Heap::undefined_value(); 1041 return isolate->heap()->undefined_value();
999 } 1042 }
1000 1043
1001 1044
1002 static Failure* ThrowRedeclarationError(const char* type, Handle<String> name) { 1045 static Failure* ThrowRedeclarationError(Isolate* isolate,
1003 HandleScope scope; 1046 const char* type,
1004 Handle<Object> type_handle = Factory::NewStringFromAscii(CStrVector(type)); 1047 Handle<String> name) {
1048 HandleScope scope(isolate);
1049 Handle<Object> type_handle =
1050 isolate->factory()->NewStringFromAscii(CStrVector(type));
1005 Handle<Object> args[2] = { type_handle, name }; 1051 Handle<Object> args[2] = { type_handle, name };
1006 Handle<Object> error = 1052 Handle<Object> error =
1007 Factory::NewTypeError("redeclaration", HandleVector(args, 2)); 1053 isolate->factory()->NewTypeError("redeclaration", HandleVector(args, 2));
1008 return Top::Throw(*error); 1054 return isolate->Throw(*error);
1009 } 1055 }
1010 1056
1011 1057
1012 static MaybeObject* Runtime_DeclareGlobals(Arguments args) { 1058 static MaybeObject* Runtime_DeclareGlobals(RUNTIME_CALLING_CONVENTION) {
1059 RUNTIME_GET_ISOLATE;
1013 ASSERT(args.length() == 4); 1060 ASSERT(args.length() == 4);
1014 HandleScope scope; 1061 HandleScope scope(isolate);
1015 Handle<GlobalObject> global = Handle<GlobalObject>(Top::context()->global()); 1062 Handle<GlobalObject> global = Handle<GlobalObject>(
1063 isolate->context()->global());
1016 1064
1017 Handle<Context> context = args.at<Context>(0); 1065 Handle<Context> context = args.at<Context>(0);
1018 CONVERT_ARG_CHECKED(FixedArray, pairs, 1); 1066 CONVERT_ARG_CHECKED(FixedArray, pairs, 1);
1019 bool is_eval = Smi::cast(args[2])->value() == 1; 1067 bool is_eval = Smi::cast(args[2])->value() == 1;
1020 StrictModeFlag strict_mode = 1068 StrictModeFlag strict_mode =
1021 static_cast<StrictModeFlag>(Smi::cast(args[3])->value()); 1069 static_cast<StrictModeFlag>(Smi::cast(args[3])->value());
1022 ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode); 1070 ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode);
1023 1071
1024 // Compute the property attributes. According to ECMA-262, section 1072 // Compute the property attributes. According to ECMA-262, section
1025 // 13, page 71, the property must be read-only and 1073 // 13, page 71, the property must be read-only and
1026 // non-deletable. However, neither SpiderMonkey nor KJS creates the 1074 // non-deletable. However, neither SpiderMonkey nor KJS creates the
1027 // property as read-only, so we don't either. 1075 // property as read-only, so we don't either.
1028 PropertyAttributes base = is_eval ? NONE : DONT_DELETE; 1076 PropertyAttributes base = is_eval ? NONE : DONT_DELETE;
1029 1077
1030 // Traverse the name/value pairs and set the properties. 1078 // Traverse the name/value pairs and set the properties.
1031 int length = pairs->length(); 1079 int length = pairs->length();
1032 for (int i = 0; i < length; i += 2) { 1080 for (int i = 0; i < length; i += 2) {
1033 HandleScope scope; 1081 HandleScope scope(isolate);
1034 Handle<String> name(String::cast(pairs->get(i))); 1082 Handle<String> name(String::cast(pairs->get(i)));
1035 Handle<Object> value(pairs->get(i + 1)); 1083 Handle<Object> value(pairs->get(i + 1), isolate);
1036 1084
1037 // We have to declare a global const property. To capture we only 1085 // We have to declare a global const property. To capture we only
1038 // assign to it when evaluating the assignment for "const x = 1086 // assign to it when evaluating the assignment for "const x =
1039 // <expr>" the initial value is the hole. 1087 // <expr>" the initial value is the hole.
1040 bool is_const_property = value->IsTheHole(); 1088 bool is_const_property = value->IsTheHole();
1041 1089
1042 if (value->IsUndefined() || is_const_property) { 1090 if (value->IsUndefined() || is_const_property) {
1043 // Lookup the property in the global object, and don't set the 1091 // Lookup the property in the global object, and don't set the
1044 // value of the variable if the property is already there. 1092 // value of the variable if the property is already there.
1045 LookupResult lookup; 1093 LookupResult lookup;
1046 global->Lookup(*name, &lookup); 1094 global->Lookup(*name, &lookup);
1047 if (lookup.IsProperty()) { 1095 if (lookup.IsProperty()) {
1048 // Determine if the property is local by comparing the holder 1096 // Determine if the property is local by comparing the holder
1049 // against the global object. The information will be used to 1097 // against the global object. The information will be used to
1050 // avoid throwing re-declaration errors when declaring 1098 // avoid throwing re-declaration errors when declaring
1051 // variables or constants that exist in the prototype chain. 1099 // variables or constants that exist in the prototype chain.
1052 bool is_local = (*global == lookup.holder()); 1100 bool is_local = (*global == lookup.holder());
1053 // Get the property attributes and determine if the property is 1101 // Get the property attributes and determine if the property is
1054 // read-only. 1102 // read-only.
1055 PropertyAttributes attributes = global->GetPropertyAttribute(*name); 1103 PropertyAttributes attributes = global->GetPropertyAttribute(*name);
1056 bool is_read_only = (attributes & READ_ONLY) != 0; 1104 bool is_read_only = (attributes & READ_ONLY) != 0;
1057 if (lookup.type() == INTERCEPTOR) { 1105 if (lookup.type() == INTERCEPTOR) {
1058 // If the interceptor says the property is there, we 1106 // If the interceptor says the property is there, we
1059 // just return undefined without overwriting the property. 1107 // just return undefined without overwriting the property.
1060 // Otherwise, we continue to setting the property. 1108 // Otherwise, we continue to setting the property.
1061 if (attributes != ABSENT) { 1109 if (attributes != ABSENT) {
1062 // Check if the existing property conflicts with regards to const. 1110 // Check if the existing property conflicts with regards to const.
1063 if (is_local && (is_read_only || is_const_property)) { 1111 if (is_local && (is_read_only || is_const_property)) {
1064 const char* type = (is_read_only) ? "const" : "var"; 1112 const char* type = (is_read_only) ? "const" : "var";
1065 return ThrowRedeclarationError(type, name); 1113 return ThrowRedeclarationError(isolate, type, name);
1066 }; 1114 };
1067 // The property already exists without conflicting: Go to 1115 // The property already exists without conflicting: Go to
1068 // the next declaration. 1116 // the next declaration.
1069 continue; 1117 continue;
1070 } 1118 }
1071 // Fall-through and introduce the absent property by using 1119 // Fall-through and introduce the absent property by using
1072 // SetProperty. 1120 // SetProperty.
1073 } else { 1121 } else {
1074 // For const properties, we treat a callback with this name 1122 // For const properties, we treat a callback with this name
1075 // even in the prototype as a conflicting declaration. 1123 // even in the prototype as a conflicting declaration.
1076 if (is_const_property && (lookup.type() == CALLBACKS)) { 1124 if (is_const_property && (lookup.type() == CALLBACKS)) {
1077 return ThrowRedeclarationError("const", name); 1125 return ThrowRedeclarationError(isolate, "const", name);
1078 } 1126 }
1079 // Otherwise, we check for locally conflicting declarations. 1127 // Otherwise, we check for locally conflicting declarations.
1080 if (is_local && (is_read_only || is_const_property)) { 1128 if (is_local && (is_read_only || is_const_property)) {
1081 const char* type = (is_read_only) ? "const" : "var"; 1129 const char* type = (is_read_only) ? "const" : "var";
1082 return ThrowRedeclarationError(type, name); 1130 return ThrowRedeclarationError(isolate, type, name);
1083 } 1131 }
1084 // The property already exists without conflicting: Go to 1132 // The property already exists without conflicting: Go to
1085 // the next declaration. 1133 // the next declaration.
1086 continue; 1134 continue;
1087 } 1135 }
1088 } 1136 }
1089 } else { 1137 } else {
1090 // Copy the function and update its context. Use it as value. 1138 // Copy the function and update its context. Use it as value.
1091 Handle<SharedFunctionInfo> shared = 1139 Handle<SharedFunctionInfo> shared =
1092 Handle<SharedFunctionInfo>::cast(value); 1140 Handle<SharedFunctionInfo>::cast(value);
1093 Handle<JSFunction> function = 1141 Handle<JSFunction> function =
1094 Factory::NewFunctionFromSharedFunctionInfo(shared, context, TENURED); 1142 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
1143 context,
1144 TENURED);
1095 value = function; 1145 value = function;
1096 } 1146 }
1097 1147
1098 LookupResult lookup; 1148 LookupResult lookup;
1099 global->LocalLookup(*name, &lookup); 1149 global->LocalLookup(*name, &lookup);
1100 1150
1101 PropertyAttributes attributes = is_const_property 1151 PropertyAttributes attributes = is_const_property
1102 ? static_cast<PropertyAttributes>(base | READ_ONLY) 1152 ? static_cast<PropertyAttributes>(base | READ_ONLY)
1103 : base; 1153 : base;
1104 1154
1105 // There's a local property that we need to overwrite because 1155 // There's a local property that we need to overwrite because
1106 // we're either declaring a function or there's an interceptor 1156 // we're either declaring a function or there's an interceptor
1107 // that claims the property is absent. 1157 // that claims the property is absent.
1108 // 1158 //
1109 // Check for conflicting re-declarations. We cannot have 1159 // Check for conflicting re-declarations. We cannot have
1110 // conflicting types in case of intercepted properties because 1160 // conflicting types in case of intercepted properties because
1111 // they are absent. 1161 // they are absent.
1112 if (lookup.IsProperty() && 1162 if (lookup.IsProperty() &&
1113 (lookup.type() != INTERCEPTOR) && 1163 (lookup.type() != INTERCEPTOR) &&
1114 (lookup.IsReadOnly() || is_const_property)) { 1164 (lookup.IsReadOnly() || is_const_property)) {
1115 const char* type = (lookup.IsReadOnly()) ? "const" : "var"; 1165 const char* type = (lookup.IsReadOnly()) ? "const" : "var";
1116 return ThrowRedeclarationError(type, name); 1166 return ThrowRedeclarationError(isolate, type, name);
1117 } 1167 }
1118 1168
1119 // Safari does not allow the invocation of callback setters for 1169 // Safari does not allow the invocation of callback setters for
1120 // function declarations. To mimic this behavior, we do not allow 1170 // function declarations. To mimic this behavior, we do not allow
1121 // the invocation of setters for function values. This makes a 1171 // the invocation of setters for function values. This makes a
1122 // difference for global functions with the same names as event 1172 // difference for global functions with the same names as event
1123 // handlers such as "function onload() {}". Firefox does call the 1173 // handlers such as "function onload() {}". Firefox does call the
1124 // onload setter in those case and Safari does not. We follow 1174 // onload setter in those case and Safari does not. We follow
1125 // Safari for compatibility. 1175 // Safari for compatibility.
1126 if (value->IsJSFunction()) { 1176 if (value->IsJSFunction()) {
1127 // Do not change DONT_DELETE to false from true. 1177 // Do not change DONT_DELETE to false from true.
1128 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) { 1178 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) {
1129 attributes = static_cast<PropertyAttributes>( 1179 attributes = static_cast<PropertyAttributes>(
1130 attributes | (lookup.GetAttributes() & DONT_DELETE)); 1180 attributes | (lookup.GetAttributes() & DONT_DELETE));
1131 } 1181 }
1132 RETURN_IF_EMPTY_HANDLE(SetLocalPropertyIgnoreAttributes(global, 1182 RETURN_IF_EMPTY_HANDLE(isolate,
1183 SetLocalPropertyIgnoreAttributes(global,
1133 name, 1184 name,
1134 value, 1185 value,
1135 attributes)); 1186 attributes));
1136 } else { 1187 } else {
1137 RETURN_IF_EMPTY_HANDLE(SetProperty(global, 1188 RETURN_IF_EMPTY_HANDLE(isolate,
1189 SetProperty(global,
1138 name, 1190 name,
1139 value, 1191 value,
1140 attributes, 1192 attributes,
1141 strict_mode)); 1193 strict_mode));
1142 } 1194 }
1143 } 1195 }
1144 1196
1145 ASSERT(!Top::has_pending_exception()); 1197 ASSERT(!isolate->has_pending_exception());
1146 return Heap::undefined_value(); 1198 return isolate->heap()->undefined_value();
1147 } 1199 }
1148 1200
1149 1201
1150 static MaybeObject* Runtime_DeclareContextSlot(Arguments args) { 1202 static MaybeObject* Runtime_DeclareContextSlot(RUNTIME_CALLING_CONVENTION) {
1151 HandleScope scope; 1203 RUNTIME_GET_ISOLATE;
1204 HandleScope scope(isolate);
1152 ASSERT(args.length() == 4); 1205 ASSERT(args.length() == 4);
1153 1206
1154 CONVERT_ARG_CHECKED(Context, context, 0); 1207 CONVERT_ARG_CHECKED(Context, context, 0);
1155 Handle<String> name(String::cast(args[1])); 1208 Handle<String> name(String::cast(args[1]));
1156 PropertyAttributes mode = 1209 PropertyAttributes mode =
1157 static_cast<PropertyAttributes>(Smi::cast(args[2])->value()); 1210 static_cast<PropertyAttributes>(Smi::cast(args[2])->value());
1158 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE); 1211 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE);
1159 Handle<Object> initial_value(args[3]); 1212 Handle<Object> initial_value(args[3], isolate);
1160 1213
1161 // Declarations are always done in the function context. 1214 // Declarations are always done in the function context.
1162 context = Handle<Context>(context->fcontext()); 1215 context = Handle<Context>(context->fcontext());
1163 1216
1164 int index; 1217 int index;
1165 PropertyAttributes attributes; 1218 PropertyAttributes attributes;
1166 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; 1219 ContextLookupFlags flags = DONT_FOLLOW_CHAINS;
1167 Handle<Object> holder = 1220 Handle<Object> holder =
1168 context->Lookup(name, flags, &index, &attributes); 1221 context->Lookup(name, flags, &index, &attributes);
1169 1222
1170 if (attributes != ABSENT) { 1223 if (attributes != ABSENT) {
1171 // The name was declared before; check for conflicting 1224 // The name was declared before; check for conflicting
1172 // re-declarations: This is similar to the code in parser.cc in 1225 // re-declarations: This is similar to the code in parser.cc in
1173 // the AstBuildingParser::Declare function. 1226 // the AstBuildingParser::Declare function.
1174 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) { 1227 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) {
1175 // Functions are not read-only. 1228 // Functions are not read-only.
1176 ASSERT(mode != READ_ONLY || initial_value->IsTheHole()); 1229 ASSERT(mode != READ_ONLY || initial_value->IsTheHole());
1177 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var"; 1230 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var";
1178 return ThrowRedeclarationError(type, name); 1231 return ThrowRedeclarationError(isolate, type, name);
1179 } 1232 }
1180 1233
1181 // Initialize it if necessary. 1234 // Initialize it if necessary.
1182 if (*initial_value != NULL) { 1235 if (*initial_value != NULL) {
1183 if (index >= 0) { 1236 if (index >= 0) {
1184 // The variable or constant context slot should always be in 1237 // The variable or constant context slot should always be in
1185 // the function context or the arguments object. 1238 // the function context or the arguments object.
1186 if (holder->IsContext()) { 1239 if (holder->IsContext()) {
1187 ASSERT(holder.is_identical_to(context)); 1240 ASSERT(holder.is_identical_to(context));
1188 if (((attributes & READ_ONLY) == 0) || 1241 if (((attributes & READ_ONLY) == 0) ||
1189 context->get(index)->IsTheHole()) { 1242 context->get(index)->IsTheHole()) {
1190 context->set(index, *initial_value); 1243 context->set(index, *initial_value);
1191 } 1244 }
1192 } else { 1245 } else {
1193 // The holder is an arguments object. 1246 // The holder is an arguments object.
1194 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); 1247 Handle<JSObject> arguments(Handle<JSObject>::cast(holder));
1195 Handle<Object> result = SetElement(arguments, index, initial_value, 1248 Handle<Object> result = SetElement(arguments, index, initial_value,
1196 kNonStrictMode); 1249 kNonStrictMode);
1197 if (result.is_null()) return Failure::Exception(); 1250 if (result.is_null()) return Failure::Exception();
1198 } 1251 }
1199 } else { 1252 } else {
1200 // Slow case: The property is not in the FixedArray part of the context. 1253 // Slow case: The property is not in the FixedArray part of the context.
1201 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); 1254 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder);
1202 RETURN_IF_EMPTY_HANDLE( 1255 RETURN_IF_EMPTY_HANDLE(
1256 isolate,
1203 SetProperty(context_ext, name, initial_value, 1257 SetProperty(context_ext, name, initial_value,
1204 mode, kNonStrictMode)); 1258 mode, kNonStrictMode));
1205 } 1259 }
1206 } 1260 }
1207 1261
1208 } else { 1262 } else {
1209 // The property is not in the function context. It needs to be 1263 // The property is not in the function context. It needs to be
1210 // "declared" in the function context's extension context, or in the 1264 // "declared" in the function context's extension context, or in the
1211 // global context. 1265 // global context.
1212 Handle<JSObject> context_ext; 1266 Handle<JSObject> context_ext;
1213 if (context->has_extension()) { 1267 if (context->has_extension()) {
1214 // The function context's extension context exists - use it. 1268 // The function context's extension context exists - use it.
1215 context_ext = Handle<JSObject>(context->extension()); 1269 context_ext = Handle<JSObject>(context->extension());
1216 } else { 1270 } else {
1217 // The function context's extension context does not exists - allocate 1271 // The function context's extension context does not exists - allocate
1218 // it. 1272 // it.
1219 context_ext = Factory::NewJSObject(Top::context_extension_function()); 1273 context_ext = isolate->factory()->NewJSObject(
1274 isolate->context_extension_function());
1220 // And store it in the extension slot. 1275 // And store it in the extension slot.
1221 context->set_extension(*context_ext); 1276 context->set_extension(*context_ext);
1222 } 1277 }
1223 ASSERT(*context_ext != NULL); 1278 ASSERT(*context_ext != NULL);
1224 1279
1225 // Declare the property by setting it to the initial value if provided, 1280 // Declare the property by setting it to the initial value if provided,
1226 // or undefined, and use the correct mode (e.g. READ_ONLY attribute for 1281 // or undefined, and use the correct mode (e.g. READ_ONLY attribute for
1227 // constant declarations). 1282 // constant declarations).
1228 ASSERT(!context_ext->HasLocalProperty(*name)); 1283 ASSERT(!context_ext->HasLocalProperty(*name));
1229 Handle<Object> value(Heap::undefined_value()); 1284 Handle<Object> value(isolate->heap()->undefined_value(), isolate);
1230 if (*initial_value != NULL) value = initial_value; 1285 if (*initial_value != NULL) value = initial_value;
1231 // Declaring a const context slot is a conflicting declaration if 1286 // Declaring a const context slot is a conflicting declaration if
1232 // there is a callback with that name in a prototype. It is 1287 // there is a callback with that name in a prototype. It is
1233 // allowed to introduce const variables in 1288 // allowed to introduce const variables in
1234 // JSContextExtensionObjects. They are treated specially in 1289 // JSContextExtensionObjects. They are treated specially in
1235 // SetProperty and no setters are invoked for those since they are 1290 // SetProperty and no setters are invoked for those since they are
1236 // not real JSObjects. 1291 // not real JSObjects.
1237 if (initial_value->IsTheHole() && 1292 if (initial_value->IsTheHole() &&
1238 !context_ext->IsJSContextExtensionObject()) { 1293 !context_ext->IsJSContextExtensionObject()) {
1239 LookupResult lookup; 1294 LookupResult lookup;
1240 context_ext->Lookup(*name, &lookup); 1295 context_ext->Lookup(*name, &lookup);
1241 if (lookup.IsProperty() && (lookup.type() == CALLBACKS)) { 1296 if (lookup.IsProperty() && (lookup.type() == CALLBACKS)) {
1242 return ThrowRedeclarationError("const", name); 1297 return ThrowRedeclarationError(isolate, "const", name);
1243 } 1298 }
1244 } 1299 }
1245 RETURN_IF_EMPTY_HANDLE(SetProperty(context_ext, name, value, mode, 1300 RETURN_IF_EMPTY_HANDLE(isolate,
1301 SetProperty(context_ext, name, value, mode,
1246 kNonStrictMode)); 1302 kNonStrictMode));
1247 } 1303 }
1248 1304
1249 return Heap::undefined_value(); 1305 return isolate->heap()->undefined_value();
1250 } 1306 }
1251 1307
1252 1308
1253 static MaybeObject* Runtime_InitializeVarGlobal(Arguments args) { 1309 static MaybeObject* Runtime_InitializeVarGlobal(RUNTIME_CALLING_CONVENTION) {
1310 RUNTIME_GET_ISOLATE;
1254 NoHandleAllocation nha; 1311 NoHandleAllocation nha;
1255 // args[0] == name 1312 // args[0] == name
1256 // args[1] == strict_mode 1313 // args[1] == strict_mode
1257 // args[2] == value (optional) 1314 // args[2] == value (optional)
1258 1315
1259 // Determine if we need to assign to the variable if it already 1316 // Determine if we need to assign to the variable if it already
1260 // exists (based on the number of arguments). 1317 // exists (based on the number of arguments).
1261 RUNTIME_ASSERT(args.length() == 2 || args.length() == 3); 1318 RUNTIME_ASSERT(args.length() == 2 || args.length() == 3);
1262 bool assign = args.length() == 3; 1319 bool assign = args.length() == 3;
1263 1320
1264 CONVERT_ARG_CHECKED(String, name, 0); 1321 CONVERT_ARG_CHECKED(String, name, 0);
1265 GlobalObject* global = Top::context()->global(); 1322 GlobalObject* global = isolate->context()->global();
1266 RUNTIME_ASSERT(args[1]->IsSmi()); 1323 RUNTIME_ASSERT(args[1]->IsSmi());
1267 StrictModeFlag strict_mode = 1324 StrictModeFlag strict_mode =
1268 static_cast<StrictModeFlag>(Smi::cast(args[1])->value()); 1325 static_cast<StrictModeFlag>(Smi::cast(args[1])->value());
1269 ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode); 1326 ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode);
1270 1327
1271 // According to ECMA-262, section 12.2, page 62, the property must 1328 // According to ECMA-262, section 12.2, page 62, the property must
1272 // not be deletable. 1329 // not be deletable.
1273 PropertyAttributes attributes = DONT_DELETE; 1330 PropertyAttributes attributes = DONT_DELETE;
1274 1331
1275 // Lookup the property locally in the global object. If it isn't 1332 // Lookup the property locally in the global object. If it isn't
1276 // there, there is a property with this name in the prototype chain. 1333 // there, there is a property with this name in the prototype chain.
1277 // We follow Safari and Firefox behavior and only set the property 1334 // We follow Safari and Firefox behavior and only set the property
1278 // locally if there is an explicit initialization value that we have 1335 // locally if there is an explicit initialization value that we have
1279 // to assign to the property. 1336 // to assign to the property.
1280 // Note that objects can have hidden prototypes, so we need to traverse 1337 // Note that objects can have hidden prototypes, so we need to traverse
1281 // the whole chain of hidden prototypes to do a 'local' lookup. 1338 // the whole chain of hidden prototypes to do a 'local' lookup.
1282 JSObject* real_holder = global; 1339 JSObject* real_holder = global;
1283 LookupResult lookup; 1340 LookupResult lookup;
1284 while (true) { 1341 while (true) {
1285 real_holder->LocalLookup(*name, &lookup); 1342 real_holder->LocalLookup(*name, &lookup);
1286 if (lookup.IsProperty()) { 1343 if (lookup.IsProperty()) {
1287 // Determine if this is a redeclaration of something read-only. 1344 // Determine if this is a redeclaration of something read-only.
1288 if (lookup.IsReadOnly()) { 1345 if (lookup.IsReadOnly()) {
1289 // If we found readonly property on one of hidden prototypes, 1346 // If we found readonly property on one of hidden prototypes,
1290 // just shadow it. 1347 // just shadow it.
1291 if (real_holder != Top::context()->global()) break; 1348 if (real_holder != isolate->context()->global()) break;
1292 return ThrowRedeclarationError("const", name); 1349 return ThrowRedeclarationError(isolate, "const", name);
1293 } 1350 }
1294 1351
1295 // Determine if this is a redeclaration of an intercepted read-only 1352 // Determine if this is a redeclaration of an intercepted read-only
1296 // property and figure out if the property exists at all. 1353 // property and figure out if the property exists at all.
1297 bool found = true; 1354 bool found = true;
1298 PropertyType type = lookup.type(); 1355 PropertyType type = lookup.type();
1299 if (type == INTERCEPTOR) { 1356 if (type == INTERCEPTOR) {
1300 HandleScope handle_scope; 1357 HandleScope handle_scope(isolate);
1301 Handle<JSObject> holder(real_holder); 1358 Handle<JSObject> holder(real_holder);
1302 PropertyAttributes intercepted = holder->GetPropertyAttribute(*name); 1359 PropertyAttributes intercepted = holder->GetPropertyAttribute(*name);
1303 real_holder = *holder; 1360 real_holder = *holder;
1304 if (intercepted == ABSENT) { 1361 if (intercepted == ABSENT) {
1305 // The interceptor claims the property isn't there. We need to 1362 // The interceptor claims the property isn't there. We need to
1306 // make sure to introduce it. 1363 // make sure to introduce it.
1307 found = false; 1364 found = false;
1308 } else if ((intercepted & READ_ONLY) != 0) { 1365 } else if ((intercepted & READ_ONLY) != 0) {
1309 // The property is present, but read-only. Since we're trying to 1366 // The property is present, but read-only. Since we're trying to
1310 // overwrite it with a variable declaration we must throw a 1367 // overwrite it with a variable declaration we must throw a
1311 // re-declaration error. However if we found readonly property 1368 // re-declaration error. However if we found readonly property
1312 // on one of hidden prototypes, just shadow it. 1369 // on one of hidden prototypes, just shadow it.
1313 if (real_holder != Top::context()->global()) break; 1370 if (real_holder != isolate->context()->global()) break;
1314 return ThrowRedeclarationError("const", name); 1371 return ThrowRedeclarationError(isolate, "const", name);
1315 } 1372 }
1316 } 1373 }
1317 1374
1318 if (found && !assign) { 1375 if (found && !assign) {
1319 // The global property is there and we're not assigning any value 1376 // The global property is there and we're not assigning any value
1320 // to it. Just return. 1377 // to it. Just return.
1321 return Heap::undefined_value(); 1378 return isolate->heap()->undefined_value();
1322 } 1379 }
1323 1380
1324 // Assign the value (or undefined) to the property. 1381 // Assign the value (or undefined) to the property.
1325 Object* value = (assign) ? args[2] : Heap::undefined_value(); 1382 Object* value = (assign) ? args[2] : isolate->heap()->undefined_value();
1326 return real_holder->SetProperty( 1383 return real_holder->SetProperty(
1327 &lookup, *name, value, attributes, strict_mode); 1384 &lookup, *name, value, attributes, strict_mode);
1328 } 1385 }
1329 1386
1330 Object* proto = real_holder->GetPrototype(); 1387 Object* proto = real_holder->GetPrototype();
1331 if (!proto->IsJSObject()) 1388 if (!proto->IsJSObject())
1332 break; 1389 break;
1333 1390
1334 if (!JSObject::cast(proto)->map()->is_hidden_prototype()) 1391 if (!JSObject::cast(proto)->map()->is_hidden_prototype())
1335 break; 1392 break;
1336 1393
1337 real_holder = JSObject::cast(proto); 1394 real_holder = JSObject::cast(proto);
1338 } 1395 }
1339 1396
1340 global = Top::context()->global(); 1397 global = isolate->context()->global();
1341 if (assign) { 1398 if (assign) {
1342 return global->SetProperty(*name, args[2], attributes, strict_mode); 1399 return global->SetProperty(*name, args[2], attributes, strict_mode);
1343 } 1400 }
1344 return Heap::undefined_value(); 1401 return isolate->heap()->undefined_value();
1345 } 1402 }
1346 1403
1347 1404
1348 static MaybeObject* Runtime_InitializeConstGlobal(Arguments args) { 1405 static MaybeObject* Runtime_InitializeConstGlobal(RUNTIME_CALLING_CONVENTION) {
1406 RUNTIME_GET_ISOLATE;
1349 // All constants are declared with an initial value. The name 1407 // All constants are declared with an initial value. The name
1350 // of the constant is the first argument and the initial value 1408 // of the constant is the first argument and the initial value
1351 // is the second. 1409 // is the second.
1352 RUNTIME_ASSERT(args.length() == 2); 1410 RUNTIME_ASSERT(args.length() == 2);
1353 CONVERT_ARG_CHECKED(String, name, 0); 1411 CONVERT_ARG_CHECKED(String, name, 0);
1354 Handle<Object> value = args.at<Object>(1); 1412 Handle<Object> value = args.at<Object>(1);
1355 1413
1356 // Get the current global object from top. 1414 // Get the current global object from top.
1357 GlobalObject* global = Top::context()->global(); 1415 GlobalObject* global = isolate->context()->global();
1358 1416
1359 // According to ECMA-262, section 12.2, page 62, the property must 1417 // According to ECMA-262, section 12.2, page 62, the property must
1360 // not be deletable. Since it's a const, it must be READ_ONLY too. 1418 // not be deletable. Since it's a const, it must be READ_ONLY too.
1361 PropertyAttributes attributes = 1419 PropertyAttributes attributes =
1362 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 1420 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
1363 1421
1364 // Lookup the property locally in the global object. If it isn't 1422 // Lookup the property locally in the global object. If it isn't
1365 // there, we add the property and take special precautions to always 1423 // there, we add the property and take special precautions to always
1366 // add it as a local property even in case of callbacks in the 1424 // add it as a local property even in case of callbacks in the
1367 // prototype chain (this rules out using SetProperty). 1425 // prototype chain (this rules out using SetProperty).
1368 // We use SetLocalPropertyIgnoreAttributes instead 1426 // We use SetLocalPropertyIgnoreAttributes instead
1369 LookupResult lookup; 1427 LookupResult lookup;
1370 global->LocalLookup(*name, &lookup); 1428 global->LocalLookup(*name, &lookup);
1371 if (!lookup.IsProperty()) { 1429 if (!lookup.IsProperty()) {
1372 return global->SetLocalPropertyIgnoreAttributes(*name, 1430 return global->SetLocalPropertyIgnoreAttributes(*name,
1373 *value, 1431 *value,
1374 attributes); 1432 attributes);
1375 } 1433 }
1376 1434
1377 // Determine if this is a redeclaration of something not 1435 // Determine if this is a redeclaration of something not
1378 // read-only. In case the result is hidden behind an interceptor we 1436 // read-only. In case the result is hidden behind an interceptor we
1379 // need to ask it for the property attributes. 1437 // need to ask it for the property attributes.
1380 if (!lookup.IsReadOnly()) { 1438 if (!lookup.IsReadOnly()) {
1381 if (lookup.type() != INTERCEPTOR) { 1439 if (lookup.type() != INTERCEPTOR) {
1382 return ThrowRedeclarationError("var", name); 1440 return ThrowRedeclarationError(isolate, "var", name);
1383 } 1441 }
1384 1442
1385 PropertyAttributes intercepted = global->GetPropertyAttribute(*name); 1443 PropertyAttributes intercepted = global->GetPropertyAttribute(*name);
1386 1444
1387 // Throw re-declaration error if the intercepted property is present 1445 // Throw re-declaration error if the intercepted property is present
1388 // but not read-only. 1446 // but not read-only.
1389 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { 1447 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) {
1390 return ThrowRedeclarationError("var", name); 1448 return ThrowRedeclarationError(isolate, "var", name);
1391 } 1449 }
1392 1450
1393 // Restore global object from context (in case of GC) and continue 1451 // Restore global object from context (in case of GC) and continue
1394 // with setting the value because the property is either absent or 1452 // with setting the value because the property is either absent or
1395 // read-only. We also have to do redo the lookup. 1453 // read-only. We also have to do redo the lookup.
1396 HandleScope handle_scope; 1454 HandleScope handle_scope(isolate);
1397 Handle<GlobalObject> global(Top::context()->global()); 1455 Handle<GlobalObject> global(isolate->context()->global());
1398 1456
1399 // BUG 1213575: Handle the case where we have to set a read-only 1457 // BUG 1213575: Handle the case where we have to set a read-only
1400 // property through an interceptor and only do it if it's 1458 // property through an interceptor and only do it if it's
1401 // uninitialized, e.g. the hole. Nirk... 1459 // uninitialized, e.g. the hole. Nirk...
1402 // Passing non-strict mode because the property is writable. 1460 // Passing non-strict mode because the property is writable.
1403 RETURN_IF_EMPTY_HANDLE(SetProperty(global, 1461 RETURN_IF_EMPTY_HANDLE(isolate,
1462 SetProperty(global,
1404 name, 1463 name,
1405 value, 1464 value,
1406 attributes, 1465 attributes,
1407 kNonStrictMode)); 1466 kNonStrictMode));
1408 return *value; 1467 return *value;
1409 } 1468 }
1410 1469
1411 // Set the value, but only we're assigning the initial value to a 1470 // Set the value, but only we're assigning the initial value to a
1412 // constant. For now, we determine this by checking if the 1471 // constant. For now, we determine this by checking if the
1413 // current value is the hole. 1472 // current value is the hole.
(...skipping 13 matching lines...) Expand all
1427 // Ignore re-initialization of constants that have already been 1486 // Ignore re-initialization of constants that have already been
1428 // assigned a function value. 1487 // assigned a function value.
1429 ASSERT(lookup.IsReadOnly() && type == CONSTANT_FUNCTION); 1488 ASSERT(lookup.IsReadOnly() && type == CONSTANT_FUNCTION);
1430 } 1489 }
1431 1490
1432 // Use the set value as the result of the operation. 1491 // Use the set value as the result of the operation.
1433 return *value; 1492 return *value;
1434 } 1493 }
1435 1494
1436 1495
1437 static MaybeObject* Runtime_InitializeConstContextSlot(Arguments args) { 1496 static MaybeObject* Runtime_InitializeConstContextSlot(
1438 HandleScope scope; 1497 RUNTIME_CALLING_CONVENTION) {
1498 RUNTIME_GET_ISOLATE;
1499 HandleScope scope(isolate);
1439 ASSERT(args.length() == 3); 1500 ASSERT(args.length() == 3);
1440 1501
1441 Handle<Object> value(args[0]); 1502 Handle<Object> value(args[0], isolate);
1442 ASSERT(!value->IsTheHole()); 1503 ASSERT(!value->IsTheHole());
1443 CONVERT_ARG_CHECKED(Context, context, 1); 1504 CONVERT_ARG_CHECKED(Context, context, 1);
1444 Handle<String> name(String::cast(args[2])); 1505 Handle<String> name(String::cast(args[2]));
1445 1506
1446 // Initializations are always done in the function context. 1507 // Initializations are always done in the function context.
1447 context = Handle<Context>(context->fcontext()); 1508 context = Handle<Context>(context->fcontext());
1448 1509
1449 int index; 1510 int index;
1450 PropertyAttributes attributes; 1511 PropertyAttributes attributes;
1451 ContextLookupFlags flags = FOLLOW_CHAINS; 1512 ContextLookupFlags flags = FOLLOW_CHAINS;
(...skipping 20 matching lines...) Expand all
1472 // the const property. 1533 // the const property.
1473 ASSERT(!holder.is_identical_to(context)); 1534 ASSERT(!holder.is_identical_to(context));
1474 if ((attributes & READ_ONLY) == 0) { 1535 if ((attributes & READ_ONLY) == 0) {
1475 Handle<Context>::cast(holder)->set(index, *value); 1536 Handle<Context>::cast(holder)->set(index, *value);
1476 } 1537 }
1477 } else { 1538 } else {
1478 // The holder is an arguments object. 1539 // The holder is an arguments object.
1479 ASSERT((attributes & READ_ONLY) == 0); 1540 ASSERT((attributes & READ_ONLY) == 0);
1480 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); 1541 Handle<JSObject> arguments(Handle<JSObject>::cast(holder));
1481 RETURN_IF_EMPTY_HANDLE( 1542 RETURN_IF_EMPTY_HANDLE(
1543 isolate,
1482 SetElement(arguments, index, value, kNonStrictMode)); 1544 SetElement(arguments, index, value, kNonStrictMode));
1483 } 1545 }
1484 return *value; 1546 return *value;
1485 } 1547 }
1486 1548
1487 // The property could not be found, we introduce it in the global 1549 // The property could not be found, we introduce it in the global
1488 // context. 1550 // context.
1489 if (attributes == ABSENT) { 1551 if (attributes == ABSENT) {
1490 Handle<JSObject> global = Handle<JSObject>(Top::context()->global()); 1552 Handle<JSObject> global = Handle<JSObject>(
1553 isolate->context()->global());
1491 // Strict mode not needed (const disallowed in strict mode). 1554 // Strict mode not needed (const disallowed in strict mode).
1492 RETURN_IF_EMPTY_HANDLE( 1555 RETURN_IF_EMPTY_HANDLE(
1556 isolate,
1493 SetProperty(global, name, value, NONE, kNonStrictMode)); 1557 SetProperty(global, name, value, NONE, kNonStrictMode));
1494 return *value; 1558 return *value;
1495 } 1559 }
1496 1560
1497 // The property was present in a context extension object. 1561 // The property was present in a context extension object.
1498 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); 1562 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder);
1499 1563
1500 if (*context_ext == context->extension()) { 1564 if (*context_ext == context->extension()) {
1501 // This is the property that was introduced by the const 1565 // This is the property that was introduced by the const
1502 // declaration. Set it if it hasn't been set before. NOTE: We 1566 // declaration. Set it if it hasn't been set before. NOTE: We
(...skipping 19 matching lines...) Expand all
1522 // We should not reach here. Any real, named property should be 1586 // We should not reach here. Any real, named property should be
1523 // either a field or a dictionary slot. 1587 // either a field or a dictionary slot.
1524 UNREACHABLE(); 1588 UNREACHABLE();
1525 } 1589 }
1526 } else { 1590 } else {
1527 // The property was found in a different context extension object. 1591 // The property was found in a different context extension object.
1528 // Set it if it is not a read-only property. 1592 // Set it if it is not a read-only property.
1529 if ((attributes & READ_ONLY) == 0) { 1593 if ((attributes & READ_ONLY) == 0) {
1530 // Strict mode not needed (const disallowed in strict mode). 1594 // Strict mode not needed (const disallowed in strict mode).
1531 RETURN_IF_EMPTY_HANDLE( 1595 RETURN_IF_EMPTY_HANDLE(
1596 isolate,
1532 SetProperty(context_ext, name, value, attributes, kNonStrictMode)); 1597 SetProperty(context_ext, name, value, attributes, kNonStrictMode));
1533 } 1598 }
1534 } 1599 }
1535 1600
1536 return *value; 1601 return *value;
1537 } 1602 }
1538 1603
1539 1604
1540 static MaybeObject* Runtime_OptimizeObjectForAddingMultipleProperties( 1605 static MaybeObject* Runtime_OptimizeObjectForAddingMultipleProperties(
1541 Arguments args) { 1606 RUNTIME_CALLING_CONVENTION) {
1542 HandleScope scope; 1607 RUNTIME_GET_ISOLATE;
1608 HandleScope scope(isolate);
1543 ASSERT(args.length() == 2); 1609 ASSERT(args.length() == 2);
1544 CONVERT_ARG_CHECKED(JSObject, object, 0); 1610 CONVERT_ARG_CHECKED(JSObject, object, 0);
1545 CONVERT_SMI_CHECKED(properties, args[1]); 1611 CONVERT_SMI_CHECKED(properties, args[1]);
1546 if (object->HasFastProperties()) { 1612 if (object->HasFastProperties()) {
1547 NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties); 1613 NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties);
1548 } 1614 }
1549 return *object; 1615 return *object;
1550 } 1616 }
1551 1617
1552 1618
1553 static MaybeObject* Runtime_RegExpExec(Arguments args) { 1619 static MaybeObject* Runtime_RegExpExec(RUNTIME_CALLING_CONVENTION) {
1554 HandleScope scope; 1620 RUNTIME_GET_ISOLATE;
1621 HandleScope scope(isolate);
1555 ASSERT(args.length() == 4); 1622 ASSERT(args.length() == 4);
1556 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); 1623 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
1557 CONVERT_ARG_CHECKED(String, subject, 1); 1624 CONVERT_ARG_CHECKED(String, subject, 1);
1558 // Due to the way the JS calls are constructed this must be less than the 1625 // Due to the way the JS calls are constructed this must be less than the
1559 // length of a string, i.e. it is always a Smi. We check anyway for security. 1626 // length of a string, i.e. it is always a Smi. We check anyway for security.
1560 CONVERT_SMI_CHECKED(index, args[2]); 1627 CONVERT_SMI_CHECKED(index, args[2]);
1561 CONVERT_ARG_CHECKED(JSArray, last_match_info, 3); 1628 CONVERT_ARG_CHECKED(JSArray, last_match_info, 3);
1562 RUNTIME_ASSERT(last_match_info->HasFastElements()); 1629 RUNTIME_ASSERT(last_match_info->HasFastElements());
1563 RUNTIME_ASSERT(index >= 0); 1630 RUNTIME_ASSERT(index >= 0);
1564 RUNTIME_ASSERT(index <= subject->length()); 1631 RUNTIME_ASSERT(index <= subject->length());
1565 Counters::regexp_entry_runtime.Increment(); 1632 isolate->counters()->regexp_entry_runtime()->Increment();
1566 Handle<Object> result = RegExpImpl::Exec(regexp, 1633 Handle<Object> result = RegExpImpl::Exec(regexp,
1567 subject, 1634 subject,
1568 index, 1635 index,
1569 last_match_info); 1636 last_match_info);
1570 if (result.is_null()) return Failure::Exception(); 1637 if (result.is_null()) return Failure::Exception();
1571 return *result; 1638 return *result;
1572 } 1639 }
1573 1640
1574 1641
1575 static MaybeObject* Runtime_RegExpConstructResult(Arguments args) { 1642 static MaybeObject* Runtime_RegExpConstructResult(RUNTIME_CALLING_CONVENTION) {
1643 RUNTIME_GET_ISOLATE;
1576 ASSERT(args.length() == 3); 1644 ASSERT(args.length() == 3);
1577 CONVERT_SMI_CHECKED(elements_count, args[0]); 1645 CONVERT_SMI_CHECKED(elements_count, args[0]);
1578 if (elements_count > JSArray::kMaxFastElementsLength) { 1646 if (elements_count > JSArray::kMaxFastElementsLength) {
1579 return Top::ThrowIllegalOperation(); 1647 return isolate->ThrowIllegalOperation();
1580 } 1648 }
1581 Object* new_object; 1649 Object* new_object;
1582 { MaybeObject* maybe_new_object = 1650 { MaybeObject* maybe_new_object =
1583 Heap::AllocateFixedArrayWithHoles(elements_count); 1651 isolate->heap()->AllocateFixedArrayWithHoles(elements_count);
1584 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object; 1652 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object;
1585 } 1653 }
1586 FixedArray* elements = FixedArray::cast(new_object); 1654 FixedArray* elements = FixedArray::cast(new_object);
1587 { MaybeObject* maybe_new_object = Heap::AllocateRaw(JSRegExpResult::kSize, 1655 { MaybeObject* maybe_new_object = isolate->heap()->AllocateRaw(
1588 NEW_SPACE, 1656 JSRegExpResult::kSize, NEW_SPACE, OLD_POINTER_SPACE);
1589 OLD_POINTER_SPACE);
1590 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object; 1657 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object;
1591 } 1658 }
1592 { 1659 {
1593 AssertNoAllocation no_gc; 1660 AssertNoAllocation no_gc;
1594 HandleScope scope; 1661 HandleScope scope(isolate);
1595 reinterpret_cast<HeapObject*>(new_object)-> 1662 reinterpret_cast<HeapObject*>(new_object)->
1596 set_map(Top::global_context()->regexp_result_map()); 1663 set_map(isolate->global_context()->regexp_result_map());
1597 } 1664 }
1598 JSArray* array = JSArray::cast(new_object); 1665 JSArray* array = JSArray::cast(new_object);
1599 array->set_properties(Heap::empty_fixed_array()); 1666 array->set_properties(isolate->heap()->empty_fixed_array());
1600 array->set_elements(elements); 1667 array->set_elements(elements);
1601 array->set_length(Smi::FromInt(elements_count)); 1668 array->set_length(Smi::FromInt(elements_count));
1602 // Write in-object properties after the length of the array. 1669 // Write in-object properties after the length of the array.
1603 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); 1670 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]);
1604 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); 1671 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]);
1605 return array; 1672 return array;
1606 } 1673 }
1607 1674
1608 1675
1609 static MaybeObject* Runtime_RegExpInitializeObject(Arguments args) { 1676 static MaybeObject* Runtime_RegExpInitializeObject(RUNTIME_CALLING_CONVENTION) {
1677 RUNTIME_GET_ISOLATE;
1610 AssertNoAllocation no_alloc; 1678 AssertNoAllocation no_alloc;
1611 ASSERT(args.length() == 5); 1679 ASSERT(args.length() == 5);
1612 CONVERT_CHECKED(JSRegExp, regexp, args[0]); 1680 CONVERT_CHECKED(JSRegExp, regexp, args[0]);
1613 CONVERT_CHECKED(String, source, args[1]); 1681 CONVERT_CHECKED(String, source, args[1]);
1614 1682
1615 Object* global = args[2]; 1683 Object* global = args[2];
1616 if (!global->IsTrue()) global = Heap::false_value(); 1684 if (!global->IsTrue()) global = isolate->heap()->false_value();
1617 1685
1618 Object* ignoreCase = args[3]; 1686 Object* ignoreCase = args[3];
1619 if (!ignoreCase->IsTrue()) ignoreCase = Heap::false_value(); 1687 if (!ignoreCase->IsTrue()) ignoreCase = isolate->heap()->false_value();
1620 1688
1621 Object* multiline = args[4]; 1689 Object* multiline = args[4];
1622 if (!multiline->IsTrue()) multiline = Heap::false_value(); 1690 if (!multiline->IsTrue()) multiline = isolate->heap()->false_value();
1623 1691
1624 Map* map = regexp->map(); 1692 Map* map = regexp->map();
1625 Object* constructor = map->constructor(); 1693 Object* constructor = map->constructor();
1626 if (constructor->IsJSFunction() && 1694 if (constructor->IsJSFunction() &&
1627 JSFunction::cast(constructor)->initial_map() == map) { 1695 JSFunction::cast(constructor)->initial_map() == map) {
1628 // If we still have the original map, set in-object properties directly. 1696 // If we still have the original map, set in-object properties directly.
1629 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, source); 1697 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, source);
1630 // TODO(lrn): Consider skipping write barrier on booleans as well. 1698 // TODO(lrn): Consider skipping write barrier on booleans as well.
1631 // Both true and false should be in oldspace at all times. 1699 // Both true and false should be in oldspace at all times.
1632 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, global); 1700 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, global);
1633 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, ignoreCase); 1701 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, ignoreCase);
1634 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, multiline); 1702 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, multiline);
1635 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, 1703 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
1636 Smi::FromInt(0), 1704 Smi::FromInt(0),
1637 SKIP_WRITE_BARRIER); 1705 SKIP_WRITE_BARRIER);
1638 return regexp; 1706 return regexp;
1639 } 1707 }
1640 1708
1641 // Map has changed, so use generic, but slower, method. Since these 1709 // Map has changed, so use generic, but slower, method.
1642 // properties were all added as DONT_DELETE they must be present and
1643 // normal so no failures can be expected.
1644 PropertyAttributes final = 1710 PropertyAttributes final =
1645 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); 1711 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE);
1646 PropertyAttributes writable = 1712 PropertyAttributes writable =
1647 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); 1713 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
1714 Heap* heap = isolate->heap();
1648 MaybeObject* result; 1715 MaybeObject* result;
1649 result = regexp->SetLocalPropertyIgnoreAttributes(Heap::source_symbol(), 1716 result = regexp->SetLocalPropertyIgnoreAttributes(heap->source_symbol(),
1650 source, 1717 source,
1651 final); 1718 final);
1652 ASSERT(!result->IsFailure()); 1719 ASSERT(!result->IsFailure());
1653 result = regexp->SetLocalPropertyIgnoreAttributes(Heap::global_symbol(), 1720 result = regexp->SetLocalPropertyIgnoreAttributes(heap->global_symbol(),
1654 global, 1721 global,
1655 final); 1722 final);
1656 ASSERT(!result->IsFailure()); 1723 ASSERT(!result->IsFailure());
1657 result = 1724 result =
1658 regexp->SetLocalPropertyIgnoreAttributes(Heap::ignore_case_symbol(), 1725 regexp->SetLocalPropertyIgnoreAttributes(heap->ignore_case_symbol(),
1659 ignoreCase, 1726 ignoreCase,
1660 final); 1727 final);
1661 ASSERT(!result->IsFailure()); 1728 ASSERT(!result->IsFailure());
1662 result = regexp->SetLocalPropertyIgnoreAttributes(Heap::multiline_symbol(), 1729 result = regexp->SetLocalPropertyIgnoreAttributes(heap->multiline_symbol(),
1663 multiline, 1730 multiline,
1664 final); 1731 final);
1665 ASSERT(!result->IsFailure()); 1732 ASSERT(!result->IsFailure());
1666 result = 1733 result =
1667 regexp->SetLocalPropertyIgnoreAttributes(Heap::last_index_symbol(), 1734 regexp->SetLocalPropertyIgnoreAttributes(heap->last_index_symbol(),
1668 Smi::FromInt(0), 1735 Smi::FromInt(0),
1669 writable); 1736 writable);
1670 ASSERT(!result->IsFailure()); 1737 ASSERT(!result->IsFailure());
1671 USE(result); 1738 USE(result);
1672 return regexp; 1739 return regexp;
1673 } 1740 }
1674 1741
1675 1742
1676 static MaybeObject* Runtime_FinishArrayPrototypeSetup(Arguments args) { 1743 static MaybeObject* Runtime_FinishArrayPrototypeSetup(
1677 HandleScope scope; 1744 RUNTIME_CALLING_CONVENTION) {
1745 RUNTIME_GET_ISOLATE;
1746 HandleScope scope(isolate);
1678 ASSERT(args.length() == 1); 1747 ASSERT(args.length() == 1);
1679 CONVERT_ARG_CHECKED(JSArray, prototype, 0); 1748 CONVERT_ARG_CHECKED(JSArray, prototype, 0);
1680 // This is necessary to enable fast checks for absence of elements 1749 // This is necessary to enable fast checks for absence of elements
1681 // on Array.prototype and below. 1750 // on Array.prototype and below.
1682 prototype->set_elements(Heap::empty_fixed_array()); 1751 prototype->set_elements(isolate->heap()->empty_fixed_array());
1683 return Smi::FromInt(0); 1752 return Smi::FromInt(0);
1684 } 1753 }
1685 1754
1686 1755
1687 static Handle<JSFunction> InstallBuiltin(Handle<JSObject> holder, 1756 static Handle<JSFunction> InstallBuiltin(Isolate* isolate,
1757 Handle<JSObject> holder,
1688 const char* name, 1758 const char* name,
1689 Builtins::Name builtin_name) { 1759 Builtins::Name builtin_name) {
1690 Handle<String> key = Factory::LookupAsciiSymbol(name); 1760 Handle<String> key = isolate->factory()->LookupAsciiSymbol(name);
1691 Handle<Code> code(Builtins::builtin(builtin_name)); 1761 Handle<Code> code(isolate->builtins()->builtin(builtin_name));
1692 Handle<JSFunction> optimized = Factory::NewFunction(key, 1762 Handle<JSFunction> optimized =
1693 JS_OBJECT_TYPE, 1763 isolate->factory()->NewFunction(key,
1694 JSObject::kHeaderSize, 1764 JS_OBJECT_TYPE,
1695 code, 1765 JSObject::kHeaderSize,
1696 false); 1766 code,
1767 false);
1697 optimized->shared()->DontAdaptArguments(); 1768 optimized->shared()->DontAdaptArguments();
1698 SetProperty(holder, key, optimized, NONE, kStrictMode); 1769 SetProperty(holder, key, optimized, NONE, kStrictMode);
1699 return optimized; 1770 return optimized;
1700 } 1771 }
1701 1772
1702 1773
1703 static MaybeObject* Runtime_SpecialArrayFunctions(Arguments args) { 1774 static MaybeObject* Runtime_SpecialArrayFunctions(RUNTIME_CALLING_CONVENTION) {
1704 HandleScope scope; 1775 RUNTIME_GET_ISOLATE;
1776 HandleScope scope(isolate);
1705 ASSERT(args.length() == 1); 1777 ASSERT(args.length() == 1);
1706 CONVERT_ARG_CHECKED(JSObject, holder, 0); 1778 CONVERT_ARG_CHECKED(JSObject, holder, 0);
1707 1779
1708 InstallBuiltin(holder, "pop", Builtins::ArrayPop); 1780 InstallBuiltin(isolate, holder, "pop", Builtins::ArrayPop);
1709 InstallBuiltin(holder, "push", Builtins::ArrayPush); 1781 InstallBuiltin(isolate, holder, "push", Builtins::ArrayPush);
1710 InstallBuiltin(holder, "shift", Builtins::ArrayShift); 1782 InstallBuiltin(isolate, holder, "shift", Builtins::ArrayShift);
1711 InstallBuiltin(holder, "unshift", Builtins::ArrayUnshift); 1783 InstallBuiltin(isolate, holder, "unshift", Builtins::ArrayUnshift);
1712 InstallBuiltin(holder, "slice", Builtins::ArraySlice); 1784 InstallBuiltin(isolate, holder, "slice", Builtins::ArraySlice);
1713 InstallBuiltin(holder, "splice", Builtins::ArraySplice); 1785 InstallBuiltin(isolate, holder, "splice", Builtins::ArraySplice);
1714 InstallBuiltin(holder, "concat", Builtins::ArrayConcat); 1786 InstallBuiltin(isolate, holder, "concat", Builtins::ArrayConcat);
1715 1787
1716 return *holder; 1788 return *holder;
1717 } 1789 }
1718 1790
1719 1791
1720 static MaybeObject* Runtime_GetGlobalReceiver(Arguments args) { 1792 static MaybeObject* Runtime_GetGlobalReceiver(RUNTIME_CALLING_CONVENTION) {
1793 RUNTIME_GET_ISOLATE;
1721 // Returns a real global receiver, not one of builtins object. 1794 // Returns a real global receiver, not one of builtins object.
1722 Context* global_context = Top::context()->global()->global_context(); 1795 Context* global_context =
1796 isolate->context()->global()->global_context();
1723 return global_context->global()->global_receiver(); 1797 return global_context->global()->global_receiver();
1724 } 1798 }
1725 1799
1726 1800
1727 static MaybeObject* Runtime_MaterializeRegExpLiteral(Arguments args) { 1801 static MaybeObject* Runtime_MaterializeRegExpLiteral(
1728 HandleScope scope; 1802 RUNTIME_CALLING_CONVENTION) {
1803 RUNTIME_GET_ISOLATE;
1804 HandleScope scope(isolate);
1729 ASSERT(args.length() == 4); 1805 ASSERT(args.length() == 4);
1730 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 1806 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
1731 int index = Smi::cast(args[1])->value(); 1807 int index = Smi::cast(args[1])->value();
1732 Handle<String> pattern = args.at<String>(2); 1808 Handle<String> pattern = args.at<String>(2);
1733 Handle<String> flags = args.at<String>(3); 1809 Handle<String> flags = args.at<String>(3);
1734 1810
1735 // Get the RegExp function from the context in the literals array. 1811 // Get the RegExp function from the context in the literals array.
1736 // This is the RegExp function from the context in which the 1812 // This is the RegExp function from the context in which the
1737 // function was created. We do not use the RegExp function from the 1813 // function was created. We do not use the RegExp function from the
1738 // current global context because this might be the RegExp function 1814 // current global context because this might be the RegExp function
1739 // from another context which we should not have access to. 1815 // from another context which we should not have access to.
1740 Handle<JSFunction> constructor = 1816 Handle<JSFunction> constructor =
1741 Handle<JSFunction>( 1817 Handle<JSFunction>(
1742 JSFunction::GlobalContextFromLiterals(*literals)->regexp_function()); 1818 JSFunction::GlobalContextFromLiterals(*literals)->regexp_function());
1743 // Compute the regular expression literal. 1819 // Compute the regular expression literal.
1744 bool has_pending_exception; 1820 bool has_pending_exception;
1745 Handle<Object> regexp = 1821 Handle<Object> regexp =
1746 RegExpImpl::CreateRegExpLiteral(constructor, pattern, flags, 1822 RegExpImpl::CreateRegExpLiteral(constructor, pattern, flags,
1747 &has_pending_exception); 1823 &has_pending_exception);
1748 if (has_pending_exception) { 1824 if (has_pending_exception) {
1749 ASSERT(Top::has_pending_exception()); 1825 ASSERT(isolate->has_pending_exception());
1750 return Failure::Exception(); 1826 return Failure::Exception();
1751 } 1827 }
1752 literals->set(index, *regexp); 1828 literals->set(index, *regexp);
1753 return *regexp; 1829 return *regexp;
1754 } 1830 }
1755 1831
1756 1832
1757 static MaybeObject* Runtime_FunctionGetName(Arguments args) { 1833 static MaybeObject* Runtime_FunctionGetName(RUNTIME_CALLING_CONVENTION) {
1834 RUNTIME_GET_ISOLATE;
1758 NoHandleAllocation ha; 1835 NoHandleAllocation ha;
1759 ASSERT(args.length() == 1); 1836 ASSERT(args.length() == 1);
1760 1837
1761 CONVERT_CHECKED(JSFunction, f, args[0]); 1838 CONVERT_CHECKED(JSFunction, f, args[0]);
1762 return f->shared()->name(); 1839 return f->shared()->name();
1763 } 1840 }
1764 1841
1765 1842
1766 static MaybeObject* Runtime_FunctionSetName(Arguments args) { 1843 static MaybeObject* Runtime_FunctionSetName(RUNTIME_CALLING_CONVENTION) {
1844 RUNTIME_GET_ISOLATE;
1767 NoHandleAllocation ha; 1845 NoHandleAllocation ha;
1768 ASSERT(args.length() == 2); 1846 ASSERT(args.length() == 2);
1769 1847
1770 CONVERT_CHECKED(JSFunction, f, args[0]); 1848 CONVERT_CHECKED(JSFunction, f, args[0]);
1771 CONVERT_CHECKED(String, name, args[1]); 1849 CONVERT_CHECKED(String, name, args[1]);
1772 f->shared()->set_name(name); 1850 f->shared()->set_name(name);
1773 return Heap::undefined_value(); 1851 return isolate->heap()->undefined_value();
1774 } 1852 }
1775 1853
1776 1854
1777 static MaybeObject* Runtime_FunctionRemovePrototype(Arguments args) { 1855 static MaybeObject* Runtime_FunctionRemovePrototype(
1856 RUNTIME_CALLING_CONVENTION) {
1857 RUNTIME_GET_ISOLATE;
1778 NoHandleAllocation ha; 1858 NoHandleAllocation ha;
1779 ASSERT(args.length() == 1); 1859 ASSERT(args.length() == 1);
1780 1860
1781 CONVERT_CHECKED(JSFunction, f, args[0]); 1861 CONVERT_CHECKED(JSFunction, f, args[0]);
1782 Object* obj; 1862 Object* obj = f->RemovePrototype();
1783 { MaybeObject* maybe_obj = f->RemovePrototype(); 1863 if (obj->IsFailure()) return obj;
1784 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1785 }
1786 1864
1787 return Heap::undefined_value(); 1865 return isolate->heap()->undefined_value();
1788 } 1866 }
1789 1867
1790 1868
1791 static MaybeObject* Runtime_FunctionGetScript(Arguments args) { 1869 static MaybeObject* Runtime_FunctionGetScript(RUNTIME_CALLING_CONVENTION) {
1792 HandleScope scope; 1870 RUNTIME_GET_ISOLATE;
1871 HandleScope scope(isolate);
1793 ASSERT(args.length() == 1); 1872 ASSERT(args.length() == 1);
1794 1873
1795 CONVERT_CHECKED(JSFunction, fun, args[0]); 1874 CONVERT_CHECKED(JSFunction, fun, args[0]);
1796 Handle<Object> script = Handle<Object>(fun->shared()->script()); 1875 Handle<Object> script = Handle<Object>(fun->shared()->script(), isolate);
1797 if (!script->IsScript()) return Heap::undefined_value(); 1876 if (!script->IsScript()) return isolate->heap()->undefined_value();
1798 1877
1799 return *GetScriptWrapper(Handle<Script>::cast(script)); 1878 return *GetScriptWrapper(Handle<Script>::cast(script));
1800 } 1879 }
1801 1880
1802 1881
1803 static MaybeObject* Runtime_FunctionGetSourceCode(Arguments args) { 1882 static MaybeObject* Runtime_FunctionGetSourceCode(RUNTIME_CALLING_CONVENTION) {
1883 RUNTIME_GET_ISOLATE;
1804 NoHandleAllocation ha; 1884 NoHandleAllocation ha;
1805 ASSERT(args.length() == 1); 1885 ASSERT(args.length() == 1);
1806 1886
1807 CONVERT_CHECKED(JSFunction, f, args[0]); 1887 CONVERT_CHECKED(JSFunction, f, args[0]);
1808 return f->shared()->GetSourceCode(); 1888 return f->shared()->GetSourceCode();
1809 } 1889 }
1810 1890
1811 1891
1812 static MaybeObject* Runtime_FunctionGetScriptSourcePosition(Arguments args) { 1892 static MaybeObject* Runtime_FunctionGetScriptSourcePosition(
1893 RUNTIME_CALLING_CONVENTION) {
1894 RUNTIME_GET_ISOLATE;
1813 NoHandleAllocation ha; 1895 NoHandleAllocation ha;
1814 ASSERT(args.length() == 1); 1896 ASSERT(args.length() == 1);
1815 1897
1816 CONVERT_CHECKED(JSFunction, fun, args[0]); 1898 CONVERT_CHECKED(JSFunction, fun, args[0]);
1817 int pos = fun->shared()->start_position(); 1899 int pos = fun->shared()->start_position();
1818 return Smi::FromInt(pos); 1900 return Smi::FromInt(pos);
1819 } 1901 }
1820 1902
1821 1903
1822 static MaybeObject* Runtime_FunctionGetPositionForOffset(Arguments args) { 1904 static MaybeObject* Runtime_FunctionGetPositionForOffset(
1905 RUNTIME_CALLING_CONVENTION) {
1906 RUNTIME_GET_ISOLATE;
1823 ASSERT(args.length() == 2); 1907 ASSERT(args.length() == 2);
1824 1908
1825 CONVERT_CHECKED(Code, code, args[0]); 1909 CONVERT_CHECKED(Code, code, args[0]);
1826 CONVERT_NUMBER_CHECKED(int, offset, Int32, args[1]); 1910 CONVERT_NUMBER_CHECKED(int, offset, Int32, args[1]);
1827 1911
1828 RUNTIME_ASSERT(0 <= offset && offset < code->Size()); 1912 RUNTIME_ASSERT(0 <= offset && offset < code->Size());
1829 1913
1830 Address pc = code->address() + offset; 1914 Address pc = code->address() + offset;
1831 return Smi::FromInt(code->SourcePosition(pc)); 1915 return Smi::FromInt(code->SourcePosition(pc));
1832 } 1916 }
1833 1917
1834 1918
1835 1919 static MaybeObject* Runtime_FunctionSetInstanceClassName(
1836 static MaybeObject* Runtime_FunctionSetInstanceClassName(Arguments args) { 1920 RUNTIME_CALLING_CONVENTION) {
1921 RUNTIME_GET_ISOLATE;
1837 NoHandleAllocation ha; 1922 NoHandleAllocation ha;
1838 ASSERT(args.length() == 2); 1923 ASSERT(args.length() == 2);
1839 1924
1840 CONVERT_CHECKED(JSFunction, fun, args[0]); 1925 CONVERT_CHECKED(JSFunction, fun, args[0]);
1841 CONVERT_CHECKED(String, name, args[1]); 1926 CONVERT_CHECKED(String, name, args[1]);
1842 fun->SetInstanceClassName(name); 1927 fun->SetInstanceClassName(name);
1843 return Heap::undefined_value(); 1928 return isolate->heap()->undefined_value();
1844 } 1929 }
1845 1930
1846 1931
1847 static MaybeObject* Runtime_FunctionSetLength(Arguments args) { 1932 static MaybeObject* Runtime_FunctionSetLength(RUNTIME_CALLING_CONVENTION) {
1933 RUNTIME_GET_ISOLATE;
1848 NoHandleAllocation ha; 1934 NoHandleAllocation ha;
1849 ASSERT(args.length() == 2); 1935 ASSERT(args.length() == 2);
1850 1936
1851 CONVERT_CHECKED(JSFunction, fun, args[0]); 1937 CONVERT_CHECKED(JSFunction, fun, args[0]);
1852 CONVERT_CHECKED(Smi, length, args[1]); 1938 CONVERT_CHECKED(Smi, length, args[1]);
1853 fun->shared()->set_length(length->value()); 1939 fun->shared()->set_length(length->value());
1854 return length; 1940 return length;
1855 } 1941 }
1856 1942
1857 1943
1858 static MaybeObject* Runtime_FunctionSetPrototype(Arguments args) { 1944 static MaybeObject* Runtime_FunctionSetPrototype(RUNTIME_CALLING_CONVENTION) {
1945 RUNTIME_GET_ISOLATE;
1859 NoHandleAllocation ha; 1946 NoHandleAllocation ha;
1860 ASSERT(args.length() == 2); 1947 ASSERT(args.length() == 2);
1861 1948
1862 CONVERT_CHECKED(JSFunction, fun, args[0]); 1949 CONVERT_CHECKED(JSFunction, fun, args[0]);
1863 ASSERT(fun->should_have_prototype()); 1950 ASSERT(fun->should_have_prototype());
1864 Object* obj; 1951 Object* obj;
1865 { MaybeObject* maybe_obj = 1952 { MaybeObject* maybe_obj =
1866 Accessors::FunctionSetPrototype(fun, args[1], NULL); 1953 Accessors::FunctionSetPrototype(fun, args[1], NULL);
1867 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 1954 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1868 } 1955 }
1869 return args[0]; // return TOS 1956 return args[0]; // return TOS
1870 } 1957 }
1871 1958
1872 1959
1873 static MaybeObject* Runtime_FunctionIsAPIFunction(Arguments args) { 1960 static MaybeObject* Runtime_FunctionIsAPIFunction(RUNTIME_CALLING_CONVENTION) {
1961 RUNTIME_GET_ISOLATE;
1874 NoHandleAllocation ha; 1962 NoHandleAllocation ha;
1875 ASSERT(args.length() == 1); 1963 ASSERT(args.length() == 1);
1876 1964
1877 CONVERT_CHECKED(JSFunction, f, args[0]); 1965 CONVERT_CHECKED(JSFunction, f, args[0]);
1878 return f->shared()->IsApiFunction() ? Heap::true_value() 1966 return f->shared()->IsApiFunction() ? isolate->heap()->true_value()
1879 : Heap::false_value(); 1967 : isolate->heap()->false_value();
1880 } 1968 }
1881 1969
1882 static MaybeObject* Runtime_FunctionIsBuiltin(Arguments args) { 1970
1971 static MaybeObject* Runtime_FunctionIsBuiltin(RUNTIME_CALLING_CONVENTION) {
1972 RUNTIME_GET_ISOLATE;
1883 NoHandleAllocation ha; 1973 NoHandleAllocation ha;
1884 ASSERT(args.length() == 1); 1974 ASSERT(args.length() == 1);
1885 1975
1886 CONVERT_CHECKED(JSFunction, f, args[0]); 1976 CONVERT_CHECKED(JSFunction, f, args[0]);
1887 return f->IsBuiltin() ? Heap::true_value() : Heap::false_value(); 1977 return f->IsBuiltin() ? isolate->heap()->true_value() :
1978 isolate->heap()->false_value();
1888 } 1979 }
1889 1980
1890 1981
1891 static MaybeObject* Runtime_SetCode(Arguments args) { 1982 static MaybeObject* Runtime_SetCode(RUNTIME_CALLING_CONVENTION) {
1892 HandleScope scope; 1983 RUNTIME_GET_ISOLATE;
1984 HandleScope scope(isolate);
1893 ASSERT(args.length() == 2); 1985 ASSERT(args.length() == 2);
1894 1986
1895 CONVERT_ARG_CHECKED(JSFunction, target, 0); 1987 CONVERT_ARG_CHECKED(JSFunction, target, 0);
1896 Handle<Object> code = args.at<Object>(1); 1988 Handle<Object> code = args.at<Object>(1);
1897 1989
1898 Handle<Context> context(target->context()); 1990 Handle<Context> context(target->context());
1899 1991
1900 if (!code->IsNull()) { 1992 if (!code->IsNull()) {
1901 RUNTIME_ASSERT(code->IsJSFunction()); 1993 RUNTIME_ASSERT(code->IsJSFunction());
1902 Handle<JSFunction> fun = Handle<JSFunction>::cast(code); 1994 Handle<JSFunction> fun = Handle<JSFunction>::cast(code);
(...skipping 11 matching lines...) Expand all
1914 target->shared()->set_code(shared->code()); 2006 target->shared()->set_code(shared->code());
1915 target->ReplaceCode(shared->code()); 2007 target->ReplaceCode(shared->code());
1916 target->shared()->set_scope_info(shared->scope_info()); 2008 target->shared()->set_scope_info(shared->scope_info());
1917 target->shared()->set_length(shared->length()); 2009 target->shared()->set_length(shared->length());
1918 target->shared()->set_formal_parameter_count( 2010 target->shared()->set_formal_parameter_count(
1919 shared->formal_parameter_count()); 2011 shared->formal_parameter_count());
1920 // Set the source code of the target function to undefined. 2012 // Set the source code of the target function to undefined.
1921 // SetCode is only used for built-in constructors like String, 2013 // SetCode is only used for built-in constructors like String,
1922 // Array, and Object, and some web code 2014 // Array, and Object, and some web code
1923 // doesn't like seeing source code for constructors. 2015 // doesn't like seeing source code for constructors.
1924 target->shared()->set_script(Heap::undefined_value()); 2016 target->shared()->set_script(isolate->heap()->undefined_value());
1925 target->shared()->code()->set_optimizable(false); 2017 target->shared()->code()->set_optimizable(false);
1926 // Clear the optimization hints related to the compiled code as these are no 2018 // Clear the optimization hints related to the compiled code as these are no
1927 // longer valid when the code is overwritten. 2019 // longer valid when the code is overwritten.
1928 target->shared()->ClearThisPropertyAssignmentsInfo(); 2020 target->shared()->ClearThisPropertyAssignmentsInfo();
1929 context = Handle<Context>(fun->context()); 2021 context = Handle<Context>(fun->context());
1930 2022
1931 // Make sure we get a fresh copy of the literal vector to avoid 2023 // Make sure we get a fresh copy of the literal vector to avoid
1932 // cross context contamination. 2024 // cross context contamination.
1933 int number_of_literals = fun->NumberOfLiterals(); 2025 int number_of_literals = fun->NumberOfLiterals();
1934 Handle<FixedArray> literals = 2026 Handle<FixedArray> literals =
1935 Factory::NewFixedArray(number_of_literals, TENURED); 2027 isolate->factory()->NewFixedArray(number_of_literals, TENURED);
1936 if (number_of_literals > 0) { 2028 if (number_of_literals > 0) {
1937 // Insert the object, regexp and array functions in the literals 2029 // Insert the object, regexp and array functions in the literals
1938 // array prefix. These are the functions that will be used when 2030 // array prefix. These are the functions that will be used when
1939 // creating object, regexp and array literals. 2031 // creating object, regexp and array literals.
1940 literals->set(JSFunction::kLiteralGlobalContextIndex, 2032 literals->set(JSFunction::kLiteralGlobalContextIndex,
1941 context->global_context()); 2033 context->global_context());
1942 } 2034 }
1943 // It's okay to skip the write barrier here because the literals 2035 // It's okay to skip the write barrier here because the literals
1944 // are guaranteed to be in old space. 2036 // are guaranteed to be in old space.
1945 target->set_literals(*literals, SKIP_WRITE_BARRIER); 2037 target->set_literals(*literals, SKIP_WRITE_BARRIER);
1946 target->set_next_function_link(Heap::undefined_value()); 2038 target->set_next_function_link(isolate->heap()->undefined_value());
1947 } 2039 }
1948 2040
1949 target->set_context(*context); 2041 target->set_context(*context);
1950 return *target; 2042 return *target;
1951 } 2043 }
1952 2044
1953 2045
1954 static MaybeObject* Runtime_SetExpectedNumberOfProperties(Arguments args) { 2046 static MaybeObject* Runtime_SetExpectedNumberOfProperties(
1955 HandleScope scope; 2047 RUNTIME_CALLING_CONVENTION) {
2048 RUNTIME_GET_ISOLATE;
2049 HandleScope scope(isolate);
1956 ASSERT(args.length() == 2); 2050 ASSERT(args.length() == 2);
1957 CONVERT_ARG_CHECKED(JSFunction, function, 0); 2051 CONVERT_ARG_CHECKED(JSFunction, function, 0);
1958 CONVERT_SMI_CHECKED(num, args[1]); 2052 CONVERT_SMI_CHECKED(num, args[1]);
1959 RUNTIME_ASSERT(num >= 0); 2053 RUNTIME_ASSERT(num >= 0);
1960 SetExpectedNofProperties(function, num); 2054 SetExpectedNofProperties(function, num);
1961 return Heap::undefined_value(); 2055 return isolate->heap()->undefined_value();
1962 } 2056 }
1963 2057
1964 2058
1965 MUST_USE_RESULT static MaybeObject* CharFromCode(Object* char_code) { 2059 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate,
2060 Object* char_code) {
1966 uint32_t code; 2061 uint32_t code;
1967 if (char_code->ToArrayIndex(&code)) { 2062 if (char_code->ToArrayIndex(&code)) {
1968 if (code <= 0xffff) { 2063 if (code <= 0xffff) {
1969 return Heap::LookupSingleCharacterStringFromCode(code); 2064 return isolate->heap()->LookupSingleCharacterStringFromCode(code);
1970 } 2065 }
1971 } 2066 }
1972 return Heap::empty_string(); 2067 return isolate->heap()->empty_string();
1973 } 2068 }
1974 2069
1975 2070
1976 static MaybeObject* Runtime_StringCharCodeAt(Arguments args) { 2071 static MaybeObject* Runtime_StringCharCodeAt(RUNTIME_CALLING_CONVENTION) {
2072 RUNTIME_GET_ISOLATE;
1977 NoHandleAllocation ha; 2073 NoHandleAllocation ha;
1978 ASSERT(args.length() == 2); 2074 ASSERT(args.length() == 2);
1979 2075
1980 CONVERT_CHECKED(String, subject, args[0]); 2076 CONVERT_CHECKED(String, subject, args[0]);
1981 Object* index = args[1]; 2077 Object* index = args[1];
1982 RUNTIME_ASSERT(index->IsNumber()); 2078 RUNTIME_ASSERT(index->IsNumber());
1983 2079
1984 uint32_t i = 0; 2080 uint32_t i = 0;
1985 if (index->IsSmi()) { 2081 if (index->IsSmi()) {
1986 int value = Smi::cast(index)->value(); 2082 int value = Smi::cast(index)->value();
1987 if (value < 0) return Heap::nan_value(); 2083 if (value < 0) return isolate->heap()->nan_value();
1988 i = value; 2084 i = value;
1989 } else { 2085 } else {
1990 ASSERT(index->IsHeapNumber()); 2086 ASSERT(index->IsHeapNumber());
1991 double value = HeapNumber::cast(index)->value(); 2087 double value = HeapNumber::cast(index)->value();
1992 i = static_cast<uint32_t>(DoubleToInteger(value)); 2088 i = static_cast<uint32_t>(DoubleToInteger(value));
1993 } 2089 }
1994 2090
1995 // Flatten the string. If someone wants to get a char at an index 2091 // Flatten the string. If someone wants to get a char at an index
1996 // in a cons string, it is likely that more indices will be 2092 // in a cons string, it is likely that more indices will be
1997 // accessed. 2093 // accessed.
1998 Object* flat; 2094 Object* flat;
1999 { MaybeObject* maybe_flat = subject->TryFlatten(); 2095 { MaybeObject* maybe_flat = subject->TryFlatten();
2000 if (!maybe_flat->ToObject(&flat)) return maybe_flat; 2096 if (!maybe_flat->ToObject(&flat)) return maybe_flat;
2001 } 2097 }
2002 subject = String::cast(flat); 2098 subject = String::cast(flat);
2003 2099
2004 if (i >= static_cast<uint32_t>(subject->length())) { 2100 if (i >= static_cast<uint32_t>(subject->length())) {
2005 return Heap::nan_value(); 2101 return isolate->heap()->nan_value();
2006 } 2102 }
2007 2103
2008 return Smi::FromInt(subject->Get(i)); 2104 return Smi::FromInt(subject->Get(i));
2009 } 2105 }
2010 2106
2011 2107
2012 static MaybeObject* Runtime_CharFromCode(Arguments args) { 2108 static MaybeObject* Runtime_CharFromCode(RUNTIME_CALLING_CONVENTION) {
2109 RUNTIME_GET_ISOLATE;
2013 NoHandleAllocation ha; 2110 NoHandleAllocation ha;
2014 ASSERT(args.length() == 1); 2111 ASSERT(args.length() == 1);
2015 return CharFromCode(args[0]); 2112 return CharFromCode(isolate, args[0]);
2016 } 2113 }
2017 2114
2018 2115
2019 class FixedArrayBuilder { 2116 class FixedArrayBuilder {
2020 public: 2117 public:
2021 explicit FixedArrayBuilder(int initial_capacity) 2118 explicit FixedArrayBuilder(Isolate* isolate, int initial_capacity)
2022 : array_(Factory::NewFixedArrayWithHoles(initial_capacity)), 2119 : array_(isolate->factory()->NewFixedArrayWithHoles(initial_capacity)),
2023 length_(0) { 2120 length_(0) {
2024 // Require a non-zero initial size. Ensures that doubling the size to 2121 // Require a non-zero initial size. Ensures that doubling the size to
2025 // extend the array will work. 2122 // extend the array will work.
2026 ASSERT(initial_capacity > 0); 2123 ASSERT(initial_capacity > 0);
2027 } 2124 }
2028 2125
2029 explicit FixedArrayBuilder(Handle<FixedArray> backing_store) 2126 explicit FixedArrayBuilder(Handle<FixedArray> backing_store)
2030 : array_(backing_store), 2127 : array_(backing_store),
2031 length_(0) { 2128 length_(0) {
2032 // Require a non-zero initial size. Ensures that doubling the size to 2129 // Require a non-zero initial size. Ensures that doubling the size to
2033 // extend the array will work. 2130 // extend the array will work.
2034 ASSERT(backing_store->length() > 0); 2131 ASSERT(backing_store->length() > 0);
2035 } 2132 }
2036 2133
2037 bool HasCapacity(int elements) { 2134 bool HasCapacity(int elements) {
2038 int length = array_->length(); 2135 int length = array_->length();
2039 int required_length = length_ + elements; 2136 int required_length = length_ + elements;
2040 return (length >= required_length); 2137 return (length >= required_length);
2041 } 2138 }
2042 2139
2043 void EnsureCapacity(int elements) { 2140 void EnsureCapacity(int elements) {
2044 int length = array_->length(); 2141 int length = array_->length();
2045 int required_length = length_ + elements; 2142 int required_length = length_ + elements;
2046 if (length < required_length) { 2143 if (length < required_length) {
2047 int new_length = length; 2144 int new_length = length;
2048 do { 2145 do {
2049 new_length *= 2; 2146 new_length *= 2;
2050 } while (new_length < required_length); 2147 } while (new_length < required_length);
2051 Handle<FixedArray> extended_array = 2148 Handle<FixedArray> extended_array =
2052 Factory::NewFixedArrayWithHoles(new_length); 2149 array_->GetIsolate()->factory()->NewFixedArrayWithHoles(new_length);
2053 array_->CopyTo(0, *extended_array, 0, length_); 2150 array_->CopyTo(0, *extended_array, 0, length_);
2054 array_ = extended_array; 2151 array_ = extended_array;
2055 } 2152 }
2056 } 2153 }
2057 2154
2058 void Add(Object* value) { 2155 void Add(Object* value) {
2059 ASSERT(length_ < capacity()); 2156 ASSERT(length_ < capacity());
2060 array_->set(length_, value); 2157 array_->set(length_, value);
2061 length_++; 2158 length_++;
2062 } 2159 }
(...skipping 10 matching lines...) Expand all
2073 2170
2074 int length() { 2171 int length() {
2075 return length_; 2172 return length_;
2076 } 2173 }
2077 2174
2078 int capacity() { 2175 int capacity() {
2079 return array_->length(); 2176 return array_->length();
2080 } 2177 }
2081 2178
2082 Handle<JSArray> ToJSArray() { 2179 Handle<JSArray> ToJSArray() {
2083 Handle<JSArray> result_array = Factory::NewJSArrayWithElements(array_); 2180 Handle<JSArray> result_array = FACTORY->NewJSArrayWithElements(array_);
2084 result_array->set_length(Smi::FromInt(length_)); 2181 result_array->set_length(Smi::FromInt(length_));
2085 return result_array; 2182 return result_array;
2086 } 2183 }
2087 2184
2088 Handle<JSArray> ToJSArray(Handle<JSArray> target_array) { 2185 Handle<JSArray> ToJSArray(Handle<JSArray> target_array) {
2089 target_array->set_elements(*array_); 2186 target_array->set_elements(*array_);
2090 target_array->set_length(Smi::FromInt(length_)); 2187 target_array->set_length(Smi::FromInt(length_));
2091 return target_array; 2188 return target_array;
2092 } 2189 }
2093 2190
(...skipping 16 matching lines...) Expand all
2110 typedef BitField<int, 0, kStringBuilderConcatHelperLengthBits> 2207 typedef BitField<int, 0, kStringBuilderConcatHelperLengthBits>
2111 StringBuilderSubstringLength; 2208 StringBuilderSubstringLength;
2112 typedef BitField<int, 2209 typedef BitField<int,
2113 kStringBuilderConcatHelperLengthBits, 2210 kStringBuilderConcatHelperLengthBits,
2114 kStringBuilderConcatHelperPositionBits> 2211 kStringBuilderConcatHelperPositionBits>
2115 StringBuilderSubstringPosition; 2212 StringBuilderSubstringPosition;
2116 2213
2117 2214
2118 class ReplacementStringBuilder { 2215 class ReplacementStringBuilder {
2119 public: 2216 public:
2120 ReplacementStringBuilder(Handle<String> subject, int estimated_part_count) 2217 ReplacementStringBuilder(Heap* heap,
2121 : array_builder_(estimated_part_count), 2218 Handle<String> subject,
2219 int estimated_part_count)
2220 : heap_(heap),
2221 array_builder_(heap->isolate(), estimated_part_count),
2122 subject_(subject), 2222 subject_(subject),
2123 character_count_(0), 2223 character_count_(0),
2124 is_ascii_(subject->IsAsciiRepresentation()) { 2224 is_ascii_(subject->IsAsciiRepresentation()) {
2125 // Require a non-zero initial size. Ensures that doubling the size to 2225 // Require a non-zero initial size. Ensures that doubling the size to
2126 // extend the array will work. 2226 // extend the array will work.
2127 ASSERT(estimated_part_count > 0); 2227 ASSERT(estimated_part_count > 0);
2128 } 2228 }
2129 2229
2130 static inline void AddSubjectSlice(FixedArrayBuilder* builder, 2230 static inline void AddSubjectSlice(FixedArrayBuilder* builder,
2131 int from, 2231 int from,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 AddElement(*string); 2263 AddElement(*string);
2164 if (!string->IsAsciiRepresentation()) { 2264 if (!string->IsAsciiRepresentation()) {
2165 is_ascii_ = false; 2265 is_ascii_ = false;
2166 } 2266 }
2167 IncrementCharacterCount(length); 2267 IncrementCharacterCount(length);
2168 } 2268 }
2169 2269
2170 2270
2171 Handle<String> ToString() { 2271 Handle<String> ToString() {
2172 if (array_builder_.length() == 0) { 2272 if (array_builder_.length() == 0) {
2173 return Factory::empty_string(); 2273 return heap_->isolate()->factory()->empty_string();
2174 } 2274 }
2175 2275
2176 Handle<String> joined_string; 2276 Handle<String> joined_string;
2177 if (is_ascii_) { 2277 if (is_ascii_) {
2178 joined_string = NewRawAsciiString(character_count_); 2278 joined_string = NewRawAsciiString(character_count_);
2179 AssertNoAllocation no_alloc; 2279 AssertNoAllocation no_alloc;
2180 SeqAsciiString* seq = SeqAsciiString::cast(*joined_string); 2280 SeqAsciiString* seq = SeqAsciiString::cast(*joined_string);
2181 char* char_buffer = seq->GetChars(); 2281 char* char_buffer = seq->GetChars();
2182 StringBuilderConcatHelper(*subject_, 2282 StringBuilderConcatHelper(*subject_,
2183 char_buffer, 2283 char_buffer,
(...skipping 20 matching lines...) Expand all
2204 } 2304 }
2205 character_count_ += by; 2305 character_count_ += by;
2206 } 2306 }
2207 2307
2208 Handle<JSArray> GetParts() { 2308 Handle<JSArray> GetParts() {
2209 return array_builder_.ToJSArray(); 2309 return array_builder_.ToJSArray();
2210 } 2310 }
2211 2311
2212 private: 2312 private:
2213 Handle<String> NewRawAsciiString(int size) { 2313 Handle<String> NewRawAsciiString(int size) {
2214 CALL_HEAP_FUNCTION(Heap::AllocateRawAsciiString(size), String); 2314 CALL_HEAP_FUNCTION(heap_->isolate(),
2315 heap_->AllocateRawAsciiString(size), String);
2215 } 2316 }
2216 2317
2217 2318
2218 Handle<String> NewRawTwoByteString(int size) { 2319 Handle<String> NewRawTwoByteString(int size) {
2219 CALL_HEAP_FUNCTION(Heap::AllocateRawTwoByteString(size), String); 2320 CALL_HEAP_FUNCTION(heap_->isolate(),
2321 heap_->AllocateRawTwoByteString(size), String);
2220 } 2322 }
2221 2323
2222 2324
2223 void AddElement(Object* element) { 2325 void AddElement(Object* element) {
2224 ASSERT(element->IsSmi() || element->IsString()); 2326 ASSERT(element->IsSmi() || element->IsString());
2225 ASSERT(array_builder_.capacity() > array_builder_.length()); 2327 ASSERT(array_builder_.capacity() > array_builder_.length());
2226 array_builder_.Add(element); 2328 array_builder_.Add(element);
2227 } 2329 }
2228 2330
2331 Heap* heap_;
2229 FixedArrayBuilder array_builder_; 2332 FixedArrayBuilder array_builder_;
2230 Handle<String> subject_; 2333 Handle<String> subject_;
2231 int character_count_; 2334 int character_count_;
2232 bool is_ascii_; 2335 bool is_ascii_;
2233 }; 2336 };
2234 2337
2235 2338
2236 class CompiledReplacement { 2339 class CompiledReplacement {
2237 public: 2340 public:
2238 CompiledReplacement() 2341 CompiledReplacement()
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 subject_length); 2532 subject_length);
2430 } else { 2533 } else {
2431 ASSERT(replacement->IsTwoByteRepresentation()); 2534 ASSERT(replacement->IsTwoByteRepresentation());
2432 AssertNoAllocation no_alloc; 2535 AssertNoAllocation no_alloc;
2433 2536
2434 ParseReplacementPattern(&parts_, 2537 ParseReplacementPattern(&parts_,
2435 replacement->ToUC16Vector(), 2538 replacement->ToUC16Vector(),
2436 capture_count, 2539 capture_count,
2437 subject_length); 2540 subject_length);
2438 } 2541 }
2542 Isolate* isolate = replacement->GetIsolate();
2439 // Find substrings of replacement string and create them as String objects. 2543 // Find substrings of replacement string and create them as String objects.
2440 int substring_index = 0; 2544 int substring_index = 0;
2441 for (int i = 0, n = parts_.length(); i < n; i++) { 2545 for (int i = 0, n = parts_.length(); i < n; i++) {
2442 int tag = parts_[i].tag; 2546 int tag = parts_[i].tag;
2443 if (tag <= 0) { // A replacement string slice. 2547 if (tag <= 0) { // A replacement string slice.
2444 int from = -tag; 2548 int from = -tag;
2445 int to = parts_[i].data; 2549 int to = parts_[i].data;
2446 replacement_substrings_.Add(Factory::NewSubString(replacement, from, to)); 2550 replacement_substrings_.Add(
2551 isolate->factory()->NewSubString(replacement, from, to));
2447 parts_[i].tag = REPLACEMENT_SUBSTRING; 2552 parts_[i].tag = REPLACEMENT_SUBSTRING;
2448 parts_[i].data = substring_index; 2553 parts_[i].data = substring_index;
2449 substring_index++; 2554 substring_index++;
2450 } else if (tag == REPLACEMENT_STRING) { 2555 } else if (tag == REPLACEMENT_STRING) {
2451 replacement_substrings_.Add(replacement); 2556 replacement_substrings_.Add(replacement);
2452 parts_[i].data = substring_index; 2557 parts_[i].data = substring_index;
2453 substring_index++; 2558 substring_index++;
2454 } 2559 }
2455 } 2560 }
2456 } 2561 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 break; 2594 break;
2490 default: 2595 default:
2491 UNREACHABLE(); 2596 UNREACHABLE();
2492 } 2597 }
2493 } 2598 }
2494 } 2599 }
2495 2600
2496 2601
2497 2602
2498 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( 2603 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString(
2604 Isolate* isolate,
2499 String* subject, 2605 String* subject,
2500 JSRegExp* regexp, 2606 JSRegExp* regexp,
2501 String* replacement, 2607 String* replacement,
2502 JSArray* last_match_info) { 2608 JSArray* last_match_info) {
2503 ASSERT(subject->IsFlat()); 2609 ASSERT(subject->IsFlat());
2504 ASSERT(replacement->IsFlat()); 2610 ASSERT(replacement->IsFlat());
2505 2611
2506 HandleScope handles; 2612 HandleScope handles(isolate);
2507 2613
2508 int length = subject->length(); 2614 int length = subject->length();
2509 Handle<String> subject_handle(subject); 2615 Handle<String> subject_handle(subject);
2510 Handle<JSRegExp> regexp_handle(regexp); 2616 Handle<JSRegExp> regexp_handle(regexp);
2511 Handle<String> replacement_handle(replacement); 2617 Handle<String> replacement_handle(replacement);
2512 Handle<JSArray> last_match_info_handle(last_match_info); 2618 Handle<JSArray> last_match_info_handle(last_match_info);
2513 Handle<Object> match = RegExpImpl::Exec(regexp_handle, 2619 Handle<Object> match = RegExpImpl::Exec(regexp_handle,
2514 subject_handle, 2620 subject_handle,
2515 0, 2621 0,
2516 last_match_info_handle); 2622 last_match_info_handle);
(...skipping 13 matching lines...) Expand all
2530 capture_count, 2636 capture_count,
2531 length); 2637 length);
2532 2638
2533 bool is_global = regexp_handle->GetFlags().is_global(); 2639 bool is_global = regexp_handle->GetFlags().is_global();
2534 2640
2535 // Guessing the number of parts that the final result string is built 2641 // Guessing the number of parts that the final result string is built
2536 // from. Global regexps can match any number of times, so we guess 2642 // from. Global regexps can match any number of times, so we guess
2537 // conservatively. 2643 // conservatively.
2538 int expected_parts = 2644 int expected_parts =
2539 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; 2645 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1;
2540 ReplacementStringBuilder builder(subject_handle, expected_parts); 2646 ReplacementStringBuilder builder(isolate->heap(),
2647 subject_handle,
2648 expected_parts);
2541 2649
2542 // Index of end of last match. 2650 // Index of end of last match.
2543 int prev = 0; 2651 int prev = 0;
2544 2652
2545 // Number of parts added by compiled replacement plus preceeding 2653 // Number of parts added by compiled replacement plus preceeding
2546 // string and possibly suffix after last match. It is possible for 2654 // string and possibly suffix after last match. It is possible for
2547 // all components to use two elements when encoded as two smis. 2655 // all components to use two elements when encoded as two smis.
2548 const int parts_added_per_loop = 2 * (compiled_replacement.parts() + 2); 2656 const int parts_added_per_loop = 2 * (compiled_replacement.parts() + 2);
2549 bool matched = true; 2657 bool matched = true;
2550 do { 2658 do {
2551 ASSERT(last_match_info_handle->HasFastElements()); 2659 ASSERT(last_match_info_handle->HasFastElements());
2552 // Increase the capacity of the builder before entering local handle-scope, 2660 // Increase the capacity of the builder before entering local handle-scope,
2553 // so its internal buffer can safely allocate a new handle if it grows. 2661 // so its internal buffer can safely allocate a new handle if it grows.
2554 builder.EnsureCapacity(parts_added_per_loop); 2662 builder.EnsureCapacity(parts_added_per_loop);
2555 2663
2556 HandleScope loop_scope; 2664 HandleScope loop_scope(isolate);
2557 int start, end; 2665 int start, end;
2558 { 2666 {
2559 AssertNoAllocation match_info_array_is_not_in_a_handle; 2667 AssertNoAllocation match_info_array_is_not_in_a_handle;
2560 FixedArray* match_info_array = 2668 FixedArray* match_info_array =
2561 FixedArray::cast(last_match_info_handle->elements()); 2669 FixedArray::cast(last_match_info_handle->elements());
2562 2670
2563 ASSERT_EQ(capture_count * 2 + 2, 2671 ASSERT_EQ(capture_count * 2 + 2,
2564 RegExpImpl::GetLastCaptureCount(match_info_array)); 2672 RegExpImpl::GetLastCaptureCount(match_info_array));
2565 start = RegExpImpl::GetCapture(match_info_array, 0); 2673 start = RegExpImpl::GetCapture(match_info_array, 0);
2566 end = RegExpImpl::GetCapture(match_info_array, 1); 2674 end = RegExpImpl::GetCapture(match_info_array, 1);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 if (prev < length) { 2706 if (prev < length) {
2599 builder.AddSubjectSlice(prev, length); 2707 builder.AddSubjectSlice(prev, length);
2600 } 2708 }
2601 2709
2602 return *(builder.ToString()); 2710 return *(builder.ToString());
2603 } 2711 }
2604 2712
2605 2713
2606 template <typename ResultSeqString> 2714 template <typename ResultSeqString>
2607 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( 2715 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString(
2716 Isolate* isolate,
2608 String* subject, 2717 String* subject,
2609 JSRegExp* regexp, 2718 JSRegExp* regexp,
2610 JSArray* last_match_info) { 2719 JSArray* last_match_info) {
2611 ASSERT(subject->IsFlat()); 2720 ASSERT(subject->IsFlat());
2612 2721
2613 HandleScope handles; 2722 HandleScope handles(isolate);
2614 2723
2615 Handle<String> subject_handle(subject); 2724 Handle<String> subject_handle(subject);
2616 Handle<JSRegExp> regexp_handle(regexp); 2725 Handle<JSRegExp> regexp_handle(regexp);
2617 Handle<JSArray> last_match_info_handle(last_match_info); 2726 Handle<JSArray> last_match_info_handle(last_match_info);
2618 Handle<Object> match = RegExpImpl::Exec(regexp_handle, 2727 Handle<Object> match = RegExpImpl::Exec(regexp_handle,
2619 subject_handle, 2728 subject_handle,
2620 0, 2729 0,
2621 last_match_info_handle); 2730 last_match_info_handle);
2622 if (match.is_null()) return Failure::Exception(); 2731 if (match.is_null()) return Failure::Exception();
2623 if (match->IsNull()) return *subject_handle; 2732 if (match->IsNull()) return *subject_handle;
2624 2733
2625 ASSERT(last_match_info_handle->HasFastElements()); 2734 ASSERT(last_match_info_handle->HasFastElements());
2626 2735
2627 HandleScope loop_scope;
2628 int start, end; 2736 int start, end;
2629 { 2737 {
2630 AssertNoAllocation match_info_array_is_not_in_a_handle; 2738 AssertNoAllocation match_info_array_is_not_in_a_handle;
2631 FixedArray* match_info_array = 2739 FixedArray* match_info_array =
2632 FixedArray::cast(last_match_info_handle->elements()); 2740 FixedArray::cast(last_match_info_handle->elements());
2633 2741
2634 start = RegExpImpl::GetCapture(match_info_array, 0); 2742 start = RegExpImpl::GetCapture(match_info_array, 0);
2635 end = RegExpImpl::GetCapture(match_info_array, 1); 2743 end = RegExpImpl::GetCapture(match_info_array, 1);
2636 } 2744 }
2637 2745
2638 int length = subject->length(); 2746 int length = subject->length();
2639 int new_length = length - (end - start); 2747 int new_length = length - (end - start);
2640 if (new_length == 0) { 2748 if (new_length == 0) {
2641 return Heap::empty_string(); 2749 return isolate->heap()->empty_string();
2642 } 2750 }
2643 Handle<ResultSeqString> answer; 2751 Handle<ResultSeqString> answer;
2644 if (ResultSeqString::kHasAsciiEncoding) { 2752 if (ResultSeqString::kHasAsciiEncoding) {
2645 answer = 2753 answer = Handle<ResultSeqString>::cast(
2646 Handle<ResultSeqString>::cast(Factory::NewRawAsciiString(new_length)); 2754 isolate->factory()->NewRawAsciiString(new_length));
2647 } else { 2755 } else {
2648 answer = 2756 answer = Handle<ResultSeqString>::cast(
2649 Handle<ResultSeqString>::cast(Factory::NewRawTwoByteString(new_length)); 2757 isolate->factory()->NewRawTwoByteString(new_length));
2650 } 2758 }
2651 2759
2652 // If the regexp isn't global, only match once. 2760 // If the regexp isn't global, only match once.
2653 if (!regexp_handle->GetFlags().is_global()) { 2761 if (!regexp_handle->GetFlags().is_global()) {
2654 if (start > 0) { 2762 if (start > 0) {
2655 String::WriteToFlat(*subject_handle, 2763 String::WriteToFlat(*subject_handle,
2656 answer->GetChars(), 2764 answer->GetChars(),
2657 0, 2765 0,
2658 start); 2766 start);
2659 } 2767 }
(...skipping 27 matching lines...) Expand all
2687 if (next > length) break; 2795 if (next > length) break;
2688 } 2796 }
2689 match = RegExpImpl::Exec(regexp_handle, 2797 match = RegExpImpl::Exec(regexp_handle,
2690 subject_handle, 2798 subject_handle,
2691 next, 2799 next,
2692 last_match_info_handle); 2800 last_match_info_handle);
2693 if (match.is_null()) return Failure::Exception(); 2801 if (match.is_null()) return Failure::Exception();
2694 if (match->IsNull()) break; 2802 if (match->IsNull()) break;
2695 2803
2696 ASSERT(last_match_info_handle->HasFastElements()); 2804 ASSERT(last_match_info_handle->HasFastElements());
2697 HandleScope loop_scope; 2805 HandleScope loop_scope(isolate);
2698 { 2806 {
2699 AssertNoAllocation match_info_array_is_not_in_a_handle; 2807 AssertNoAllocation match_info_array_is_not_in_a_handle;
2700 FixedArray* match_info_array = 2808 FixedArray* match_info_array =
2701 FixedArray::cast(last_match_info_handle->elements()); 2809 FixedArray::cast(last_match_info_handle->elements());
2702 start = RegExpImpl::GetCapture(match_info_array, 0); 2810 start = RegExpImpl::GetCapture(match_info_array, 0);
2703 end = RegExpImpl::GetCapture(match_info_array, 1); 2811 end = RegExpImpl::GetCapture(match_info_array, 1);
2704 } 2812 }
2705 } while (true); 2813 } while (true);
2706 2814
2707 if (prev < length) { 2815 if (prev < length) {
2708 // Add substring subject[prev;length] to answer string. 2816 // Add substring subject[prev;length] to answer string.
2709 String::WriteToFlat(*subject_handle, 2817 String::WriteToFlat(*subject_handle,
2710 answer->GetChars() + position, 2818 answer->GetChars() + position,
2711 prev, 2819 prev,
2712 length); 2820 length);
2713 position += length - prev; 2821 position += length - prev;
2714 } 2822 }
2715 2823
2716 if (position == 0) { 2824 if (position == 0) {
2717 return Heap::empty_string(); 2825 return isolate->heap()->empty_string();
2718 } 2826 }
2719 2827
2720 // Shorten string and fill 2828 // Shorten string and fill
2721 int string_size = ResultSeqString::SizeFor(position); 2829 int string_size = ResultSeqString::SizeFor(position);
2722 int allocated_string_size = ResultSeqString::SizeFor(new_length); 2830 int allocated_string_size = ResultSeqString::SizeFor(new_length);
2723 int delta = allocated_string_size - string_size; 2831 int delta = allocated_string_size - string_size;
2724 2832
2725 answer->set_length(position); 2833 answer->set_length(position);
2726 if (delta == 0) return *answer; 2834 if (delta == 0) return *answer;
2727 2835
2728 Address end_of_string = answer->address() + string_size; 2836 Address end_of_string = answer->address() + string_size;
2729 Heap::CreateFillerObjectAt(end_of_string, delta); 2837 isolate->heap()->CreateFillerObjectAt(end_of_string, delta);
2730 2838
2731 return *answer; 2839 return *answer;
2732 } 2840 }
2733 2841
2734 2842
2735 static MaybeObject* Runtime_StringReplaceRegExpWithString(Arguments args) { 2843 static MaybeObject* Runtime_StringReplaceRegExpWithString(
2844 RUNTIME_CALLING_CONVENTION) {
2845 RUNTIME_GET_ISOLATE;
2736 ASSERT(args.length() == 4); 2846 ASSERT(args.length() == 4);
2737 2847
2738 CONVERT_CHECKED(String, subject, args[0]); 2848 CONVERT_CHECKED(String, subject, args[0]);
2739 if (!subject->IsFlat()) { 2849 if (!subject->IsFlat()) {
2740 Object* flat_subject; 2850 Object* flat_subject;
2741 { MaybeObject* maybe_flat_subject = subject->TryFlatten(); 2851 { MaybeObject* maybe_flat_subject = subject->TryFlatten();
2742 if (!maybe_flat_subject->ToObject(&flat_subject)) { 2852 if (!maybe_flat_subject->ToObject(&flat_subject)) {
2743 return maybe_flat_subject; 2853 return maybe_flat_subject;
2744 } 2854 }
2745 } 2855 }
(...skipping 12 matching lines...) Expand all
2758 } 2868 }
2759 2869
2760 CONVERT_CHECKED(JSRegExp, regexp, args[1]); 2870 CONVERT_CHECKED(JSRegExp, regexp, args[1]);
2761 CONVERT_CHECKED(JSArray, last_match_info, args[3]); 2871 CONVERT_CHECKED(JSArray, last_match_info, args[3]);
2762 2872
2763 ASSERT(last_match_info->HasFastElements()); 2873 ASSERT(last_match_info->HasFastElements());
2764 2874
2765 if (replacement->length() == 0) { 2875 if (replacement->length() == 0) {
2766 if (subject->HasOnlyAsciiChars()) { 2876 if (subject->HasOnlyAsciiChars()) {
2767 return StringReplaceRegExpWithEmptyString<SeqAsciiString>( 2877 return StringReplaceRegExpWithEmptyString<SeqAsciiString>(
2768 subject, regexp, last_match_info); 2878 isolate, subject, regexp, last_match_info);
2769 } else { 2879 } else {
2770 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( 2880 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>(
2771 subject, regexp, last_match_info); 2881 isolate, subject, regexp, last_match_info);
2772 } 2882 }
2773 } 2883 }
2774 2884
2775 return StringReplaceRegExpWithString(subject, 2885 return StringReplaceRegExpWithString(isolate,
2886 subject,
2776 regexp, 2887 regexp,
2777 replacement, 2888 replacement,
2778 last_match_info); 2889 last_match_info);
2779 } 2890 }
2780 2891
2781 2892
2782 // Perform string match of pattern on subject, starting at start index. 2893 // Perform string match of pattern on subject, starting at start index.
2783 // Caller must ensure that 0 <= start_index <= sub->length(), 2894 // Caller must ensure that 0 <= start_index <= sub->length(),
2784 // and should check that pat->length() + start_index <= sub->length(). 2895 // and should check that pat->length() + start_index <= sub->length().
2785 int Runtime::StringMatch(Handle<String> sub, 2896 int Runtime::StringMatch(Isolate* isolate,
2897 Handle<String> sub,
2786 Handle<String> pat, 2898 Handle<String> pat,
2787 int start_index) { 2899 int start_index) {
2788 ASSERT(0 <= start_index); 2900 ASSERT(0 <= start_index);
2789 ASSERT(start_index <= sub->length()); 2901 ASSERT(start_index <= sub->length());
2790 2902
2791 int pattern_length = pat->length(); 2903 int pattern_length = pat->length();
2792 if (pattern_length == 0) return start_index; 2904 if (pattern_length == 0) return start_index;
2793 2905
2794 int subject_length = sub->length(); 2906 int subject_length = sub->length();
2795 if (start_index + pattern_length > subject_length) return -1; 2907 if (start_index + pattern_length > subject_length) return -1;
2796 2908
2797 if (!sub->IsFlat()) FlattenString(sub); 2909 if (!sub->IsFlat()) FlattenString(sub);
2798 if (!pat->IsFlat()) FlattenString(pat); 2910 if (!pat->IsFlat()) FlattenString(pat);
2799 2911
2800 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid 2912 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
2801 // Extract flattened substrings of cons strings before determining asciiness. 2913 // Extract flattened substrings of cons strings before determining asciiness.
2802 String* seq_sub = *sub; 2914 String* seq_sub = *sub;
2803 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); 2915 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first();
2804 String* seq_pat = *pat; 2916 String* seq_pat = *pat;
2805 if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first(); 2917 if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first();
2806 2918
2807 // dispatch on type of strings 2919 // dispatch on type of strings
2808 if (seq_pat->IsAsciiRepresentation()) { 2920 if (seq_pat->IsAsciiRepresentation()) {
2809 Vector<const char> pat_vector = seq_pat->ToAsciiVector(); 2921 Vector<const char> pat_vector = seq_pat->ToAsciiVector();
2810 if (seq_sub->IsAsciiRepresentation()) { 2922 if (seq_sub->IsAsciiRepresentation()) {
2811 return SearchString(seq_sub->ToAsciiVector(), pat_vector, start_index); 2923 return SearchString(isolate,
2924 seq_sub->ToAsciiVector(),
2925 pat_vector,
2926 start_index);
2812 } 2927 }
2813 return SearchString(seq_sub->ToUC16Vector(), pat_vector, start_index); 2928 return SearchString(isolate,
2929 seq_sub->ToUC16Vector(),
2930 pat_vector,
2931 start_index);
2814 } 2932 }
2815 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector(); 2933 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector();
2816 if (seq_sub->IsAsciiRepresentation()) { 2934 if (seq_sub->IsAsciiRepresentation()) {
2817 return SearchString(seq_sub->ToAsciiVector(), pat_vector, start_index); 2935 return SearchString(isolate,
2936 seq_sub->ToAsciiVector(),
2937 pat_vector,
2938 start_index);
2818 } 2939 }
2819 return SearchString(seq_sub->ToUC16Vector(), pat_vector, start_index); 2940 return SearchString(isolate,
2941 seq_sub->ToUC16Vector(),
2942 pat_vector,
2943 start_index);
2820 } 2944 }
2821 2945
2822 2946
2823 static MaybeObject* Runtime_StringIndexOf(Arguments args) { 2947 static MaybeObject* Runtime_StringIndexOf(RUNTIME_CALLING_CONVENTION) {
2824 HandleScope scope; // create a new handle scope 2948 RUNTIME_GET_ISOLATE;
2949 HandleScope scope(isolate); // create a new handle scope
2825 ASSERT(args.length() == 3); 2950 ASSERT(args.length() == 3);
2826 2951
2827 CONVERT_ARG_CHECKED(String, sub, 0); 2952 CONVERT_ARG_CHECKED(String, sub, 0);
2828 CONVERT_ARG_CHECKED(String, pat, 1); 2953 CONVERT_ARG_CHECKED(String, pat, 1);
2829 2954
2830 Object* index = args[2]; 2955 Object* index = args[2];
2831 uint32_t start_index; 2956 uint32_t start_index;
2832 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1); 2957 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);
2833 2958
2834 RUNTIME_ASSERT(start_index <= static_cast<uint32_t>(sub->length())); 2959 RUNTIME_ASSERT(start_index <= static_cast<uint32_t>(sub->length()));
2835 int position = Runtime::StringMatch(sub, pat, start_index); 2960 int position =
2961 Runtime::StringMatch(isolate, sub, pat, start_index);
2836 return Smi::FromInt(position); 2962 return Smi::FromInt(position);
2837 } 2963 }
2838 2964
2839 2965
2840 template <typename schar, typename pchar> 2966 template <typename schar, typename pchar>
2841 static int StringMatchBackwards(Vector<const schar> subject, 2967 static int StringMatchBackwards(Vector<const schar> subject,
2842 Vector<const pchar> pattern, 2968 Vector<const pchar> pattern,
2843 int idx) { 2969 int idx) {
2844 int pattern_length = pattern.length(); 2970 int pattern_length = pattern.length();
2845 ASSERT(pattern_length >= 1); 2971 ASSERT(pattern_length >= 1);
(...skipping 18 matching lines...) Expand all
2864 } 2990 }
2865 j++; 2991 j++;
2866 } 2992 }
2867 if (j == pattern_length) { 2993 if (j == pattern_length) {
2868 return i; 2994 return i;
2869 } 2995 }
2870 } 2996 }
2871 return -1; 2997 return -1;
2872 } 2998 }
2873 2999
2874 static MaybeObject* Runtime_StringLastIndexOf(Arguments args) { 3000 static MaybeObject* Runtime_StringLastIndexOf(RUNTIME_CALLING_CONVENTION) {
2875 HandleScope scope; // create a new handle scope 3001 RUNTIME_GET_ISOLATE;
3002 HandleScope scope(isolate); // create a new handle scope
2876 ASSERT(args.length() == 3); 3003 ASSERT(args.length() == 3);
2877 3004
2878 CONVERT_ARG_CHECKED(String, sub, 0); 3005 CONVERT_ARG_CHECKED(String, sub, 0);
2879 CONVERT_ARG_CHECKED(String, pat, 1); 3006 CONVERT_ARG_CHECKED(String, pat, 1);
2880 3007
2881 Object* index = args[2]; 3008 Object* index = args[2];
2882 uint32_t start_index; 3009 uint32_t start_index;
2883 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1); 3010 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);
2884 3011
2885 uint32_t pat_length = pat->length(); 3012 uint32_t pat_length = pat->length();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2921 position = StringMatchBackwards(sub->ToUC16Vector(), 3048 position = StringMatchBackwards(sub->ToUC16Vector(),
2922 pat_vector, 3049 pat_vector,
2923 start_index); 3050 start_index);
2924 } 3051 }
2925 } 3052 }
2926 3053
2927 return Smi::FromInt(position); 3054 return Smi::FromInt(position);
2928 } 3055 }
2929 3056
2930 3057
2931 static MaybeObject* Runtime_StringLocaleCompare(Arguments args) { 3058 static MaybeObject* Runtime_StringLocaleCompare(RUNTIME_CALLING_CONVENTION) {
3059 RUNTIME_GET_ISOLATE;
2932 NoHandleAllocation ha; 3060 NoHandleAllocation ha;
2933 ASSERT(args.length() == 2); 3061 ASSERT(args.length() == 2);
2934 3062
2935 CONVERT_CHECKED(String, str1, args[0]); 3063 CONVERT_CHECKED(String, str1, args[0]);
2936 CONVERT_CHECKED(String, str2, args[1]); 3064 CONVERT_CHECKED(String, str2, args[1]);
2937 3065
2938 if (str1 == str2) return Smi::FromInt(0); // Equal. 3066 if (str1 == str2) return Smi::FromInt(0); // Equal.
2939 int str1_length = str1->length(); 3067 int str1_length = str1->length();
2940 int str2_length = str2->length(); 3068 int str2_length = str2->length();
2941 3069
2942 // Decide trivial cases without flattening. 3070 // Decide trivial cases without flattening.
2943 if (str1_length == 0) { 3071 if (str1_length == 0) {
2944 if (str2_length == 0) return Smi::FromInt(0); // Equal. 3072 if (str2_length == 0) return Smi::FromInt(0); // Equal.
2945 return Smi::FromInt(-str2_length); 3073 return Smi::FromInt(-str2_length);
2946 } else { 3074 } else {
2947 if (str2_length == 0) return Smi::FromInt(str1_length); 3075 if (str2_length == 0) return Smi::FromInt(str1_length);
2948 } 3076 }
2949 3077
2950 int end = str1_length < str2_length ? str1_length : str2_length; 3078 int end = str1_length < str2_length ? str1_length : str2_length;
2951 3079
2952 // No need to flatten if we are going to find the answer on the first 3080 // No need to flatten if we are going to find the answer on the first
2953 // character. At this point we know there is at least one character 3081 // character. At this point we know there is at least one character
2954 // in each string, due to the trivial case handling above. 3082 // in each string, due to the trivial case handling above.
2955 int d = str1->Get(0) - str2->Get(0); 3083 int d = str1->Get(0) - str2->Get(0);
2956 if (d != 0) return Smi::FromInt(d); 3084 if (d != 0) return Smi::FromInt(d);
2957 3085
2958 str1->TryFlatten(); 3086 str1->TryFlatten();
2959 str2->TryFlatten(); 3087 str2->TryFlatten();
2960 3088
2961 static StringInputBuffer buf1; 3089 StringInputBuffer& buf1 =
2962 static StringInputBuffer buf2; 3090 *isolate->runtime_state()->string_locale_compare_buf1();
3091 StringInputBuffer& buf2 =
3092 *isolate->runtime_state()->string_locale_compare_buf2();
2963 3093
2964 buf1.Reset(str1); 3094 buf1.Reset(str1);
2965 buf2.Reset(str2); 3095 buf2.Reset(str2);
2966 3096
2967 for (int i = 0; i < end; i++) { 3097 for (int i = 0; i < end; i++) {
2968 uint16_t char1 = buf1.GetNext(); 3098 uint16_t char1 = buf1.GetNext();
2969 uint16_t char2 = buf2.GetNext(); 3099 uint16_t char2 = buf2.GetNext();
2970 if (char1 != char2) return Smi::FromInt(char1 - char2); 3100 if (char1 != char2) return Smi::FromInt(char1 - char2);
2971 } 3101 }
2972 3102
2973 return Smi::FromInt(str1_length - str2_length); 3103 return Smi::FromInt(str1_length - str2_length);
2974 } 3104 }
2975 3105
2976 3106
2977 static MaybeObject* Runtime_SubString(Arguments args) { 3107 static MaybeObject* Runtime_SubString(RUNTIME_CALLING_CONVENTION) {
3108 RUNTIME_GET_ISOLATE;
2978 NoHandleAllocation ha; 3109 NoHandleAllocation ha;
2979 ASSERT(args.length() == 3); 3110 ASSERT(args.length() == 3);
2980 3111
2981 CONVERT_CHECKED(String, value, args[0]); 3112 CONVERT_CHECKED(String, value, args[0]);
2982 Object* from = args[1]; 3113 Object* from = args[1];
2983 Object* to = args[2]; 3114 Object* to = args[2];
2984 int start, end; 3115 int start, end;
2985 // We have a fast integer-only case here to avoid a conversion to double in 3116 // We have a fast integer-only case here to avoid a conversion to double in
2986 // the common case where from and to are Smis. 3117 // the common case where from and to are Smis.
2987 if (from->IsSmi() && to->IsSmi()) { 3118 if (from->IsSmi() && to->IsSmi()) {
2988 start = Smi::cast(from)->value(); 3119 start = Smi::cast(from)->value();
2989 end = Smi::cast(to)->value(); 3120 end = Smi::cast(to)->value();
2990 } else { 3121 } else {
2991 CONVERT_DOUBLE_CHECKED(from_number, from); 3122 CONVERT_DOUBLE_CHECKED(from_number, from);
2992 CONVERT_DOUBLE_CHECKED(to_number, to); 3123 CONVERT_DOUBLE_CHECKED(to_number, to);
2993 start = FastD2I(from_number); 3124 start = FastD2I(from_number);
2994 end = FastD2I(to_number); 3125 end = FastD2I(to_number);
2995 } 3126 }
2996 RUNTIME_ASSERT(end >= start); 3127 RUNTIME_ASSERT(end >= start);
2997 RUNTIME_ASSERT(start >= 0); 3128 RUNTIME_ASSERT(start >= 0);
2998 RUNTIME_ASSERT(end <= value->length()); 3129 RUNTIME_ASSERT(end <= value->length());
2999 Counters::sub_string_runtime.Increment(); 3130 isolate->counters()->sub_string_runtime()->Increment();
3000 return value->SubString(start, end); 3131 return value->SubString(start, end);
3001 } 3132 }
3002 3133
3003 3134
3004 static MaybeObject* Runtime_StringMatch(Arguments args) { 3135 static MaybeObject* Runtime_StringMatch(RUNTIME_CALLING_CONVENTION) {
3136 RUNTIME_GET_ISOLATE;
3005 ASSERT_EQ(3, args.length()); 3137 ASSERT_EQ(3, args.length());
3006 3138
3007 CONVERT_ARG_CHECKED(String, subject, 0); 3139 CONVERT_ARG_CHECKED(String, subject, 0);
3008 CONVERT_ARG_CHECKED(JSRegExp, regexp, 1); 3140 CONVERT_ARG_CHECKED(JSRegExp, regexp, 1);
3009 CONVERT_ARG_CHECKED(JSArray, regexp_info, 2); 3141 CONVERT_ARG_CHECKED(JSArray, regexp_info, 2);
3010 HandleScope handles; 3142 HandleScope handles;
3011 3143
3012 Handle<Object> match = RegExpImpl::Exec(regexp, subject, 0, regexp_info); 3144 Handle<Object> match = RegExpImpl::Exec(regexp, subject, 0, regexp_info);
3013 3145
3014 if (match.is_null()) { 3146 if (match.is_null()) {
3015 return Failure::Exception(); 3147 return Failure::Exception();
3016 } 3148 }
3017 if (match->IsNull()) { 3149 if (match->IsNull()) {
3018 return Heap::null_value(); 3150 return isolate->heap()->null_value();
3019 } 3151 }
3020 int length = subject->length(); 3152 int length = subject->length();
3021 3153
3022 CompilationZoneScope zone_space(DELETE_ON_EXIT); 3154 CompilationZoneScope zone_space(DELETE_ON_EXIT);
3023 ZoneList<int> offsets(8); 3155 ZoneList<int> offsets(8);
3024 do { 3156 do {
3025 int start; 3157 int start;
3026 int end; 3158 int end;
3027 { 3159 {
3028 AssertNoAllocation no_alloc; 3160 AssertNoAllocation no_alloc;
3029 FixedArray* elements = FixedArray::cast(regexp_info->elements()); 3161 FixedArray* elements = FixedArray::cast(regexp_info->elements());
3030 start = Smi::cast(elements->get(RegExpImpl::kFirstCapture))->value(); 3162 start = Smi::cast(elements->get(RegExpImpl::kFirstCapture))->value();
3031 end = Smi::cast(elements->get(RegExpImpl::kFirstCapture + 1))->value(); 3163 end = Smi::cast(elements->get(RegExpImpl::kFirstCapture + 1))->value();
3032 } 3164 }
3033 offsets.Add(start); 3165 offsets.Add(start);
3034 offsets.Add(end); 3166 offsets.Add(end);
3035 int index = start < end ? end : end + 1; 3167 int index = start < end ? end : end + 1;
3036 if (index > length) break; 3168 if (index > length) break;
3037 match = RegExpImpl::Exec(regexp, subject, index, regexp_info); 3169 match = RegExpImpl::Exec(regexp, subject, index, regexp_info);
3038 if (match.is_null()) { 3170 if (match.is_null()) {
3039 return Failure::Exception(); 3171 return Failure::Exception();
3040 } 3172 }
3041 } while (!match->IsNull()); 3173 } while (!match->IsNull());
3042 int matches = offsets.length() / 2; 3174 int matches = offsets.length() / 2;
3043 Handle<FixedArray> elements = Factory::NewFixedArray(matches); 3175 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(matches);
3044 for (int i = 0; i < matches ; i++) { 3176 for (int i = 0; i < matches ; i++) {
3045 int from = offsets.at(i * 2); 3177 int from = offsets.at(i * 2);
3046 int to = offsets.at(i * 2 + 1); 3178 int to = offsets.at(i * 2 + 1);
3047 Handle<String> match = Factory::NewSubString(subject, from, to); 3179 Handle<String> match = isolate->factory()->NewSubString(subject, from, to);
3048 elements->set(i, *match); 3180 elements->set(i, *match);
3049 } 3181 }
3050 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); 3182 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(elements);
3051 result->set_length(Smi::FromInt(matches)); 3183 result->set_length(Smi::FromInt(matches));
3052 return *result; 3184 return *result;
3053 } 3185 }
3054 3186
3055 3187
3056 // Two smis before and after the match, for very long strings. 3188 // Two smis before and after the match, for very long strings.
3057 const int kMaxBuilderEntriesPerRegExpMatch = 5; 3189 const int kMaxBuilderEntriesPerRegExpMatch = 5;
3058 3190
3059 3191
3060 static void SetLastMatchInfoNoCaptures(Handle<String> subject, 3192 static void SetLastMatchInfoNoCaptures(Handle<String> subject,
3061 Handle<JSArray> last_match_info, 3193 Handle<JSArray> last_match_info,
3062 int match_start, 3194 int match_start,
3063 int match_end) { 3195 int match_end) {
3064 // Fill last_match_info with a single capture. 3196 // Fill last_match_info with a single capture.
3065 last_match_info->EnsureSize(2 + RegExpImpl::kLastMatchOverhead); 3197 last_match_info->EnsureSize(2 + RegExpImpl::kLastMatchOverhead);
3066 AssertNoAllocation no_gc; 3198 AssertNoAllocation no_gc;
3067 FixedArray* elements = FixedArray::cast(last_match_info->elements()); 3199 FixedArray* elements = FixedArray::cast(last_match_info->elements());
3068 RegExpImpl::SetLastCaptureCount(elements, 2); 3200 RegExpImpl::SetLastCaptureCount(elements, 2);
3069 RegExpImpl::SetLastInput(elements, *subject); 3201 RegExpImpl::SetLastInput(elements, *subject);
3070 RegExpImpl::SetLastSubject(elements, *subject); 3202 RegExpImpl::SetLastSubject(elements, *subject);
3071 RegExpImpl::SetCapture(elements, 0, match_start); 3203 RegExpImpl::SetCapture(elements, 0, match_start);
3072 RegExpImpl::SetCapture(elements, 1, match_end); 3204 RegExpImpl::SetCapture(elements, 1, match_end);
3073 } 3205 }
3074 3206
3075 3207
3076 template <typename SubjectChar, typename PatternChar> 3208 template <typename SubjectChar, typename PatternChar>
3077 static bool SearchStringMultiple(Vector<const SubjectChar> subject, 3209 static bool SearchStringMultiple(Isolate* isolate,
3210 Vector<const SubjectChar> subject,
3078 Vector<const PatternChar> pattern, 3211 Vector<const PatternChar> pattern,
3079 String* pattern_string, 3212 String* pattern_string,
3080 FixedArrayBuilder* builder, 3213 FixedArrayBuilder* builder,
3081 int* match_pos) { 3214 int* match_pos) {
3082 int pos = *match_pos; 3215 int pos = *match_pos;
3083 int subject_length = subject.length(); 3216 int subject_length = subject.length();
3084 int pattern_length = pattern.length(); 3217 int pattern_length = pattern.length();
3085 int max_search_start = subject_length - pattern_length; 3218 int max_search_start = subject_length - pattern_length;
3086 StringSearch<PatternChar, SubjectChar> search(pattern); 3219 StringSearch<PatternChar, SubjectChar> search(isolate, pattern);
3087 while (pos <= max_search_start) { 3220 while (pos <= max_search_start) {
3088 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) { 3221 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) {
3089 *match_pos = pos; 3222 *match_pos = pos;
3090 return false; 3223 return false;
3091 } 3224 }
3092 // Position of end of previous match. 3225 // Position of end of previous match.
3093 int match_end = pos + pattern_length; 3226 int match_end = pos + pattern_length;
3094 int new_pos = search.Search(subject, match_end); 3227 int new_pos = search.Search(subject, match_end);
3095 if (new_pos >= 0) { 3228 if (new_pos >= 0) {
3096 // A match. 3229 // A match.
(...skipping 12 matching lines...) Expand all
3109 if (pos < max_search_start) { 3242 if (pos < max_search_start) {
3110 ReplacementStringBuilder::AddSubjectSlice(builder, 3243 ReplacementStringBuilder::AddSubjectSlice(builder,
3111 pos + pattern_length, 3244 pos + pattern_length,
3112 subject_length); 3245 subject_length);
3113 } 3246 }
3114 *match_pos = pos; 3247 *match_pos = pos;
3115 return true; 3248 return true;
3116 } 3249 }
3117 3250
3118 3251
3119 static bool SearchStringMultiple(Handle<String> subject, 3252 static bool SearchStringMultiple(Isolate* isolate,
3253 Handle<String> subject,
3120 Handle<String> pattern, 3254 Handle<String> pattern,
3121 Handle<JSArray> last_match_info, 3255 Handle<JSArray> last_match_info,
3122 FixedArrayBuilder* builder) { 3256 FixedArrayBuilder* builder) {
3123 ASSERT(subject->IsFlat()); 3257 ASSERT(subject->IsFlat());
3124 ASSERT(pattern->IsFlat()); 3258 ASSERT(pattern->IsFlat());
3125 3259
3126 // Treating as if a previous match was before first character. 3260 // Treating as if a previous match was before first character.
3127 int match_pos = -pattern->length(); 3261 int match_pos = -pattern->length();
3128 3262
3129 for (;;) { // Break when search complete. 3263 for (;;) { // Break when search complete.
3130 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); 3264 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch);
3131 AssertNoAllocation no_gc; 3265 AssertNoAllocation no_gc;
3132 if (subject->IsAsciiRepresentation()) { 3266 if (subject->IsAsciiRepresentation()) {
3133 Vector<const char> subject_vector = subject->ToAsciiVector(); 3267 Vector<const char> subject_vector = subject->ToAsciiVector();
3134 if (pattern->IsAsciiRepresentation()) { 3268 if (pattern->IsAsciiRepresentation()) {
3135 if (SearchStringMultiple(subject_vector, 3269 if (SearchStringMultiple(isolate,
3270 subject_vector,
3136 pattern->ToAsciiVector(), 3271 pattern->ToAsciiVector(),
3137 *pattern, 3272 *pattern,
3138 builder, 3273 builder,
3139 &match_pos)) break; 3274 &match_pos)) break;
3140 } else { 3275 } else {
3141 if (SearchStringMultiple(subject_vector, 3276 if (SearchStringMultiple(isolate,
3277 subject_vector,
3142 pattern->ToUC16Vector(), 3278 pattern->ToUC16Vector(),
3143 *pattern, 3279 *pattern,
3144 builder, 3280 builder,
3145 &match_pos)) break; 3281 &match_pos)) break;
3146 } 3282 }
3147 } else { 3283 } else {
3148 Vector<const uc16> subject_vector = subject->ToUC16Vector(); 3284 Vector<const uc16> subject_vector = subject->ToUC16Vector();
3149 if (pattern->IsAsciiRepresentation()) { 3285 if (pattern->IsAsciiRepresentation()) {
3150 if (SearchStringMultiple(subject_vector, 3286 if (SearchStringMultiple(isolate,
3287 subject_vector,
3151 pattern->ToAsciiVector(), 3288 pattern->ToAsciiVector(),
3152 *pattern, 3289 *pattern,
3153 builder, 3290 builder,
3154 &match_pos)) break; 3291 &match_pos)) break;
3155 } else { 3292 } else {
3156 if (SearchStringMultiple(subject_vector, 3293 if (SearchStringMultiple(isolate,
3294 subject_vector,
3157 pattern->ToUC16Vector(), 3295 pattern->ToUC16Vector(),
3158 *pattern, 3296 *pattern,
3159 builder, 3297 builder,
3160 &match_pos)) break; 3298 &match_pos)) break;
3161 } 3299 }
3162 } 3300 }
3163 } 3301 }
3164 3302
3165 if (match_pos >= 0) { 3303 if (match_pos >= 0) {
3166 SetLastMatchInfoNoCaptures(subject, 3304 SetLastMatchInfoNoCaptures(subject,
3167 last_match_info, 3305 last_match_info,
3168 match_pos, 3306 match_pos,
3169 match_pos + pattern->length()); 3307 match_pos + pattern->length());
3170 return true; 3308 return true;
3171 } 3309 }
3172 return false; // No matches at all. 3310 return false; // No matches at all.
3173 } 3311 }
3174 3312
3175 3313
3176 static RegExpImpl::IrregexpResult SearchRegExpNoCaptureMultiple( 3314 static RegExpImpl::IrregexpResult SearchRegExpNoCaptureMultiple(
3315 Isolate* isolate,
3177 Handle<String> subject, 3316 Handle<String> subject,
3178 Handle<JSRegExp> regexp, 3317 Handle<JSRegExp> regexp,
3179 Handle<JSArray> last_match_array, 3318 Handle<JSArray> last_match_array,
3180 FixedArrayBuilder* builder) { 3319 FixedArrayBuilder* builder) {
3181 ASSERT(subject->IsFlat()); 3320 ASSERT(subject->IsFlat());
3182 int match_start = -1; 3321 int match_start = -1;
3183 int match_end = 0; 3322 int match_end = 0;
3184 int pos = 0; 3323 int pos = 0;
3185 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); 3324 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject);
3186 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; 3325 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION;
(...skipping 10 matching lines...) Expand all
3197 register_vector); 3336 register_vector);
3198 if (result == RegExpImpl::RE_SUCCESS) { 3337 if (result == RegExpImpl::RE_SUCCESS) {
3199 match_start = register_vector[0]; 3338 match_start = register_vector[0];
3200 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); 3339 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch);
3201 if (match_end < match_start) { 3340 if (match_end < match_start) {
3202 ReplacementStringBuilder::AddSubjectSlice(builder, 3341 ReplacementStringBuilder::AddSubjectSlice(builder,
3203 match_end, 3342 match_end,
3204 match_start); 3343 match_start);
3205 } 3344 }
3206 match_end = register_vector[1]; 3345 match_end = register_vector[1];
3207 HandleScope loop_scope; 3346 HandleScope loop_scope(isolate);
3208 builder->Add(*Factory::NewSubString(subject, match_start, match_end)); 3347 builder->Add(*isolate->factory()->NewSubString(subject,
3348 match_start,
3349 match_end));
3209 if (match_start != match_end) { 3350 if (match_start != match_end) {
3210 pos = match_end; 3351 pos = match_end;
3211 } else { 3352 } else {
3212 pos = match_end + 1; 3353 pos = match_end + 1;
3213 if (pos > subject_length) break; 3354 if (pos > subject_length) break;
3214 } 3355 }
3215 } else if (result == RegExpImpl::RE_FAILURE) { 3356 } else if (result == RegExpImpl::RE_FAILURE) {
3216 break; 3357 break;
3217 } else { 3358 } else {
3218 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION); 3359 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION);
(...skipping 12 matching lines...) Expand all
3231 match_start, 3372 match_start,
3232 match_end); 3373 match_end);
3233 return RegExpImpl::RE_SUCCESS; 3374 return RegExpImpl::RE_SUCCESS;
3234 } else { 3375 } else {
3235 return RegExpImpl::RE_FAILURE; // No matches at all. 3376 return RegExpImpl::RE_FAILURE; // No matches at all.
3236 } 3377 }
3237 } 3378 }
3238 3379
3239 3380
3240 static RegExpImpl::IrregexpResult SearchRegExpMultiple( 3381 static RegExpImpl::IrregexpResult SearchRegExpMultiple(
3382 Isolate* isolate,
3241 Handle<String> subject, 3383 Handle<String> subject,
3242 Handle<JSRegExp> regexp, 3384 Handle<JSRegExp> regexp,
3243 Handle<JSArray> last_match_array, 3385 Handle<JSArray> last_match_array,
3244 FixedArrayBuilder* builder) { 3386 FixedArrayBuilder* builder) {
3245 3387
3246 ASSERT(subject->IsFlat()); 3388 ASSERT(subject->IsFlat());
3247 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); 3389 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject);
3248 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; 3390 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION;
3249 3391
3250 OffsetsVector registers(required_registers); 3392 OffsetsVector registers(required_registers);
(...skipping 23 matching lines...) Expand all
3274 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); 3416 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch);
3275 if (match_end < match_start) { 3417 if (match_end < match_start) {
3276 ReplacementStringBuilder::AddSubjectSlice(builder, 3418 ReplacementStringBuilder::AddSubjectSlice(builder,
3277 match_end, 3419 match_end,
3278 match_start); 3420 match_start);
3279 } 3421 }
3280 match_end = register_vector[1]; 3422 match_end = register_vector[1];
3281 3423
3282 { 3424 {
3283 // Avoid accumulating new handles inside loop. 3425 // Avoid accumulating new handles inside loop.
3284 HandleScope temp_scope; 3426 HandleScope temp_scope(isolate);
3285 // Arguments array to replace function is match, captures, index and 3427 // Arguments array to replace function is match, captures, index and
3286 // subject, i.e., 3 + capture count in total. 3428 // subject, i.e., 3 + capture count in total.
3287 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count); 3429 Handle<FixedArray> elements =
3288 Handle<String> match = Factory::NewSubString(subject, 3430 isolate->factory()->NewFixedArray(3 + capture_count);
3289 match_start, 3431 Handle<String> match = isolate->factory()->NewSubString(subject,
3290 match_end); 3432 match_start,
3433 match_end);
3291 elements->set(0, *match); 3434 elements->set(0, *match);
3292 for (int i = 1; i <= capture_count; i++) { 3435 for (int i = 1; i <= capture_count; i++) {
3293 int start = register_vector[i * 2]; 3436 int start = register_vector[i * 2];
3294 if (start >= 0) { 3437 if (start >= 0) {
3295 int end = register_vector[i * 2 + 1]; 3438 int end = register_vector[i * 2 + 1];
3296 ASSERT(start <= end); 3439 ASSERT(start <= end);
3297 Handle<String> substring = Factory::NewSubString(subject, 3440 Handle<String> substring = isolate->factory()->NewSubString(subject,
3298 start, 3441 start,
3299 end); 3442 end);
3300 elements->set(i, *substring); 3443 elements->set(i, *substring);
3301 } else { 3444 } else {
3302 ASSERT(register_vector[i * 2 + 1] < 0); 3445 ASSERT(register_vector[i * 2 + 1] < 0);
3303 elements->set(i, Heap::undefined_value()); 3446 elements->set(i, isolate->heap()->undefined_value());
3304 } 3447 }
3305 } 3448 }
3306 elements->set(capture_count + 1, Smi::FromInt(match_start)); 3449 elements->set(capture_count + 1, Smi::FromInt(match_start));
3307 elements->set(capture_count + 2, *subject); 3450 elements->set(capture_count + 2, *subject);
3308 builder->Add(*Factory::NewJSArrayWithElements(elements)); 3451 builder->Add(*isolate->factory()->NewJSArrayWithElements(elements));
3309 } 3452 }
3310 // Swap register vectors, so the last successful match is in 3453 // Swap register vectors, so the last successful match is in
3311 // prev_register_vector. 3454 // prev_register_vector.
3312 Vector<int32_t> tmp = prev_register_vector; 3455 Vector<int32_t> tmp = prev_register_vector;
3313 prev_register_vector = register_vector; 3456 prev_register_vector = register_vector;
3314 register_vector = tmp; 3457 register_vector = tmp;
3315 3458
3316 if (match_end > match_start) { 3459 if (match_end > match_start) {
3317 pos = match_end; 3460 pos = match_end;
3318 } else { 3461 } else {
(...skipping 30 matching lines...) Expand all
3349 RegExpImpl::SetCapture(elements, i, prev_register_vector[i]); 3492 RegExpImpl::SetCapture(elements, i, prev_register_vector[i]);
3350 } 3493 }
3351 return RegExpImpl::RE_SUCCESS; 3494 return RegExpImpl::RE_SUCCESS;
3352 } 3495 }
3353 } 3496 }
3354 // No matches at all, return failure or exception result directly. 3497 // No matches at all, return failure or exception result directly.
3355 return result; 3498 return result;
3356 } 3499 }
3357 3500
3358 3501
3359 static MaybeObject* Runtime_RegExpExecMultiple(Arguments args) { 3502 static MaybeObject* Runtime_RegExpExecMultiple(RUNTIME_CALLING_CONVENTION) {
3503 RUNTIME_GET_ISOLATE;
3360 ASSERT(args.length() == 4); 3504 ASSERT(args.length() == 4);
3361 HandleScope handles; 3505 HandleScope handles(isolate);
3362 3506
3363 CONVERT_ARG_CHECKED(String, subject, 1); 3507 CONVERT_ARG_CHECKED(String, subject, 1);
3364 if (!subject->IsFlat()) { FlattenString(subject); } 3508 if (!subject->IsFlat()) { FlattenString(subject); }
3365 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); 3509 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
3366 CONVERT_ARG_CHECKED(JSArray, last_match_info, 2); 3510 CONVERT_ARG_CHECKED(JSArray, last_match_info, 2);
3367 CONVERT_ARG_CHECKED(JSArray, result_array, 3); 3511 CONVERT_ARG_CHECKED(JSArray, result_array, 3);
3368 3512
3369 ASSERT(last_match_info->HasFastElements()); 3513 ASSERT(last_match_info->HasFastElements());
3370 ASSERT(regexp->GetFlags().is_global()); 3514 ASSERT(regexp->GetFlags().is_global());
3371 Handle<FixedArray> result_elements; 3515 Handle<FixedArray> result_elements;
3372 if (result_array->HasFastElements()) { 3516 if (result_array->HasFastElements()) {
3373 result_elements = 3517 result_elements =
3374 Handle<FixedArray>(FixedArray::cast(result_array->elements())); 3518 Handle<FixedArray>(FixedArray::cast(result_array->elements()));
3375 } else { 3519 } else {
3376 result_elements = Factory::NewFixedArrayWithHoles(16); 3520 result_elements = isolate->factory()->NewFixedArrayWithHoles(16);
3377 } 3521 }
3378 FixedArrayBuilder builder(result_elements); 3522 FixedArrayBuilder builder(result_elements);
3379 3523
3380 if (regexp->TypeTag() == JSRegExp::ATOM) { 3524 if (regexp->TypeTag() == JSRegExp::ATOM) {
3381 Handle<String> pattern( 3525 Handle<String> pattern(
3382 String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex))); 3526 String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex)));
3383 ASSERT(pattern->IsFlat()); 3527 ASSERT(pattern->IsFlat());
3384 if (SearchStringMultiple(subject, pattern, last_match_info, &builder)) { 3528 if (SearchStringMultiple(isolate, subject, pattern,
3529 last_match_info, &builder)) {
3385 return *builder.ToJSArray(result_array); 3530 return *builder.ToJSArray(result_array);
3386 } 3531 }
3387 return Heap::null_value(); 3532 return isolate->heap()->null_value();
3388 } 3533 }
3389 3534
3390 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); 3535 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP);
3391 3536
3392 RegExpImpl::IrregexpResult result; 3537 RegExpImpl::IrregexpResult result;
3393 if (regexp->CaptureCount() == 0) { 3538 if (regexp->CaptureCount() == 0) {
3394 result = SearchRegExpNoCaptureMultiple(subject, 3539 result = SearchRegExpNoCaptureMultiple(isolate,
3540 subject,
3395 regexp, 3541 regexp,
3396 last_match_info, 3542 last_match_info,
3397 &builder); 3543 &builder);
3398 } else { 3544 } else {
3399 result = SearchRegExpMultiple(subject, regexp, last_match_info, &builder); 3545 result = SearchRegExpMultiple(isolate,
3546 subject,
3547 regexp,
3548 last_match_info,
3549 &builder);
3400 } 3550 }
3401 if (result == RegExpImpl::RE_SUCCESS) return *builder.ToJSArray(result_array); 3551 if (result == RegExpImpl::RE_SUCCESS) return *builder.ToJSArray(result_array);
3402 if (result == RegExpImpl::RE_FAILURE) return Heap::null_value(); 3552 if (result == RegExpImpl::RE_FAILURE) return isolate->heap()->null_value();
3403 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION); 3553 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION);
3404 return Failure::Exception(); 3554 return Failure::Exception();
3405 } 3555 }
3406 3556
3407 3557
3408 static MaybeObject* Runtime_NumberToRadixString(Arguments args) { 3558 static MaybeObject* Runtime_NumberToRadixString(RUNTIME_CALLING_CONVENTION) {
3559 RUNTIME_GET_ISOLATE;
3409 NoHandleAllocation ha; 3560 NoHandleAllocation ha;
3410 ASSERT(args.length() == 2); 3561 ASSERT(args.length() == 2);
3411 3562
3412 // Fast case where the result is a one character string. 3563 // Fast case where the result is a one character string.
3413 if (args[0]->IsSmi() && args[1]->IsSmi()) { 3564 if (args[0]->IsSmi() && args[1]->IsSmi()) {
3414 int value = Smi::cast(args[0])->value(); 3565 int value = Smi::cast(args[0])->value();
3415 int radix = Smi::cast(args[1])->value(); 3566 int radix = Smi::cast(args[1])->value();
3416 if (value >= 0 && value < radix) { 3567 if (value >= 0 && value < radix) {
3417 RUNTIME_ASSERT(radix <= 36); 3568 RUNTIME_ASSERT(radix <= 36);
3418 // Character array used for conversion. 3569 // Character array used for conversion.
3419 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 3570 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
3420 return Heap::LookupSingleCharacterStringFromCode(kCharTable[value]); 3571 return isolate->heap()->
3572 LookupSingleCharacterStringFromCode(kCharTable[value]);
3421 } 3573 }
3422 } 3574 }
3423 3575
3424 // Slow case. 3576 // Slow case.
3425 CONVERT_DOUBLE_CHECKED(value, args[0]); 3577 CONVERT_DOUBLE_CHECKED(value, args[0]);
3426 if (isnan(value)) { 3578 if (isnan(value)) {
3427 return Heap::AllocateStringFromAscii(CStrVector("NaN")); 3579 return isolate->heap()->AllocateStringFromAscii(CStrVector("NaN"));
3428 } 3580 }
3429 if (isinf(value)) { 3581 if (isinf(value)) {
3430 if (value < 0) { 3582 if (value < 0) {
3431 return Heap::AllocateStringFromAscii(CStrVector("-Infinity")); 3583 return isolate->heap()->AllocateStringFromAscii(CStrVector("-Infinity"));
3432 } 3584 }
3433 return Heap::AllocateStringFromAscii(CStrVector("Infinity")); 3585 return isolate->heap()->AllocateStringFromAscii(CStrVector("Infinity"));
3434 } 3586 }
3435 CONVERT_DOUBLE_CHECKED(radix_number, args[1]); 3587 CONVERT_DOUBLE_CHECKED(radix_number, args[1]);
3436 int radix = FastD2I(radix_number); 3588 int radix = FastD2I(radix_number);
3437 RUNTIME_ASSERT(2 <= radix && radix <= 36); 3589 RUNTIME_ASSERT(2 <= radix && radix <= 36);
3438 char* str = DoubleToRadixCString(value, radix); 3590 char* str = DoubleToRadixCString(value, radix);
3439 MaybeObject* result = Heap::AllocateStringFromAscii(CStrVector(str)); 3591 MaybeObject* result =
3592 isolate->heap()->AllocateStringFromAscii(CStrVector(str));
3440 DeleteArray(str); 3593 DeleteArray(str);
3441 return result; 3594 return result;
3442 } 3595 }
3443 3596
3444 3597
3445 static MaybeObject* Runtime_NumberToFixed(Arguments args) { 3598 static MaybeObject* Runtime_NumberToFixed(RUNTIME_CALLING_CONVENTION) {
3599 RUNTIME_GET_ISOLATE;
3446 NoHandleAllocation ha; 3600 NoHandleAllocation ha;
3447 ASSERT(args.length() == 2); 3601 ASSERT(args.length() == 2);
3448 3602
3449 CONVERT_DOUBLE_CHECKED(value, args[0]); 3603 CONVERT_DOUBLE_CHECKED(value, args[0]);
3450 if (isnan(value)) { 3604 if (isnan(value)) {
3451 return Heap::AllocateStringFromAscii(CStrVector("NaN")); 3605 return isolate->heap()->AllocateStringFromAscii(CStrVector("NaN"));
3452 } 3606 }
3453 if (isinf(value)) { 3607 if (isinf(value)) {
3454 if (value < 0) { 3608 if (value < 0) {
3455 return Heap::AllocateStringFromAscii(CStrVector("-Infinity")); 3609 return isolate->heap()->AllocateStringFromAscii(CStrVector("-Infinity"));
3456 } 3610 }
3457 return Heap::AllocateStringFromAscii(CStrVector("Infinity")); 3611 return isolate->heap()->AllocateStringFromAscii(CStrVector("Infinity"));
3458 } 3612 }
3459 CONVERT_DOUBLE_CHECKED(f_number, args[1]); 3613 CONVERT_DOUBLE_CHECKED(f_number, args[1]);
3460 int f = FastD2I(f_number); 3614 int f = FastD2I(f_number);
3461 RUNTIME_ASSERT(f >= 0); 3615 RUNTIME_ASSERT(f >= 0);
3462 char* str = DoubleToFixedCString(value, f); 3616 char* str = DoubleToFixedCString(value, f);
3463 MaybeObject* result = Heap::AllocateStringFromAscii(CStrVector(str)); 3617 MaybeObject* res =
3618 isolate->heap()->AllocateStringFromAscii(CStrVector(str));
3464 DeleteArray(str); 3619 DeleteArray(str);
3465 return result; 3620 return res;
3466 } 3621 }
3467 3622
3468 3623
3469 static MaybeObject* Runtime_NumberToExponential(Arguments args) { 3624 static MaybeObject* Runtime_NumberToExponential(RUNTIME_CALLING_CONVENTION) {
3625 RUNTIME_GET_ISOLATE;
3470 NoHandleAllocation ha; 3626 NoHandleAllocation ha;
3471 ASSERT(args.length() == 2); 3627 ASSERT(args.length() == 2);
3472 3628
3473 CONVERT_DOUBLE_CHECKED(value, args[0]); 3629 CONVERT_DOUBLE_CHECKED(value, args[0]);
3474 if (isnan(value)) { 3630 if (isnan(value)) {
3475 return Heap::AllocateStringFromAscii(CStrVector("NaN")); 3631 return isolate->heap()->AllocateStringFromAscii(CStrVector("NaN"));
3476 } 3632 }
3477 if (isinf(value)) { 3633 if (isinf(value)) {
3478 if (value < 0) { 3634 if (value < 0) {
3479 return Heap::AllocateStringFromAscii(CStrVector("-Infinity")); 3635 return isolate->heap()->AllocateStringFromAscii(CStrVector("-Infinity"));
3480 } 3636 }
3481 return Heap::AllocateStringFromAscii(CStrVector("Infinity")); 3637 return isolate->heap()->AllocateStringFromAscii(CStrVector("Infinity"));
3482 } 3638 }
3483 CONVERT_DOUBLE_CHECKED(f_number, args[1]); 3639 CONVERT_DOUBLE_CHECKED(f_number, args[1]);
3484 int f = FastD2I(f_number); 3640 int f = FastD2I(f_number);
3485 RUNTIME_ASSERT(f >= -1 && f <= 20); 3641 RUNTIME_ASSERT(f >= -1 && f <= 20);
3486 char* str = DoubleToExponentialCString(value, f); 3642 char* str = DoubleToExponentialCString(value, f);
3487 MaybeObject* result = Heap::AllocateStringFromAscii(CStrVector(str)); 3643 MaybeObject* res =
3644 isolate->heap()->AllocateStringFromAscii(CStrVector(str));
3488 DeleteArray(str); 3645 DeleteArray(str);
3489 return result; 3646 return res;
3490 } 3647 }
3491 3648
3492 3649
3493 static MaybeObject* Runtime_NumberToPrecision(Arguments args) { 3650 static MaybeObject* Runtime_NumberToPrecision(RUNTIME_CALLING_CONVENTION) {
3651 RUNTIME_GET_ISOLATE;
3494 NoHandleAllocation ha; 3652 NoHandleAllocation ha;
3495 ASSERT(args.length() == 2); 3653 ASSERT(args.length() == 2);
3496 3654
3497 CONVERT_DOUBLE_CHECKED(value, args[0]); 3655 CONVERT_DOUBLE_CHECKED(value, args[0]);
3498 if (isnan(value)) { 3656 if (isnan(value)) {
3499 return Heap::AllocateStringFromAscii(CStrVector("NaN")); 3657 return isolate->heap()->AllocateStringFromAscii(CStrVector("NaN"));
3500 } 3658 }
3501 if (isinf(value)) { 3659 if (isinf(value)) {
3502 if (value < 0) { 3660 if (value < 0) {
3503 return Heap::AllocateStringFromAscii(CStrVector("-Infinity")); 3661 return isolate->heap()->AllocateStringFromAscii(CStrVector("-Infinity"));
3504 } 3662 }
3505 return Heap::AllocateStringFromAscii(CStrVector("Infinity")); 3663 return isolate->heap()->AllocateStringFromAscii(CStrVector("Infinity"));
3506 } 3664 }
3507 CONVERT_DOUBLE_CHECKED(f_number, args[1]); 3665 CONVERT_DOUBLE_CHECKED(f_number, args[1]);
3508 int f = FastD2I(f_number); 3666 int f = FastD2I(f_number);
3509 RUNTIME_ASSERT(f >= 1 && f <= 21); 3667 RUNTIME_ASSERT(f >= 1 && f <= 21);
3510 char* str = DoubleToPrecisionCString(value, f); 3668 char* str = DoubleToPrecisionCString(value, f);
3511 MaybeObject* result = Heap::AllocateStringFromAscii(CStrVector(str)); 3669 MaybeObject* res =
3670 isolate->heap()->AllocateStringFromAscii(CStrVector(str));
3512 DeleteArray(str); 3671 DeleteArray(str);
3513 return result; 3672 return res;
3514 } 3673 }
3515 3674
3516 3675
3517 // Returns a single character string where first character equals 3676 // Returns a single character string where first character equals
3518 // string->Get(index). 3677 // string->Get(index).
3519 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { 3678 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
3520 if (index < static_cast<uint32_t>(string->length())) { 3679 if (index < static_cast<uint32_t>(string->length())) {
3521 string->TryFlatten(); 3680 string->TryFlatten();
3522 return LookupSingleCharacterStringFromCode( 3681 return LookupSingleCharacterStringFromCode(
3523 string->Get(index)); 3682 string->Get(index));
3524 } 3683 }
3525 return Execution::CharAt(string, index); 3684 return Execution::CharAt(string, index);
3526 } 3685 }
3527 3686
3528 3687
3529 MaybeObject* Runtime::GetElementOrCharAt(Handle<Object> object, 3688 MaybeObject* Runtime::GetElementOrCharAt(Isolate* isolate,
3689 Handle<Object> object,
3530 uint32_t index) { 3690 uint32_t index) {
3531 // Handle [] indexing on Strings 3691 // Handle [] indexing on Strings
3532 if (object->IsString()) { 3692 if (object->IsString()) {
3533 Handle<Object> result = GetCharAt(Handle<String>::cast(object), index); 3693 Handle<Object> result = GetCharAt(Handle<String>::cast(object), index);
3534 if (!result->IsUndefined()) return *result; 3694 if (!result->IsUndefined()) return *result;
3535 } 3695 }
3536 3696
3537 // Handle [] indexing on String objects 3697 // Handle [] indexing on String objects
3538 if (object->IsStringObjectWithCharacterAt(index)) { 3698 if (object->IsStringObjectWithCharacterAt(index)) {
3539 Handle<JSValue> js_value = Handle<JSValue>::cast(object); 3699 Handle<JSValue> js_value = Handle<JSValue>::cast(object);
3540 Handle<Object> result = 3700 Handle<Object> result =
3541 GetCharAt(Handle<String>(String::cast(js_value->value())), index); 3701 GetCharAt(Handle<String>(String::cast(js_value->value())), index);
3542 if (!result->IsUndefined()) return *result; 3702 if (!result->IsUndefined()) return *result;
3543 } 3703 }
3544 3704
3545 if (object->IsString() || object->IsNumber() || object->IsBoolean()) { 3705 if (object->IsString() || object->IsNumber() || object->IsBoolean()) {
3546 Handle<Object> prototype = GetPrototype(object); 3706 Handle<Object> prototype = GetPrototype(object);
3547 return prototype->GetElement(index); 3707 return prototype->GetElement(index);
3548 } 3708 }
3549 3709
3550 return GetElement(object, index); 3710 return GetElement(object, index);
3551 } 3711 }
3552 3712
3553 3713
3554 MaybeObject* Runtime::GetElement(Handle<Object> object, uint32_t index) { 3714 MaybeObject* Runtime::GetElement(Handle<Object> object, uint32_t index) {
3555 return object->GetElement(index); 3715 return object->GetElement(index);
3556 } 3716 }
3557 3717
3558 3718
3559 MaybeObject* Runtime::GetObjectProperty(Handle<Object> object, 3719 MaybeObject* Runtime::GetObjectProperty(Isolate* isolate,
3720 Handle<Object> object,
3560 Handle<Object> key) { 3721 Handle<Object> key) {
3561 HandleScope scope; 3722 HandleScope scope(isolate);
3562 3723
3563 if (object->IsUndefined() || object->IsNull()) { 3724 if (object->IsUndefined() || object->IsNull()) {
3564 Handle<Object> args[2] = { key, object }; 3725 Handle<Object> args[2] = { key, object };
3565 Handle<Object> error = 3726 Handle<Object> error =
3566 Factory::NewTypeError("non_object_property_load", 3727 isolate->factory()->NewTypeError("non_object_property_load",
3567 HandleVector(args, 2)); 3728 HandleVector(args, 2));
3568 return Top::Throw(*error); 3729 return isolate->Throw(*error);
3569 } 3730 }
3570 3731
3571 // Check if the given key is an array index. 3732 // Check if the given key is an array index.
3572 uint32_t index; 3733 uint32_t index;
3573 if (key->ToArrayIndex(&index)) { 3734 if (key->ToArrayIndex(&index)) {
3574 return GetElementOrCharAt(object, index); 3735 return GetElementOrCharAt(isolate, object, index);
3575 } 3736 }
3576 3737
3577 // Convert the key to a string - possibly by calling back into JavaScript. 3738 // Convert the key to a string - possibly by calling back into JavaScript.
3578 Handle<String> name; 3739 Handle<String> name;
3579 if (key->IsString()) { 3740 if (key->IsString()) {
3580 name = Handle<String>::cast(key); 3741 name = Handle<String>::cast(key);
3581 } else { 3742 } else {
3582 bool has_pending_exception = false; 3743 bool has_pending_exception = false;
3583 Handle<Object> converted = 3744 Handle<Object> converted =
3584 Execution::ToString(key, &has_pending_exception); 3745 Execution::ToString(key, &has_pending_exception);
3585 if (has_pending_exception) return Failure::Exception(); 3746 if (has_pending_exception) return Failure::Exception();
3586 name = Handle<String>::cast(converted); 3747 name = Handle<String>::cast(converted);
3587 } 3748 }
3588 3749
3589 // Check if the name is trivially convertible to an index and get 3750 // Check if the name is trivially convertible to an index and get
3590 // the element if so. 3751 // the element if so.
3591 if (name->AsArrayIndex(&index)) { 3752 if (name->AsArrayIndex(&index)) {
3592 return GetElementOrCharAt(object, index); 3753 return GetElementOrCharAt(isolate, object, index);
3593 } else { 3754 } else {
3594 PropertyAttributes attr; 3755 PropertyAttributes attr;
3595 return object->GetProperty(*name, &attr); 3756 return object->GetProperty(*name, &attr);
3596 } 3757 }
3597 } 3758 }
3598 3759
3599 3760
3600 static MaybeObject* Runtime_GetProperty(Arguments args) { 3761 static MaybeObject* Runtime_GetProperty(RUNTIME_CALLING_CONVENTION) {
3762 RUNTIME_GET_ISOLATE;
3601 NoHandleAllocation ha; 3763 NoHandleAllocation ha;
3602 ASSERT(args.length() == 2); 3764 ASSERT(args.length() == 2);
3603 3765
3604 Handle<Object> object = args.at<Object>(0); 3766 Handle<Object> object = args.at<Object>(0);
3605 Handle<Object> key = args.at<Object>(1); 3767 Handle<Object> key = args.at<Object>(1);
3606 3768
3607 return Runtime::GetObjectProperty(object, key); 3769 return Runtime::GetObjectProperty(isolate, object, key);
3608 } 3770 }
3609 3771
3610 3772
3611 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric. 3773 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric.
3612 static MaybeObject* Runtime_KeyedGetProperty(Arguments args) { 3774 static MaybeObject* Runtime_KeyedGetProperty(RUNTIME_CALLING_CONVENTION) {
3775 RUNTIME_GET_ISOLATE;
3613 NoHandleAllocation ha; 3776 NoHandleAllocation ha;
3614 ASSERT(args.length() == 2); 3777 ASSERT(args.length() == 2);
3615 3778
3616 // Fast cases for getting named properties of the receiver JSObject 3779 // Fast cases for getting named properties of the receiver JSObject
3617 // itself. 3780 // itself.
3618 // 3781 //
3619 // The global proxy objects has to be excluded since LocalLookup on 3782 // The global proxy objects has to be excluded since LocalLookup on
3620 // the global proxy object can return a valid result even though the 3783 // the global proxy object can return a valid result even though the
3621 // global proxy object never has properties. This is the case 3784 // global proxy object never has properties. This is the case
3622 // because the global proxy object forwards everything to its hidden 3785 // because the global proxy object forwards everything to its hidden
3623 // prototype including local lookups. 3786 // prototype including local lookups.
3624 // 3787 //
3625 // Additionally, we need to make sure that we do not cache results 3788 // Additionally, we need to make sure that we do not cache results
3626 // for objects that require access checks. 3789 // for objects that require access checks.
3627 if (args[0]->IsJSObject() && 3790 if (args[0]->IsJSObject() &&
3628 !args[0]->IsJSGlobalProxy() && 3791 !args[0]->IsJSGlobalProxy() &&
3629 !args[0]->IsAccessCheckNeeded() && 3792 !args[0]->IsAccessCheckNeeded() &&
3630 args[1]->IsString()) { 3793 args[1]->IsString()) {
3631 JSObject* receiver = JSObject::cast(args[0]); 3794 JSObject* receiver = JSObject::cast(args[0]);
3632 String* key = String::cast(args[1]); 3795 String* key = String::cast(args[1]);
3633 if (receiver->HasFastProperties()) { 3796 if (receiver->HasFastProperties()) {
3634 // Attempt to use lookup cache. 3797 // Attempt to use lookup cache.
3635 Map* receiver_map = receiver->map(); 3798 Map* receiver_map = receiver->map();
3636 int offset = KeyedLookupCache::Lookup(receiver_map, key); 3799 KeyedLookupCache* keyed_lookup_cache = isolate->keyed_lookup_cache();
3800 int offset = keyed_lookup_cache->Lookup(receiver_map, key);
3637 if (offset != -1) { 3801 if (offset != -1) {
3638 Object* value = receiver->FastPropertyAt(offset); 3802 Object* value = receiver->FastPropertyAt(offset);
3639 return value->IsTheHole() ? Heap::undefined_value() : value; 3803 return value->IsTheHole() ? isolate->heap()->undefined_value() : value;
3640 } 3804 }
3641 // Lookup cache miss. Perform lookup and update the cache if appropriate. 3805 // Lookup cache miss. Perform lookup and update the cache if appropriate.
3642 LookupResult result; 3806 LookupResult result;
3643 receiver->LocalLookup(key, &result); 3807 receiver->LocalLookup(key, &result);
3644 if (result.IsProperty() && result.type() == FIELD) { 3808 if (result.IsProperty() && result.type() == FIELD) {
3645 int offset = result.GetFieldIndex(); 3809 int offset = result.GetFieldIndex();
3646 KeyedLookupCache::Update(receiver_map, key, offset); 3810 keyed_lookup_cache->Update(receiver_map, key, offset);
3647 return receiver->FastPropertyAt(offset); 3811 return receiver->FastPropertyAt(offset);
3648 } 3812 }
3649 } else { 3813 } else {
3650 // Attempt dictionary lookup. 3814 // Attempt dictionary lookup.
3651 StringDictionary* dictionary = receiver->property_dictionary(); 3815 StringDictionary* dictionary = receiver->property_dictionary();
3652 int entry = dictionary->FindEntry(key); 3816 int entry = dictionary->FindEntry(key);
3653 if ((entry != StringDictionary::kNotFound) && 3817 if ((entry != StringDictionary::kNotFound) &&
3654 (dictionary->DetailsAt(entry).type() == NORMAL)) { 3818 (dictionary->DetailsAt(entry).type() == NORMAL)) {
3655 Object* value = dictionary->ValueAt(entry); 3819 Object* value = dictionary->ValueAt(entry);
3656 if (!receiver->IsGlobalObject()) return value; 3820 if (!receiver->IsGlobalObject()) return value;
3657 value = JSGlobalPropertyCell::cast(value)->value(); 3821 value = JSGlobalPropertyCell::cast(value)->value();
3658 if (!value->IsTheHole()) return value; 3822 if (!value->IsTheHole()) return value;
3659 // If value is the hole do the general lookup. 3823 // If value is the hole do the general lookup.
3660 } 3824 }
3661 } 3825 }
3662 } else if (args[0]->IsString() && args[1]->IsSmi()) { 3826 } else if (args[0]->IsString() && args[1]->IsSmi()) {
3663 // Fast case for string indexing using [] with a smi index. 3827 // Fast case for string indexing using [] with a smi index.
3664 HandleScope scope; 3828 HandleScope scope(isolate);
3665 Handle<String> str = args.at<String>(0); 3829 Handle<String> str = args.at<String>(0);
3666 int index = Smi::cast(args[1])->value(); 3830 int index = Smi::cast(args[1])->value();
3667 if (index >= 0 && index < str->length()) { 3831 if (index >= 0 && index < str->length()) {
3668 Handle<Object> result = GetCharAt(str, index); 3832 Handle<Object> result = GetCharAt(str, index);
3669 return *result; 3833 return *result;
3670 } 3834 }
3671 } 3835 }
3672 3836
3673 // Fall back to GetObjectProperty. 3837 // Fall back to GetObjectProperty.
3674 return Runtime::GetObjectProperty(args.at<Object>(0), 3838 return Runtime::GetObjectProperty(isolate,
3839 args.at<Object>(0),
3675 args.at<Object>(1)); 3840 args.at<Object>(1));
3676 } 3841 }
3677 3842
3678 // Implements part of 8.12.9 DefineOwnProperty. 3843 // Implements part of 8.12.9 DefineOwnProperty.
3679 // There are 3 cases that lead here: 3844 // There are 3 cases that lead here:
3680 // Step 4b - define a new accessor property. 3845 // Step 4b - define a new accessor property.
3681 // Steps 9c & 12 - replace an existing data property with an accessor property. 3846 // Steps 9c & 12 - replace an existing data property with an accessor property.
3682 // Step 12 - update an existing accessor property with an accessor or generic 3847 // Step 12 - update an existing accessor property with an accessor or generic
3683 // descriptor. 3848 // descriptor.
3684 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) { 3849 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(
3850 RUNTIME_CALLING_CONVENTION) {
3851 RUNTIME_GET_ISOLATE;
3685 ASSERT(args.length() == 5); 3852 ASSERT(args.length() == 5);
3686 HandleScope scope; 3853 HandleScope scope(isolate);
3687 CONVERT_ARG_CHECKED(JSObject, obj, 0); 3854 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3688 CONVERT_CHECKED(String, name, args[1]); 3855 CONVERT_CHECKED(String, name, args[1]);
3689 CONVERT_CHECKED(Smi, flag_setter, args[2]); 3856 CONVERT_CHECKED(Smi, flag_setter, args[2]);
3690 Object* fun = args[3]; 3857 Object* fun = args[3];
3691 RUNTIME_ASSERT(fun->IsJSFunction() || fun->IsUndefined()); 3858 RUNTIME_ASSERT(fun->IsJSFunction() || fun->IsUndefined());
3692 CONVERT_CHECKED(Smi, flag_attr, args[4]); 3859 CONVERT_CHECKED(Smi, flag_attr, args[4]);
3693 int unchecked = flag_attr->value(); 3860 int unchecked = flag_attr->value();
3694 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3861 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3695 RUNTIME_ASSERT(!obj->IsNull()); 3862 RUNTIME_ASSERT(!obj->IsNull());
3696 LookupResult result; 3863 LookupResult result;
(...skipping 14 matching lines...) Expand all
3711 } 3878 }
3712 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); 3879 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr);
3713 } 3880 }
3714 3881
3715 // Implements part of 8.12.9 DefineOwnProperty. 3882 // Implements part of 8.12.9 DefineOwnProperty.
3716 // There are 3 cases that lead here: 3883 // There are 3 cases that lead here:
3717 // Step 4a - define a new data property. 3884 // Step 4a - define a new data property.
3718 // Steps 9b & 12 - replace an existing accessor property with a data property. 3885 // Steps 9b & 12 - replace an existing accessor property with a data property.
3719 // Step 12 - update an existing data property with a data or generic 3886 // Step 12 - update an existing data property with a data or generic
3720 // descriptor. 3887 // descriptor.
3721 static MaybeObject* Runtime_DefineOrRedefineDataProperty(Arguments args) { 3888 static MaybeObject* Runtime_DefineOrRedefineDataProperty(
3889 RUNTIME_CALLING_CONVENTION) {
3890 RUNTIME_GET_ISOLATE;
3722 ASSERT(args.length() == 4); 3891 ASSERT(args.length() == 4);
3723 HandleScope scope; 3892 HandleScope scope(isolate);
3724 CONVERT_ARG_CHECKED(JSObject, js_object, 0); 3893 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
3725 CONVERT_ARG_CHECKED(String, name, 1); 3894 CONVERT_ARG_CHECKED(String, name, 1);
3726 Handle<Object> obj_value = args.at<Object>(2); 3895 Handle<Object> obj_value = args.at<Object>(2);
3727 3896
3728 CONVERT_CHECKED(Smi, flag, args[3]); 3897 CONVERT_CHECKED(Smi, flag, args[3]);
3729 int unchecked = flag->value(); 3898 int unchecked = flag->value();
3730 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3899 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3731 3900
3732 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3901 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3733 3902
(...skipping 26 matching lines...) Expand all
3760 } 3929 }
3761 3930
3762 LookupResult result; 3931 LookupResult result;
3763 js_object->LookupRealNamedProperty(*name, &result); 3932 js_object->LookupRealNamedProperty(*name, &result);
3764 3933
3765 // To be compatible with safari we do not change the value on API objects 3934 // To be compatible with safari we do not change the value on API objects
3766 // in defineProperty. Firefox disagrees here, and actually changes the value. 3935 // in defineProperty. Firefox disagrees here, and actually changes the value.
3767 if (result.IsProperty() && 3936 if (result.IsProperty() &&
3768 (result.type() == CALLBACKS) && 3937 (result.type() == CALLBACKS) &&
3769 result.GetCallbackObject()->IsAccessorInfo()) { 3938 result.GetCallbackObject()->IsAccessorInfo()) {
3770 return Heap::undefined_value(); 3939 return isolate->heap()->undefined_value();
3771 } 3940 }
3772 3941
3773 // Take special care when attributes are different and there is already 3942 // Take special care when attributes are different and there is already
3774 // a property. For simplicity we normalize the property which enables us 3943 // a property. For simplicity we normalize the property which enables us
3775 // to not worry about changing the instance_descriptor and creating a new 3944 // to not worry about changing the instance_descriptor and creating a new
3776 // map. The current version of SetObjectProperty does not handle attributes 3945 // map. The current version of SetObjectProperty does not handle attributes
3777 // correctly in the case where a property is a field and is reset with 3946 // correctly in the case where a property is a field and is reset with
3778 // new attributes. 3947 // new attributes.
3779 if (result.IsProperty() && 3948 if (result.IsProperty() &&
3780 (attr != result.GetAttributes() || result.type() == CALLBACKS)) { 3949 (attr != result.GetAttributes() || result.type() == CALLBACKS)) {
3781 // New attributes - normalize to avoid writing to instance descriptor 3950 // New attributes - normalize to avoid writing to instance descriptor
3782 if (js_object->IsJSGlobalProxy()) { 3951 if (js_object->IsJSGlobalProxy()) {
3783 // Since the result is a property, the prototype will exist so 3952 // Since the result is a property, the prototype will exist so
3784 // we don't have to check for null. 3953 // we don't have to check for null.
3785 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); 3954 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype()));
3786 } 3955 }
3787 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); 3956 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0);
3788 // Use IgnoreAttributes version since a readonly property may be 3957 // Use IgnoreAttributes version since a readonly property may be
3789 // overridden and SetProperty does not allow this. 3958 // overridden and SetProperty does not allow this.
3790 return js_object->SetLocalPropertyIgnoreAttributes(*name, 3959 return js_object->SetLocalPropertyIgnoreAttributes(*name,
3791 *obj_value, 3960 *obj_value,
3792 attr); 3961 attr);
3793 } 3962 }
3794 3963
3795 return Runtime::ForceSetObjectProperty(js_object, name, obj_value, attr); 3964 return Runtime::ForceSetObjectProperty(isolate,
3965 js_object,
3966 name,
3967 obj_value,
3968 attr);
3796 } 3969 }
3797 3970
3798 3971
3799 MaybeObject* Runtime::SetObjectProperty(Handle<Object> object, 3972 MaybeObject* Runtime::SetObjectProperty(Isolate* isolate,
3973 Handle<Object> object,
3800 Handle<Object> key, 3974 Handle<Object> key,
3801 Handle<Object> value, 3975 Handle<Object> value,
3802 PropertyAttributes attr, 3976 PropertyAttributes attr,
3803 StrictModeFlag strict_mode) { 3977 StrictModeFlag strict_mode) {
3804 HandleScope scope; 3978 HandleScope scope(isolate);
3805 3979
3806 if (object->IsUndefined() || object->IsNull()) { 3980 if (object->IsUndefined() || object->IsNull()) {
3807 Handle<Object> args[2] = { key, object }; 3981 Handle<Object> args[2] = { key, object };
3808 Handle<Object> error = 3982 Handle<Object> error =
3809 Factory::NewTypeError("non_object_property_store", 3983 isolate->factory()->NewTypeError("non_object_property_store",
3810 HandleVector(args, 2)); 3984 HandleVector(args, 2));
3811 return Top::Throw(*error); 3985 return isolate->Throw(*error);
3812 } 3986 }
3813 3987
3814 // If the object isn't a JavaScript object, we ignore the store. 3988 // If the object isn't a JavaScript object, we ignore the store.
3815 if (!object->IsJSObject()) return *value; 3989 if (!object->IsJSObject()) return *value;
3816 3990
3817 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 3991 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
3818 3992
3819 // Check if the given key is an array index. 3993 // Check if the given key is an array index.
3820 uint32_t index; 3994 uint32_t index;
3821 if (key->ToArrayIndex(&index)) { 3995 if (key->ToArrayIndex(&index)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3855 Handle<String> name = Handle<String>::cast(converted); 4029 Handle<String> name = Handle<String>::cast(converted);
3856 4030
3857 if (name->AsArrayIndex(&index)) { 4031 if (name->AsArrayIndex(&index)) {
3858 return js_object->SetElement(index, *value, strict_mode); 4032 return js_object->SetElement(index, *value, strict_mode);
3859 } else { 4033 } else {
3860 return js_object->SetProperty(*name, *value, attr, strict_mode); 4034 return js_object->SetProperty(*name, *value, attr, strict_mode);
3861 } 4035 }
3862 } 4036 }
3863 4037
3864 4038
3865 MaybeObject* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, 4039 MaybeObject* Runtime::ForceSetObjectProperty(Isolate* isolate,
4040 Handle<JSObject> js_object,
3866 Handle<Object> key, 4041 Handle<Object> key,
3867 Handle<Object> value, 4042 Handle<Object> value,
3868 PropertyAttributes attr) { 4043 PropertyAttributes attr) {
3869 HandleScope scope; 4044 HandleScope scope(isolate);
3870 4045
3871 // Check if the given key is an array index. 4046 // Check if the given key is an array index.
3872 uint32_t index; 4047 uint32_t index;
3873 if (key->ToArrayIndex(&index)) { 4048 if (key->ToArrayIndex(&index)) {
3874 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters 4049 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
3875 // of a string using [] notation. We need to support this too in 4050 // of a string using [] notation. We need to support this too in
3876 // JavaScript. 4051 // JavaScript.
3877 // In the case of a String object we just need to redirect the assignment to 4052 // In the case of a String object we just need to redirect the assignment to
3878 // the underlying string if the index is in range. Since the underlying 4053 // the underlying string if the index is in range. Since the underlying
3879 // string does nothing with the assignment then we can ignore such 4054 // string does nothing with the assignment then we can ignore such
(...skipping 24 matching lines...) Expand all
3904 Handle<String> name = Handle<String>::cast(converted); 4079 Handle<String> name = Handle<String>::cast(converted);
3905 4080
3906 if (name->AsArrayIndex(&index)) { 4081 if (name->AsArrayIndex(&index)) {
3907 return js_object->SetElement(index, *value, kNonStrictMode); 4082 return js_object->SetElement(index, *value, kNonStrictMode);
3908 } else { 4083 } else {
3909 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr); 4084 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr);
3910 } 4085 }
3911 } 4086 }
3912 4087
3913 4088
3914 MaybeObject* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object, 4089 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate,
4090 Handle<JSObject> js_object,
3915 Handle<Object> key) { 4091 Handle<Object> key) {
3916 HandleScope scope; 4092 HandleScope scope(isolate);
3917 4093
3918 // Check if the given key is an array index. 4094 // Check if the given key is an array index.
3919 uint32_t index; 4095 uint32_t index;
3920 if (key->ToArrayIndex(&index)) { 4096 if (key->ToArrayIndex(&index)) {
3921 // In Firefox/SpiderMonkey, Safari and Opera you can access the 4097 // In Firefox/SpiderMonkey, Safari and Opera you can access the
3922 // characters of a string using [] notation. In the case of a 4098 // characters of a string using [] notation. In the case of a
3923 // String object we just need to redirect the deletion to the 4099 // String object we just need to redirect the deletion to the
3924 // underlying string if the index is in range. Since the 4100 // underlying string if the index is in range. Since the
3925 // underlying string does nothing with the deletion, we can ignore 4101 // underlying string does nothing with the deletion, we can ignore
3926 // such deletions. 4102 // such deletions.
3927 if (js_object->IsStringObjectWithCharacterAt(index)) { 4103 if (js_object->IsStringObjectWithCharacterAt(index)) {
3928 return Heap::true_value(); 4104 return isolate->heap()->true_value();
3929 } 4105 }
3930 4106
3931 return js_object->DeleteElement(index, JSObject::FORCE_DELETION); 4107 return js_object->DeleteElement(index, JSObject::FORCE_DELETION);
3932 } 4108 }
3933 4109
3934 Handle<String> key_string; 4110 Handle<String> key_string;
3935 if (key->IsString()) { 4111 if (key->IsString()) {
3936 key_string = Handle<String>::cast(key); 4112 key_string = Handle<String>::cast(key);
3937 } else { 4113 } else {
3938 // Call-back into JavaScript to convert the key to a string. 4114 // Call-back into JavaScript to convert the key to a string.
3939 bool has_pending_exception = false; 4115 bool has_pending_exception = false;
3940 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 4116 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
3941 if (has_pending_exception) return Failure::Exception(); 4117 if (has_pending_exception) return Failure::Exception();
3942 key_string = Handle<String>::cast(converted); 4118 key_string = Handle<String>::cast(converted);
3943 } 4119 }
3944 4120
3945 key_string->TryFlatten(); 4121 key_string->TryFlatten();
3946 return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION); 4122 return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION);
3947 } 4123 }
3948 4124
3949 4125
3950 static MaybeObject* Runtime_SetProperty(Arguments args) { 4126 static MaybeObject* Runtime_SetProperty(RUNTIME_CALLING_CONVENTION) {
4127 RUNTIME_GET_ISOLATE;
3951 NoHandleAllocation ha; 4128 NoHandleAllocation ha;
3952 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); 4129 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5);
3953 4130
3954 Handle<Object> object = args.at<Object>(0); 4131 Handle<Object> object = args.at<Object>(0);
3955 Handle<Object> key = args.at<Object>(1); 4132 Handle<Object> key = args.at<Object>(1);
3956 Handle<Object> value = args.at<Object>(2); 4133 Handle<Object> value = args.at<Object>(2);
3957 CONVERT_SMI_CHECKED(unchecked_attributes, args[3]); 4134 CONVERT_SMI_CHECKED(unchecked_attributes, args[3]);
3958 RUNTIME_ASSERT( 4135 RUNTIME_ASSERT(
3959 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 4136 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3960 // Compute attributes. 4137 // Compute attributes.
3961 PropertyAttributes attributes = 4138 PropertyAttributes attributes =
3962 static_cast<PropertyAttributes>(unchecked_attributes); 4139 static_cast<PropertyAttributes>(unchecked_attributes);
3963 4140
3964 StrictModeFlag strict_mode = kNonStrictMode; 4141 StrictModeFlag strict_mode = kNonStrictMode;
3965 if (args.length() == 5) { 4142 if (args.length() == 5) {
3966 CONVERT_SMI_CHECKED(strict_unchecked, args[4]); 4143 CONVERT_SMI_CHECKED(strict_unchecked, args[4]);
3967 RUNTIME_ASSERT(strict_unchecked == kStrictMode || 4144 RUNTIME_ASSERT(strict_unchecked == kStrictMode ||
3968 strict_unchecked == kNonStrictMode); 4145 strict_unchecked == kNonStrictMode);
3969 strict_mode = static_cast<StrictModeFlag>(strict_unchecked); 4146 strict_mode = static_cast<StrictModeFlag>(strict_unchecked);
3970 } 4147 }
3971 4148
3972 return Runtime::SetObjectProperty(object, 4149 return Runtime::SetObjectProperty(isolate,
4150 object,
3973 key, 4151 key,
3974 value, 4152 value,
3975 attributes, 4153 attributes,
3976 strict_mode); 4154 strict_mode);
3977 } 4155 }
3978 4156
3979 4157
3980 // Set a local property, even if it is READ_ONLY. If the property does not 4158 // Set a local property, even if it is READ_ONLY. If the property does not
3981 // exist, it will be added with attributes NONE. 4159 // exist, it will be added with attributes NONE.
3982 static MaybeObject* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { 4160 static MaybeObject* Runtime_IgnoreAttributesAndSetProperty(
4161 RUNTIME_CALLING_CONVENTION) {
4162 RUNTIME_GET_ISOLATE;
3983 NoHandleAllocation ha; 4163 NoHandleAllocation ha;
3984 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); 4164 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4);
3985 CONVERT_CHECKED(JSObject, object, args[0]); 4165 CONVERT_CHECKED(JSObject, object, args[0]);
3986 CONVERT_CHECKED(String, name, args[1]); 4166 CONVERT_CHECKED(String, name, args[1]);
3987 // Compute attributes. 4167 // Compute attributes.
3988 PropertyAttributes attributes = NONE; 4168 PropertyAttributes attributes = NONE;
3989 if (args.length() == 4) { 4169 if (args.length() == 4) {
3990 CONVERT_CHECKED(Smi, value_obj, args[3]); 4170 CONVERT_CHECKED(Smi, value_obj, args[3]);
3991 int unchecked_value = value_obj->value(); 4171 int unchecked_value = value_obj->value();
3992 // Only attribute bits should be set. 4172 // Only attribute bits should be set.
3993 RUNTIME_ASSERT( 4173 RUNTIME_ASSERT(
3994 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 4174 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3995 attributes = static_cast<PropertyAttributes>(unchecked_value); 4175 attributes = static_cast<PropertyAttributes>(unchecked_value);
3996 } 4176 }
3997 4177
3998 return object-> 4178 return object->
3999 SetLocalPropertyIgnoreAttributes(name, args[2], attributes); 4179 SetLocalPropertyIgnoreAttributes(name, args[2], attributes);
4000 } 4180 }
4001 4181
4002 4182
4003 static MaybeObject* Runtime_DeleteProperty(Arguments args) { 4183 static MaybeObject* Runtime_DeleteProperty(RUNTIME_CALLING_CONVENTION) {
4184 RUNTIME_GET_ISOLATE;
4004 NoHandleAllocation ha; 4185 NoHandleAllocation ha;
4005 ASSERT(args.length() == 3); 4186 ASSERT(args.length() == 3);
4006 4187
4007 CONVERT_CHECKED(JSObject, object, args[0]); 4188 CONVERT_CHECKED(JSObject, object, args[0]);
4008 CONVERT_CHECKED(String, key, args[1]); 4189 CONVERT_CHECKED(String, key, args[1]);
4009 CONVERT_SMI_CHECKED(strict, args[2]); 4190 CONVERT_SMI_CHECKED(strict, args[2]);
4010 return object->DeleteProperty(key, (strict == kStrictMode) 4191 return object->DeleteProperty(key, (strict == kStrictMode)
4011 ? JSObject::STRICT_DELETION 4192 ? JSObject::STRICT_DELETION
4012 : JSObject::NORMAL_DELETION); 4193 : JSObject::NORMAL_DELETION);
4013 } 4194 }
4014 4195
4015 4196
4016 static Object* HasLocalPropertyImplementation(Handle<JSObject> object, 4197 static Object* HasLocalPropertyImplementation(Isolate* isolate,
4198 Handle<JSObject> object,
4017 Handle<String> key) { 4199 Handle<String> key) {
4018 if (object->HasLocalProperty(*key)) return Heap::true_value(); 4200 if (object->HasLocalProperty(*key)) return isolate->heap()->true_value();
4019 // Handle hidden prototypes. If there's a hidden prototype above this thing 4201 // Handle hidden prototypes. If there's a hidden prototype above this thing
4020 // then we have to check it for properties, because they are supposed to 4202 // then we have to check it for properties, because they are supposed to
4021 // look like they are on this object. 4203 // look like they are on this object.
4022 Handle<Object> proto(object->GetPrototype()); 4204 Handle<Object> proto(object->GetPrototype());
4023 if (proto->IsJSObject() && 4205 if (proto->IsJSObject() &&
4024 Handle<JSObject>::cast(proto)->map()->is_hidden_prototype()) { 4206 Handle<JSObject>::cast(proto)->map()->is_hidden_prototype()) {
4025 return HasLocalPropertyImplementation(Handle<JSObject>::cast(proto), key); 4207 return HasLocalPropertyImplementation(isolate,
4208 Handle<JSObject>::cast(proto),
4209 key);
4026 } 4210 }
4027 return Heap::false_value(); 4211 return isolate->heap()->false_value();
4028 } 4212 }
4029 4213
4030 4214
4031 static MaybeObject* Runtime_HasLocalProperty(Arguments args) { 4215 static MaybeObject* Runtime_HasLocalProperty(RUNTIME_CALLING_CONVENTION) {
4216 RUNTIME_GET_ISOLATE;
4032 NoHandleAllocation ha; 4217 NoHandleAllocation ha;
4033 ASSERT(args.length() == 2); 4218 ASSERT(args.length() == 2);
4034 CONVERT_CHECKED(String, key, args[1]); 4219 CONVERT_CHECKED(String, key, args[1]);
4035 4220
4036 Object* obj = args[0]; 4221 Object* obj = args[0];
4037 // Only JS objects can have properties. 4222 // Only JS objects can have properties.
4038 if (obj->IsJSObject()) { 4223 if (obj->IsJSObject()) {
4039 JSObject* object = JSObject::cast(obj); 4224 JSObject* object = JSObject::cast(obj);
4040 // Fast case - no interceptors. 4225 // Fast case - no interceptors.
4041 if (object->HasRealNamedProperty(key)) return Heap::true_value(); 4226 if (object->HasRealNamedProperty(key)) return isolate->heap()->true_value();
4042 // Slow case. Either it's not there or we have an interceptor. We should 4227 // Slow case. Either it's not there or we have an interceptor. We should
4043 // have handles for this kind of deal. 4228 // have handles for this kind of deal.
4044 HandleScope scope; 4229 HandleScope scope(isolate);
4045 return HasLocalPropertyImplementation(Handle<JSObject>(object), 4230 return HasLocalPropertyImplementation(isolate,
4231 Handle<JSObject>(object),
4046 Handle<String>(key)); 4232 Handle<String>(key));
4047 } else if (obj->IsString()) { 4233 } else if (obj->IsString()) {
4048 // Well, there is one exception: Handle [] on strings. 4234 // Well, there is one exception: Handle [] on strings.
4049 uint32_t index; 4235 uint32_t index;
4050 if (key->AsArrayIndex(&index)) { 4236 if (key->AsArrayIndex(&index)) {
4051 String* string = String::cast(obj); 4237 String* string = String::cast(obj);
4052 if (index < static_cast<uint32_t>(string->length())) 4238 if (index < static_cast<uint32_t>(string->length()))
4053 return Heap::true_value(); 4239 return isolate->heap()->true_value();
4054 } 4240 }
4055 } 4241 }
4056 return Heap::false_value(); 4242 return isolate->heap()->false_value();
4057 } 4243 }
4058 4244
4059 4245
4060 static MaybeObject* Runtime_HasProperty(Arguments args) { 4246 static MaybeObject* Runtime_HasProperty(RUNTIME_CALLING_CONVENTION) {
4247 RUNTIME_GET_ISOLATE;
4061 NoHandleAllocation na; 4248 NoHandleAllocation na;
4062 ASSERT(args.length() == 2); 4249 ASSERT(args.length() == 2);
4063 4250
4064 // Only JS objects can have properties. 4251 // Only JS objects can have properties.
4065 if (args[0]->IsJSObject()) { 4252 if (args[0]->IsJSObject()) {
4066 JSObject* object = JSObject::cast(args[0]); 4253 JSObject* object = JSObject::cast(args[0]);
4067 CONVERT_CHECKED(String, key, args[1]); 4254 CONVERT_CHECKED(String, key, args[1]);
4068 if (object->HasProperty(key)) return Heap::true_value(); 4255 if (object->HasProperty(key)) return isolate->heap()->true_value();
4069 } 4256 }
4070 return Heap::false_value(); 4257 return isolate->heap()->false_value();
4071 } 4258 }
4072 4259
4073 4260
4074 static MaybeObject* Runtime_HasElement(Arguments args) { 4261 static MaybeObject* Runtime_HasElement(RUNTIME_CALLING_CONVENTION) {
4262 RUNTIME_GET_ISOLATE;
4075 NoHandleAllocation na; 4263 NoHandleAllocation na;
4076 ASSERT(args.length() == 2); 4264 ASSERT(args.length() == 2);
4077 4265
4078 // Only JS objects can have elements. 4266 // Only JS objects can have elements.
4079 if (args[0]->IsJSObject()) { 4267 if (args[0]->IsJSObject()) {
4080 JSObject* object = JSObject::cast(args[0]); 4268 JSObject* object = JSObject::cast(args[0]);
4081 CONVERT_CHECKED(Smi, index_obj, args[1]); 4269 CONVERT_CHECKED(Smi, index_obj, args[1]);
4082 uint32_t index = index_obj->value(); 4270 uint32_t index = index_obj->value();
4083 if (object->HasElement(index)) return Heap::true_value(); 4271 if (object->HasElement(index)) return isolate->heap()->true_value();
4084 } 4272 }
4085 return Heap::false_value(); 4273 return isolate->heap()->false_value();
4086 } 4274 }
4087 4275
4088 4276
4089 static MaybeObject* Runtime_IsPropertyEnumerable(Arguments args) { 4277 static MaybeObject* Runtime_IsPropertyEnumerable(RUNTIME_CALLING_CONVENTION) {
4278 RUNTIME_GET_ISOLATE;
4090 NoHandleAllocation ha; 4279 NoHandleAllocation ha;
4091 ASSERT(args.length() == 2); 4280 ASSERT(args.length() == 2);
4092 4281
4093 CONVERT_CHECKED(JSObject, object, args[0]); 4282 CONVERT_CHECKED(JSObject, object, args[0]);
4094 CONVERT_CHECKED(String, key, args[1]); 4283 CONVERT_CHECKED(String, key, args[1]);
4095 4284
4096 uint32_t index; 4285 uint32_t index;
4097 if (key->AsArrayIndex(&index)) { 4286 if (key->AsArrayIndex(&index)) {
4098 return Heap::ToBoolean(object->HasElement(index)); 4287 return isolate->heap()->ToBoolean(object->HasElement(index));
4099 } 4288 }
4100 4289
4101 PropertyAttributes att = object->GetLocalPropertyAttribute(key); 4290 PropertyAttributes att = object->GetLocalPropertyAttribute(key);
4102 return Heap::ToBoolean(att != ABSENT && (att & DONT_ENUM) == 0); 4291 return isolate->heap()->ToBoolean(att != ABSENT && (att & DONT_ENUM) == 0);
4103 } 4292 }
4104 4293
4105 4294
4106 static MaybeObject* Runtime_GetPropertyNames(Arguments args) { 4295 static MaybeObject* Runtime_GetPropertyNames(RUNTIME_CALLING_CONVENTION) {
4107 HandleScope scope; 4296 RUNTIME_GET_ISOLATE;
4297 HandleScope scope(isolate);
4108 ASSERT(args.length() == 1); 4298 ASSERT(args.length() == 1);
4109 CONVERT_ARG_CHECKED(JSObject, object, 0); 4299 CONVERT_ARG_CHECKED(JSObject, object, 0);
4110 return *GetKeysFor(object); 4300 return *GetKeysFor(object);
4111 } 4301 }
4112 4302
4113 4303
4114 // Returns either a FixedArray as Runtime_GetPropertyNames, 4304 // Returns either a FixedArray as Runtime_GetPropertyNames,
4115 // or, if the given object has an enum cache that contains 4305 // or, if the given object has an enum cache that contains
4116 // all enumerable properties of the object and its prototypes 4306 // all enumerable properties of the object and its prototypes
4117 // have none, the map of the object. This is used to speed up 4307 // have none, the map of the object. This is used to speed up
4118 // the check for deletions during a for-in. 4308 // the check for deletions during a for-in.
4119 static MaybeObject* Runtime_GetPropertyNamesFast(Arguments args) { 4309 static MaybeObject* Runtime_GetPropertyNamesFast(RUNTIME_CALLING_CONVENTION) {
4310 RUNTIME_GET_ISOLATE;
4120 ASSERT(args.length() == 1); 4311 ASSERT(args.length() == 1);
4121 4312
4122 CONVERT_CHECKED(JSObject, raw_object, args[0]); 4313 CONVERT_CHECKED(JSObject, raw_object, args[0]);
4123 4314
4124 if (raw_object->IsSimpleEnum()) return raw_object->map(); 4315 if (raw_object->IsSimpleEnum()) return raw_object->map();
4125 4316
4126 HandleScope scope; 4317 HandleScope scope(isolate);
4127 Handle<JSObject> object(raw_object); 4318 Handle<JSObject> object(raw_object);
4128 Handle<FixedArray> content = GetKeysInFixedArrayFor(object, 4319 Handle<FixedArray> content = GetKeysInFixedArrayFor(object,
4129 INCLUDE_PROTOS); 4320 INCLUDE_PROTOS);
4130 4321
4131 // Test again, since cache may have been built by preceding call. 4322 // Test again, since cache may have been built by preceding call.
4132 if (object->IsSimpleEnum()) return object->map(); 4323 if (object->IsSimpleEnum()) return object->map();
4133 4324
4134 return *content; 4325 return *content;
4135 } 4326 }
4136 4327
4137 4328
4138 // Find the length of the prototype chain that is to to handled as one. If a 4329 // Find the length of the prototype chain that is to to handled as one. If a
4139 // prototype object is hidden it is to be viewed as part of the the object it 4330 // prototype object is hidden it is to be viewed as part of the the object it
4140 // is prototype for. 4331 // is prototype for.
4141 static int LocalPrototypeChainLength(JSObject* obj) { 4332 static int LocalPrototypeChainLength(JSObject* obj) {
4142 int count = 1; 4333 int count = 1;
4143 Object* proto = obj->GetPrototype(); 4334 Object* proto = obj->GetPrototype();
4144 while (proto->IsJSObject() && 4335 while (proto->IsJSObject() &&
4145 JSObject::cast(proto)->map()->is_hidden_prototype()) { 4336 JSObject::cast(proto)->map()->is_hidden_prototype()) {
4146 count++; 4337 count++;
4147 proto = JSObject::cast(proto)->GetPrototype(); 4338 proto = JSObject::cast(proto)->GetPrototype();
4148 } 4339 }
4149 return count; 4340 return count;
4150 } 4341 }
4151 4342
4152 4343
4153 // Return the names of the local named properties. 4344 // Return the names of the local named properties.
4154 // args[0]: object 4345 // args[0]: object
4155 static MaybeObject* Runtime_GetLocalPropertyNames(Arguments args) { 4346 static MaybeObject* Runtime_GetLocalPropertyNames(RUNTIME_CALLING_CONVENTION) {
4156 HandleScope scope; 4347 RUNTIME_GET_ISOLATE;
4348 HandleScope scope(isolate);
4157 ASSERT(args.length() == 1); 4349 ASSERT(args.length() == 1);
4158 if (!args[0]->IsJSObject()) { 4350 if (!args[0]->IsJSObject()) {
4159 return Heap::undefined_value(); 4351 return isolate->heap()->undefined_value();
4160 } 4352 }
4161 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4353 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4162 4354
4163 // Skip the global proxy as it has no properties and always delegates to the 4355 // Skip the global proxy as it has no properties and always delegates to the
4164 // real global object. 4356 // real global object.
4165 if (obj->IsJSGlobalProxy()) { 4357 if (obj->IsJSGlobalProxy()) {
4166 // Only collect names if access is permitted. 4358 // Only collect names if access is permitted.
4167 if (obj->IsAccessCheckNeeded() && 4359 if (obj->IsAccessCheckNeeded() &&
4168 !Top::MayNamedAccess(*obj, Heap::undefined_value(), v8::ACCESS_KEYS)) { 4360 !isolate->MayNamedAccess(*obj,
4169 Top::ReportFailedAccessCheck(*obj, v8::ACCESS_KEYS); 4361 isolate->heap()->undefined_value(),
4170 return *Factory::NewJSArray(0); 4362 v8::ACCESS_KEYS)) {
4363 isolate->ReportFailedAccessCheck(*obj, v8::ACCESS_KEYS);
4364 return *isolate->factory()->NewJSArray(0);
4171 } 4365 }
4172 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); 4366 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
4173 } 4367 }
4174 4368
4175 // Find the number of objects making up this. 4369 // Find the number of objects making up this.
4176 int length = LocalPrototypeChainLength(*obj); 4370 int length = LocalPrototypeChainLength(*obj);
4177 4371
4178 // Find the number of local properties for each of the objects. 4372 // Find the number of local properties for each of the objects.
4179 ScopedVector<int> local_property_count(length); 4373 ScopedVector<int> local_property_count(length);
4180 int total_property_count = 0; 4374 int total_property_count = 0;
4181 Handle<JSObject> jsproto = obj; 4375 Handle<JSObject> jsproto = obj;
4182 for (int i = 0; i < length; i++) { 4376 for (int i = 0; i < length; i++) {
4183 // Only collect names if access is permitted. 4377 // Only collect names if access is permitted.
4184 if (jsproto->IsAccessCheckNeeded() && 4378 if (jsproto->IsAccessCheckNeeded() &&
4185 !Top::MayNamedAccess(*jsproto, 4379 !isolate->MayNamedAccess(*jsproto,
4186 Heap::undefined_value(), 4380 isolate->heap()->undefined_value(),
4187 v8::ACCESS_KEYS)) { 4381 v8::ACCESS_KEYS)) {
4188 Top::ReportFailedAccessCheck(*jsproto, v8::ACCESS_KEYS); 4382 isolate->ReportFailedAccessCheck(*jsproto, v8::ACCESS_KEYS);
4189 return *Factory::NewJSArray(0); 4383 return *isolate->factory()->NewJSArray(0);
4190 } 4384 }
4191 int n; 4385 int n;
4192 n = jsproto->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE)); 4386 n = jsproto->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE));
4193 local_property_count[i] = n; 4387 local_property_count[i] = n;
4194 total_property_count += n; 4388 total_property_count += n;
4195 if (i < length - 1) { 4389 if (i < length - 1) {
4196 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); 4390 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
4197 } 4391 }
4198 } 4392 }
4199 4393
4200 // Allocate an array with storage for all the property names. 4394 // Allocate an array with storage for all the property names.
4201 Handle<FixedArray> names = Factory::NewFixedArray(total_property_count); 4395 Handle<FixedArray> names =
4396 isolate->factory()->NewFixedArray(total_property_count);
4202 4397
4203 // Get the property names. 4398 // Get the property names.
4204 jsproto = obj; 4399 jsproto = obj;
4205 int proto_with_hidden_properties = 0; 4400 int proto_with_hidden_properties = 0;
4206 for (int i = 0; i < length; i++) { 4401 for (int i = 0; i < length; i++) {
4207 jsproto->GetLocalPropertyNames(*names, 4402 jsproto->GetLocalPropertyNames(*names,
4208 i == 0 ? 0 : local_property_count[i - 1]); 4403 i == 0 ? 0 : local_property_count[i - 1]);
4209 if (!GetHiddenProperties(jsproto, false)->IsUndefined()) { 4404 if (!GetHiddenProperties(jsproto, false)->IsUndefined()) {
4210 proto_with_hidden_properties++; 4405 proto_with_hidden_properties++;
4211 } 4406 }
4212 if (i < length - 1) { 4407 if (i < length - 1) {
4213 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); 4408 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
4214 } 4409 }
4215 } 4410 }
4216 4411
4217 // Filter out name of hidden propeties object. 4412 // Filter out name of hidden propeties object.
4218 if (proto_with_hidden_properties > 0) { 4413 if (proto_with_hidden_properties > 0) {
4219 Handle<FixedArray> old_names = names; 4414 Handle<FixedArray> old_names = names;
4220 names = Factory::NewFixedArray( 4415 names = isolate->factory()->NewFixedArray(
4221 names->length() - proto_with_hidden_properties); 4416 names->length() - proto_with_hidden_properties);
4222 int dest_pos = 0; 4417 int dest_pos = 0;
4223 for (int i = 0; i < total_property_count; i++) { 4418 for (int i = 0; i < total_property_count; i++) {
4224 Object* name = old_names->get(i); 4419 Object* name = old_names->get(i);
4225 if (name == Heap::hidden_symbol()) { 4420 if (name == isolate->heap()->hidden_symbol()) {
4226 continue; 4421 continue;
4227 } 4422 }
4228 names->set(dest_pos++, name); 4423 names->set(dest_pos++, name);
4229 } 4424 }
4230 } 4425 }
4231 4426
4232 return *Factory::NewJSArrayWithElements(names); 4427 return *isolate->factory()->NewJSArrayWithElements(names);
4233 } 4428 }
4234 4429
4235 4430
4236 // Return the names of the local indexed properties. 4431 // Return the names of the local indexed properties.
4237 // args[0]: object 4432 // args[0]: object
4238 static MaybeObject* Runtime_GetLocalElementNames(Arguments args) { 4433 static MaybeObject* Runtime_GetLocalElementNames(RUNTIME_CALLING_CONVENTION) {
4239 HandleScope scope; 4434 RUNTIME_GET_ISOLATE;
4435 HandleScope scope(isolate);
4240 ASSERT(args.length() == 1); 4436 ASSERT(args.length() == 1);
4241 if (!args[0]->IsJSObject()) { 4437 if (!args[0]->IsJSObject()) {
4242 return Heap::undefined_value(); 4438 return isolate->heap()->undefined_value();
4243 } 4439 }
4244 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4440 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4245 4441
4246 int n = obj->NumberOfLocalElements(static_cast<PropertyAttributes>(NONE)); 4442 int n = obj->NumberOfLocalElements(static_cast<PropertyAttributes>(NONE));
4247 Handle<FixedArray> names = Factory::NewFixedArray(n); 4443 Handle<FixedArray> names = isolate->factory()->NewFixedArray(n);
4248 obj->GetLocalElementKeys(*names, static_cast<PropertyAttributes>(NONE)); 4444 obj->GetLocalElementKeys(*names, static_cast<PropertyAttributes>(NONE));
4249 return *Factory::NewJSArrayWithElements(names); 4445 return *isolate->factory()->NewJSArrayWithElements(names);
4250 } 4446 }
4251 4447
4252 4448
4253 // Return information on whether an object has a named or indexed interceptor. 4449 // Return information on whether an object has a named or indexed interceptor.
4254 // args[0]: object 4450 // args[0]: object
4255 static MaybeObject* Runtime_GetInterceptorInfo(Arguments args) { 4451 static MaybeObject* Runtime_GetInterceptorInfo(RUNTIME_CALLING_CONVENTION) {
4256 HandleScope scope; 4452 RUNTIME_GET_ISOLATE;
4453 HandleScope scope(isolate);
4257 ASSERT(args.length() == 1); 4454 ASSERT(args.length() == 1);
4258 if (!args[0]->IsJSObject()) { 4455 if (!args[0]->IsJSObject()) {
4259 return Smi::FromInt(0); 4456 return Smi::FromInt(0);
4260 } 4457 }
4261 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4458 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4262 4459
4263 int result = 0; 4460 int result = 0;
4264 if (obj->HasNamedInterceptor()) result |= 2; 4461 if (obj->HasNamedInterceptor()) result |= 2;
4265 if (obj->HasIndexedInterceptor()) result |= 1; 4462 if (obj->HasIndexedInterceptor()) result |= 1;
4266 4463
4267 return Smi::FromInt(result); 4464 return Smi::FromInt(result);
4268 } 4465 }
4269 4466
4270 4467
4271 // Return property names from named interceptor. 4468 // Return property names from named interceptor.
4272 // args[0]: object 4469 // args[0]: object
4273 static MaybeObject* Runtime_GetNamedInterceptorPropertyNames(Arguments args) { 4470 static MaybeObject* Runtime_GetNamedInterceptorPropertyNames(
4274 HandleScope scope; 4471 RUNTIME_CALLING_CONVENTION) {
4472 RUNTIME_GET_ISOLATE;
4473 HandleScope scope(isolate);
4275 ASSERT(args.length() == 1); 4474 ASSERT(args.length() == 1);
4276 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4475 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4277 4476
4278 if (obj->HasNamedInterceptor()) { 4477 if (obj->HasNamedInterceptor()) {
4279 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj); 4478 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj);
4280 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result); 4479 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
4281 } 4480 }
4282 return Heap::undefined_value(); 4481 return isolate->heap()->undefined_value();
4283 } 4482 }
4284 4483
4285 4484
4286 // Return element names from indexed interceptor. 4485 // Return element names from indexed interceptor.
4287 // args[0]: object 4486 // args[0]: object
4288 static MaybeObject* Runtime_GetIndexedInterceptorElementNames(Arguments args) { 4487 static MaybeObject* Runtime_GetIndexedInterceptorElementNames(
4289 HandleScope scope; 4488 RUNTIME_CALLING_CONVENTION) {
4489 RUNTIME_GET_ISOLATE;
4490 HandleScope scope(isolate);
4290 ASSERT(args.length() == 1); 4491 ASSERT(args.length() == 1);
4291 CONVERT_ARG_CHECKED(JSObject, obj, 0); 4492 CONVERT_ARG_CHECKED(JSObject, obj, 0);
4292 4493
4293 if (obj->HasIndexedInterceptor()) { 4494 if (obj->HasIndexedInterceptor()) {
4294 v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj); 4495 v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj);
4295 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result); 4496 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
4296 } 4497 }
4297 return Heap::undefined_value(); 4498 return isolate->heap()->undefined_value();
4298 } 4499 }
4299 4500
4300 4501
4301 static MaybeObject* Runtime_LocalKeys(Arguments args) { 4502 static MaybeObject* Runtime_LocalKeys(RUNTIME_CALLING_CONVENTION) {
4503 RUNTIME_GET_ISOLATE;
4302 ASSERT_EQ(args.length(), 1); 4504 ASSERT_EQ(args.length(), 1);
4303 CONVERT_CHECKED(JSObject, raw_object, args[0]); 4505 CONVERT_CHECKED(JSObject, raw_object, args[0]);
4304 HandleScope scope; 4506 HandleScope scope(isolate);
4305 Handle<JSObject> object(raw_object); 4507 Handle<JSObject> object(raw_object);
4306 4508
4307 if (object->IsJSGlobalProxy()) { 4509 if (object->IsJSGlobalProxy()) {
4308 // Do access checks before going to the global object. 4510 // Do access checks before going to the global object.
4309 if (object->IsAccessCheckNeeded() && 4511 if (object->IsAccessCheckNeeded() &&
4310 !Top::MayNamedAccess(*object, Heap::undefined_value(), 4512 !isolate->MayNamedAccess(*object, isolate->heap()->undefined_value(),
4311 v8::ACCESS_KEYS)) { 4513 v8::ACCESS_KEYS)) {
4312 Top::ReportFailedAccessCheck(*object, v8::ACCESS_KEYS); 4514 isolate->ReportFailedAccessCheck(*object, v8::ACCESS_KEYS);
4313 return *Factory::NewJSArray(0); 4515 return *isolate->factory()->NewJSArray(0);
4314 } 4516 }
4315 4517
4316 Handle<Object> proto(object->GetPrototype()); 4518 Handle<Object> proto(object->GetPrototype());
4317 // If proxy is detached we simply return an empty array. 4519 // If proxy is detached we simply return an empty array.
4318 if (proto->IsNull()) return *Factory::NewJSArray(0); 4520 if (proto->IsNull()) return *isolate->factory()->NewJSArray(0);
4319 object = Handle<JSObject>::cast(proto); 4521 object = Handle<JSObject>::cast(proto);
4320 } 4522 }
4321 4523
4322 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object, 4524 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object,
4323 LOCAL_ONLY); 4525 LOCAL_ONLY);
4324 // Some fast paths through GetKeysInFixedArrayFor reuse a cached 4526 // Some fast paths through GetKeysInFixedArrayFor reuse a cached
4325 // property array and since the result is mutable we have to create 4527 // property array and since the result is mutable we have to create
4326 // a fresh clone on each invocation. 4528 // a fresh clone on each invocation.
4327 int length = contents->length(); 4529 int length = contents->length();
4328 Handle<FixedArray> copy = Factory::NewFixedArray(length); 4530 Handle<FixedArray> copy = isolate->factory()->NewFixedArray(length);
4329 for (int i = 0; i < length; i++) { 4531 for (int i = 0; i < length; i++) {
4330 Object* entry = contents->get(i); 4532 Object* entry = contents->get(i);
4331 if (entry->IsString()) { 4533 if (entry->IsString()) {
4332 copy->set(i, entry); 4534 copy->set(i, entry);
4333 } else { 4535 } else {
4334 ASSERT(entry->IsNumber()); 4536 ASSERT(entry->IsNumber());
4335 HandleScope scope; 4537 HandleScope scope(isolate);
4336 Handle<Object> entry_handle(entry); 4538 Handle<Object> entry_handle(entry, isolate);
4337 Handle<Object> entry_str = Factory::NumberToString(entry_handle); 4539 Handle<Object> entry_str =
4540 isolate->factory()->NumberToString(entry_handle);
4338 copy->set(i, *entry_str); 4541 copy->set(i, *entry_str);
4339 } 4542 }
4340 } 4543 }
4341 return *Factory::NewJSArrayWithElements(copy); 4544 return *isolate->factory()->NewJSArrayWithElements(copy);
4342 } 4545 }
4343 4546
4344 4547
4345 static MaybeObject* Runtime_GetArgumentsProperty(Arguments args) { 4548 static MaybeObject* Runtime_GetArgumentsProperty(RUNTIME_CALLING_CONVENTION) {
4549 RUNTIME_GET_ISOLATE;
4346 NoHandleAllocation ha; 4550 NoHandleAllocation ha;
4347 ASSERT(args.length() == 1); 4551 ASSERT(args.length() == 1);
4348 4552
4349 // Compute the frame holding the arguments. 4553 // Compute the frame holding the arguments.
4350 JavaScriptFrameIterator it; 4554 JavaScriptFrameIterator it;
4351 it.AdvanceToArgumentsFrame(); 4555 it.AdvanceToArgumentsFrame();
4352 JavaScriptFrame* frame = it.frame(); 4556 JavaScriptFrame* frame = it.frame();
4353 4557
4354 // Get the actual number of provided arguments. 4558 // Get the actual number of provided arguments.
4355 const uint32_t n = frame->ComputeParametersCount(); 4559 const uint32_t n = frame->ComputeParametersCount();
4356 4560
4357 // Try to convert the key to an index. If successful and within 4561 // Try to convert the key to an index. If successful and within
4358 // index return the the argument from the frame. 4562 // index return the the argument from the frame.
4359 uint32_t index; 4563 uint32_t index;
4360 if (args[0]->ToArrayIndex(&index) && index < n) { 4564 if (args[0]->ToArrayIndex(&index) && index < n) {
4361 return frame->GetParameter(index); 4565 return frame->GetParameter(index);
4362 } 4566 }
4363 4567
4364 // Convert the key to a string. 4568 // Convert the key to a string.
4365 HandleScope scope; 4569 HandleScope scope(isolate);
4366 bool exception = false; 4570 bool exception = false;
4367 Handle<Object> converted = 4571 Handle<Object> converted =
4368 Execution::ToString(args.at<Object>(0), &exception); 4572 Execution::ToString(args.at<Object>(0), &exception);
4369 if (exception) return Failure::Exception(); 4573 if (exception) return Failure::Exception();
4370 Handle<String> key = Handle<String>::cast(converted); 4574 Handle<String> key = Handle<String>::cast(converted);
4371 4575
4372 // Try to convert the string key into an array index. 4576 // Try to convert the string key into an array index.
4373 if (key->AsArrayIndex(&index)) { 4577 if (key->AsArrayIndex(&index)) {
4374 if (index < n) { 4578 if (index < n) {
4375 return frame->GetParameter(index); 4579 return frame->GetParameter(index);
4376 } else { 4580 } else {
4377 return Top::initial_object_prototype()->GetElement(index); 4581 return isolate->initial_object_prototype()->GetElement(index);
4378 } 4582 }
4379 } 4583 }
4380 4584
4381 // Handle special arguments properties. 4585 // Handle special arguments properties.
4382 if (key->Equals(Heap::length_symbol())) return Smi::FromInt(n); 4586 if (key->Equals(isolate->heap()->length_symbol())) return Smi::FromInt(n);
4383 if (key->Equals(Heap::callee_symbol())) { 4587 if (key->Equals(isolate->heap()->callee_symbol())) {
4384 Object* function = frame->function(); 4588 Object* function = frame->function();
4385 if (function->IsJSFunction() && 4589 if (function->IsJSFunction() &&
4386 JSFunction::cast(function)->shared()->strict_mode()) { 4590 JSFunction::cast(function)->shared()->strict_mode()) {
4387 return Top::Throw(*Factory::NewTypeError("strict_arguments_callee", 4591 return isolate->Throw(*isolate->factory()->NewTypeError(
4388 HandleVector<Object>(NULL, 0))); 4592 "strict_arguments_callee", HandleVector<Object>(NULL, 0)));
4389 } 4593 }
4390 return function; 4594 return function;
4391 } 4595 }
4392 4596
4393 // Lookup in the initial Object.prototype object. 4597 // Lookup in the initial Object.prototype object.
4394 return Top::initial_object_prototype()->GetProperty(*key); 4598 return isolate->initial_object_prototype()->GetProperty(*key);
4395 } 4599 }
4396 4600
4397 4601
4398 static MaybeObject* Runtime_ToFastProperties(Arguments args) { 4602 static MaybeObject* Runtime_ToFastProperties(RUNTIME_CALLING_CONVENTION) {
4399 HandleScope scope; 4603 RUNTIME_GET_ISOLATE;
4604 HandleScope scope(isolate);
4400 4605
4401 ASSERT(args.length() == 1); 4606 ASSERT(args.length() == 1);
4402 Handle<Object> object = args.at<Object>(0); 4607 Handle<Object> object = args.at<Object>(0);
4403 if (object->IsJSObject()) { 4608 if (object->IsJSObject()) {
4404 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 4609 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
4405 if (!js_object->HasFastProperties() && !js_object->IsGlobalObject()) { 4610 if (!js_object->HasFastProperties() && !js_object->IsGlobalObject()) {
4406 MaybeObject* ok = js_object->TransformToFastProperties(0); 4611 MaybeObject* ok = js_object->TransformToFastProperties(0);
4407 if (ok->IsRetryAfterGC()) return ok; 4612 if (ok->IsRetryAfterGC()) return ok;
4408 } 4613 }
4409 } 4614 }
4410 return *object; 4615 return *object;
4411 } 4616 }
4412 4617
4413 4618
4414 static MaybeObject* Runtime_ToSlowProperties(Arguments args) { 4619 static MaybeObject* Runtime_ToSlowProperties(RUNTIME_CALLING_CONVENTION) {
4415 HandleScope scope; 4620 RUNTIME_GET_ISOLATE;
4621 HandleScope scope(isolate);
4416 4622
4417 ASSERT(args.length() == 1); 4623 ASSERT(args.length() == 1);
4418 Handle<Object> object = args.at<Object>(0); 4624 Handle<Object> object = args.at<Object>(0);
4419 if (object->IsJSObject() && !object->IsJSGlobalProxy()) { 4625 if (object->IsJSObject() && !object->IsJSGlobalProxy()) {
4420 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 4626 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
4421 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); 4627 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0);
4422 } 4628 }
4423 return *object; 4629 return *object;
4424 } 4630 }
4425 4631
4426 4632
4427 static MaybeObject* Runtime_ToBool(Arguments args) { 4633 static MaybeObject* Runtime_ToBool(RUNTIME_CALLING_CONVENTION) {
4634 RUNTIME_GET_ISOLATE;
4428 NoHandleAllocation ha; 4635 NoHandleAllocation ha;
4429 ASSERT(args.length() == 1); 4636 ASSERT(args.length() == 1);
4430 4637
4431 return args[0]->ToBoolean(); 4638 return args[0]->ToBoolean();
4432 } 4639 }
4433 4640
4434 4641
4435 // Returns the type string of a value; see ECMA-262, 11.4.3 (p 47). 4642 // Returns the type string of a value; see ECMA-262, 11.4.3 (p 47).
4436 // Possible optimizations: put the type string into the oddballs. 4643 // Possible optimizations: put the type string into the oddballs.
4437 static MaybeObject* Runtime_Typeof(Arguments args) { 4644 static MaybeObject* Runtime_Typeof(RUNTIME_CALLING_CONVENTION) {
4645 RUNTIME_GET_ISOLATE;
4438 NoHandleAllocation ha; 4646 NoHandleAllocation ha;
4439 4647
4440 Object* obj = args[0]; 4648 Object* obj = args[0];
4441 if (obj->IsNumber()) return Heap::number_symbol(); 4649 if (obj->IsNumber()) return isolate->heap()->number_symbol();
4442 HeapObject* heap_obj = HeapObject::cast(obj); 4650 HeapObject* heap_obj = HeapObject::cast(obj);
4443 4651
4444 // typeof an undetectable object is 'undefined' 4652 // typeof an undetectable object is 'undefined'
4445 if (heap_obj->map()->is_undetectable()) return Heap::undefined_symbol(); 4653 if (heap_obj->map()->is_undetectable()) {
4654 return isolate->heap()->undefined_symbol();
4655 }
4446 4656
4447 InstanceType instance_type = heap_obj->map()->instance_type(); 4657 InstanceType instance_type = heap_obj->map()->instance_type();
4448 if (instance_type < FIRST_NONSTRING_TYPE) { 4658 if (instance_type < FIRST_NONSTRING_TYPE) {
4449 return Heap::string_symbol(); 4659 return isolate->heap()->string_symbol();
4450 } 4660 }
4451 4661
4452 switch (instance_type) { 4662 switch (instance_type) {
4453 case ODDBALL_TYPE: 4663 case ODDBALL_TYPE:
4454 if (heap_obj->IsTrue() || heap_obj->IsFalse()) { 4664 if (heap_obj->IsTrue() || heap_obj->IsFalse()) {
4455 return Heap::boolean_symbol(); 4665 return isolate->heap()->boolean_symbol();
4456 } 4666 }
4457 if (heap_obj->IsNull()) { 4667 if (heap_obj->IsNull()) {
4458 return Heap::object_symbol(); 4668 return isolate->heap()->object_symbol();
4459 } 4669 }
4460 ASSERT(heap_obj->IsUndefined()); 4670 ASSERT(heap_obj->IsUndefined());
4461 return Heap::undefined_symbol(); 4671 return isolate->heap()->undefined_symbol();
4462 case JS_FUNCTION_TYPE: case JS_REGEXP_TYPE: 4672 case JS_FUNCTION_TYPE: case JS_REGEXP_TYPE:
4463 return Heap::function_symbol(); 4673 return isolate->heap()->function_symbol();
4464 default: 4674 default:
4465 // For any kind of object not handled above, the spec rule for 4675 // For any kind of object not handled above, the spec rule for
4466 // host objects gives that it is okay to return "object" 4676 // host objects gives that it is okay to return "object"
4467 return Heap::object_symbol(); 4677 return isolate->heap()->object_symbol();
4468 } 4678 }
4469 } 4679 }
4470 4680
4471 4681
4472 static bool AreDigits(const char*s, int from, int to) { 4682 static bool AreDigits(const char*s, int from, int to) {
4473 for (int i = from; i < to; i++) { 4683 for (int i = from; i < to; i++) {
4474 if (s[i] < '0' || s[i] > '9') return false; 4684 if (s[i] < '0' || s[i] > '9') return false;
4475 } 4685 }
4476 4686
4477 return true; 4687 return true;
4478 } 4688 }
4479 4689
4480 4690
4481 static int ParseDecimalInteger(const char*s, int from, int to) { 4691 static int ParseDecimalInteger(const char*s, int from, int to) {
4482 ASSERT(to - from < 10); // Overflow is not possible. 4692 ASSERT(to - from < 10); // Overflow is not possible.
4483 ASSERT(from < to); 4693 ASSERT(from < to);
4484 int d = s[from] - '0'; 4694 int d = s[from] - '0';
4485 4695
4486 for (int i = from + 1; i < to; i++) { 4696 for (int i = from + 1; i < to; i++) {
4487 d = 10 * d + (s[i] - '0'); 4697 d = 10 * d + (s[i] - '0');
4488 } 4698 }
4489 4699
4490 return d; 4700 return d;
4491 } 4701 }
4492 4702
4493 4703
4494 static MaybeObject* Runtime_StringToNumber(Arguments args) { 4704 static MaybeObject* Runtime_StringToNumber(RUNTIME_CALLING_CONVENTION) {
4705 RUNTIME_GET_ISOLATE;
4495 NoHandleAllocation ha; 4706 NoHandleAllocation ha;
4496 ASSERT(args.length() == 1); 4707 ASSERT(args.length() == 1);
4497 CONVERT_CHECKED(String, subject, args[0]); 4708 CONVERT_CHECKED(String, subject, args[0]);
4498 subject->TryFlatten(); 4709 subject->TryFlatten();
4499 4710
4500 // Fast case: short integer or some sorts of junk values. 4711 // Fast case: short integer or some sorts of junk values.
4501 int len = subject->length(); 4712 int len = subject->length();
4502 if (subject->IsSeqAsciiString()) { 4713 if (subject->IsSeqAsciiString()) {
4503 if (len == 0) return Smi::FromInt(0); 4714 if (len == 0) return Smi::FromInt(0);
4504 4715
4505 char const* data = SeqAsciiString::cast(subject)->GetChars(); 4716 char const* data = SeqAsciiString::cast(subject)->GetChars();
4506 bool minus = (data[0] == '-'); 4717 bool minus = (data[0] == '-');
4507 int start_pos = (minus ? 1 : 0); 4718 int start_pos = (minus ? 1 : 0);
4508 4719
4509 if (start_pos == len) { 4720 if (start_pos == len) {
4510 return Heap::nan_value(); 4721 return isolate->heap()->nan_value();
4511 } else if (data[start_pos] > '9') { 4722 } else if (data[start_pos] > '9') {
4512 // Fast check for a junk value. A valid string may start from a 4723 // Fast check for a junk value. A valid string may start from a
4513 // whitespace, a sign ('+' or '-'), the decimal point, a decimal digit or 4724 // whitespace, a sign ('+' or '-'), the decimal point, a decimal digit or
4514 // the 'I' character ('Infinity'). All of that have codes not greater than 4725 // the 'I' character ('Infinity'). All of that have codes not greater than
4515 // '9' except 'I'. 4726 // '9' except 'I'.
4516 if (data[start_pos] != 'I') { 4727 if (data[start_pos] != 'I') {
4517 return Heap::nan_value(); 4728 return isolate->heap()->nan_value();
4518 } 4729 }
4519 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { 4730 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) {
4520 // The maximal/minimal smi has 10 digits. If the string has less digits we 4731 // The maximal/minimal smi has 10 digits. If the string has less digits we
4521 // know it will fit into the smi-data type. 4732 // know it will fit into the smi-data type.
4522 int d = ParseDecimalInteger(data, start_pos, len); 4733 int d = ParseDecimalInteger(data, start_pos, len);
4523 if (minus) { 4734 if (minus) {
4524 if (d == 0) return Heap::minus_zero_value(); 4735 if (d == 0) return isolate->heap()->minus_zero_value();
4525 d = -d; 4736 d = -d;
4526 } else if (!subject->HasHashCode() && 4737 } else if (!subject->HasHashCode() &&
4527 len <= String::kMaxArrayIndexSize && 4738 len <= String::kMaxArrayIndexSize &&
4528 (len == 1 || data[0] != '0')) { 4739 (len == 1 || data[0] != '0')) {
4529 // String hash is not calculated yet but all the data are present. 4740 // String hash is not calculated yet but all the data are present.
4530 // Update the hash field to speed up sequential convertions. 4741 // Update the hash field to speed up sequential convertions.
4531 uint32_t hash = StringHasher::MakeArrayIndexHash(d, len); 4742 uint32_t hash = StringHasher::MakeArrayIndexHash(d, len);
4532 #ifdef DEBUG 4743 #ifdef DEBUG
4533 subject->Hash(); // Force hash calculation. 4744 subject->Hash(); // Force hash calculation.
4534 ASSERT_EQ(static_cast<int>(subject->hash_field()), 4745 ASSERT_EQ(static_cast<int>(subject->hash_field()),
4535 static_cast<int>(hash)); 4746 static_cast<int>(hash));
4536 #endif 4747 #endif
4537 subject->set_hash_field(hash); 4748 subject->set_hash_field(hash);
4538 } 4749 }
4539 return Smi::FromInt(d); 4750 return Smi::FromInt(d);
4540 } 4751 }
4541 } 4752 }
4542 4753
4543 // Slower case. 4754 // Slower case.
4544 return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX)); 4755 return isolate->heap()->NumberFromDouble(StringToDouble(subject, ALLOW_HEX));
4545 } 4756 }
4546 4757
4547 4758
4548 static MaybeObject* Runtime_StringFromCharCodeArray(Arguments args) { 4759 static MaybeObject* Runtime_StringFromCharCodeArray(
4760 RUNTIME_CALLING_CONVENTION) {
4761 RUNTIME_GET_ISOLATE;
4549 NoHandleAllocation ha; 4762 NoHandleAllocation ha;
4550 ASSERT(args.length() == 1); 4763 ASSERT(args.length() == 1);
4551 4764
4552 CONVERT_CHECKED(JSArray, codes, args[0]); 4765 CONVERT_CHECKED(JSArray, codes, args[0]);
4553 int length = Smi::cast(codes->length())->value(); 4766 int length = Smi::cast(codes->length())->value();
4554 4767
4555 // Check if the string can be ASCII. 4768 // Check if the string can be ASCII.
4556 int i; 4769 int i;
4557 for (i = 0; i < length; i++) { 4770 for (i = 0; i < length; i++) {
4558 Object* element; 4771 Object* element;
4559 { MaybeObject* maybe_element = codes->GetElement(i); 4772 { MaybeObject* maybe_element = codes->GetElement(i);
4560 // We probably can't get an exception here, but just in order to enforce 4773 // We probably can't get an exception here, but just in order to enforce
4561 // the checking of inputs in the runtime calls we check here. 4774 // the checking of inputs in the runtime calls we check here.
4562 if (!maybe_element->ToObject(&element)) return maybe_element; 4775 if (!maybe_element->ToObject(&element)) return maybe_element;
4563 } 4776 }
4564 CONVERT_NUMBER_CHECKED(int, chr, Int32, element); 4777 CONVERT_NUMBER_CHECKED(int, chr, Int32, element);
4565 if ((chr & 0xffff) > String::kMaxAsciiCharCode) 4778 if ((chr & 0xffff) > String::kMaxAsciiCharCode)
4566 break; 4779 break;
4567 } 4780 }
4568 4781
4569 MaybeObject* maybe_object = NULL; 4782 MaybeObject* maybe_object = NULL;
4570 if (i == length) { // The string is ASCII. 4783 if (i == length) { // The string is ASCII.
4571 maybe_object = Heap::AllocateRawAsciiString(length); 4784 maybe_object = isolate->heap()->AllocateRawAsciiString(length);
4572 } else { // The string is not ASCII. 4785 } else { // The string is not ASCII.
4573 maybe_object = Heap::AllocateRawTwoByteString(length); 4786 maybe_object = isolate->heap()->AllocateRawTwoByteString(length);
4574 } 4787 }
4575 4788
4576 Object* object = NULL; 4789 Object* object = NULL;
4577 if (!maybe_object->ToObject(&object)) return maybe_object; 4790 if (!maybe_object->ToObject(&object)) return maybe_object;
4578 String* result = String::cast(object); 4791 String* result = String::cast(object);
4579 for (int i = 0; i < length; i++) { 4792 for (int i = 0; i < length; i++) {
4580 Object* element; 4793 Object* element;
4581 { MaybeObject* maybe_element = codes->GetElement(i); 4794 { MaybeObject* maybe_element = codes->GetElement(i);
4582 if (!maybe_element->ToObject(&element)) return maybe_element; 4795 if (!maybe_element->ToObject(&element)) return maybe_element;
4583 } 4796 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4618 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4831 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4619 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4832 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4620 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4833 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4621 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4834 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4622 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4835 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4623 }; 4836 };
4624 return kNotEscaped[character] != 0; 4837 return kNotEscaped[character] != 0;
4625 } 4838 }
4626 4839
4627 4840
4628 static MaybeObject* Runtime_URIEscape(Arguments args) { 4841 static MaybeObject* Runtime_URIEscape(RUNTIME_CALLING_CONVENTION) {
4842 RUNTIME_GET_ISOLATE;
4629 const char hex_chars[] = "0123456789ABCDEF"; 4843 const char hex_chars[] = "0123456789ABCDEF";
4630 NoHandleAllocation ha; 4844 NoHandleAllocation ha;
4631 ASSERT(args.length() == 1); 4845 ASSERT(args.length() == 1);
4632 CONVERT_CHECKED(String, source, args[0]); 4846 CONVERT_CHECKED(String, source, args[0]);
4633 4847
4634 source->TryFlatten(); 4848 source->TryFlatten();
4635 4849
4636 int escaped_length = 0; 4850 int escaped_length = 0;
4637 int length = source->length(); 4851 int length = source->length();
4638 { 4852 {
4639 Access<StringInputBuffer> buffer(&runtime_string_input_buffer); 4853 Access<StringInputBuffer> buffer(
4854 isolate->runtime_state()->string_input_buffer());
4640 buffer->Reset(source); 4855 buffer->Reset(source);
4641 while (buffer->has_more()) { 4856 while (buffer->has_more()) {
4642 uint16_t character = buffer->GetNext(); 4857 uint16_t character = buffer->GetNext();
4643 if (character >= 256) { 4858 if (character >= 256) {
4644 escaped_length += 6; 4859 escaped_length += 6;
4645 } else if (IsNotEscaped(character)) { 4860 } else if (IsNotEscaped(character)) {
4646 escaped_length++; 4861 escaped_length++;
4647 } else { 4862 } else {
4648 escaped_length += 3; 4863 escaped_length += 3;
4649 } 4864 }
4650 // We don't allow strings that are longer than a maximal length. 4865 // We don't allow strings that are longer than a maximal length.
4651 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. 4866 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow.
4652 if (escaped_length > String::kMaxLength) { 4867 if (escaped_length > String::kMaxLength) {
4653 Top::context()->mark_out_of_memory(); 4868 isolate->context()->mark_out_of_memory();
4654 return Failure::OutOfMemoryException(); 4869 return Failure::OutOfMemoryException();
4655 } 4870 }
4656 } 4871 }
4657 } 4872 }
4658 // No length change implies no change. Return original string if no change. 4873 // No length change implies no change. Return original string if no change.
4659 if (escaped_length == length) { 4874 if (escaped_length == length) {
4660 return source; 4875 return source;
4661 } 4876 }
4662 Object* o; 4877 Object* o;
4663 { MaybeObject* maybe_o = Heap::AllocateRawAsciiString(escaped_length); 4878 { MaybeObject* maybe_o =
4879 isolate->heap()->AllocateRawAsciiString(escaped_length);
4664 if (!maybe_o->ToObject(&o)) return maybe_o; 4880 if (!maybe_o->ToObject(&o)) return maybe_o;
4665 } 4881 }
4666 String* destination = String::cast(o); 4882 String* destination = String::cast(o);
4667 int dest_position = 0; 4883 int dest_position = 0;
4668 4884
4669 Access<StringInputBuffer> buffer(&runtime_string_input_buffer); 4885 Access<StringInputBuffer> buffer(
4886 isolate->runtime_state()->string_input_buffer());
4670 buffer->Rewind(); 4887 buffer->Rewind();
4671 while (buffer->has_more()) { 4888 while (buffer->has_more()) {
4672 uint16_t chr = buffer->GetNext(); 4889 uint16_t chr = buffer->GetNext();
4673 if (chr >= 256) { 4890 if (chr >= 256) {
4674 destination->Set(dest_position, '%'); 4891 destination->Set(dest_position, '%');
4675 destination->Set(dest_position+1, 'u'); 4892 destination->Set(dest_position+1, 'u');
4676 destination->Set(dest_position+2, hex_chars[chr >> 12]); 4893 destination->Set(dest_position+2, hex_chars[chr >> 12]);
4677 destination->Set(dest_position+3, hex_chars[(chr >> 8) & 0xf]); 4894 destination->Set(dest_position+3, hex_chars[(chr >> 8) & 0xf]);
4678 destination->Set(dest_position+4, hex_chars[(chr >> 4) & 0xf]); 4895 destination->Set(dest_position+4, hex_chars[(chr >> 4) & 0xf]);
4679 destination->Set(dest_position+5, hex_chars[chr & 0xf]); 4896 destination->Set(dest_position+5, hex_chars[chr & 0xf]);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4734 source->Get(i + 2))) != -1) { 4951 source->Get(i + 2))) != -1) {
4735 *step = 3; 4952 *step = 3;
4736 return lo; 4953 return lo;
4737 } else { 4954 } else {
4738 *step = 1; 4955 *step = 1;
4739 return character; 4956 return character;
4740 } 4957 }
4741 } 4958 }
4742 4959
4743 4960
4744 static MaybeObject* Runtime_URIUnescape(Arguments args) { 4961 static MaybeObject* Runtime_URIUnescape(RUNTIME_CALLING_CONVENTION) {
4962 RUNTIME_GET_ISOLATE;
4745 NoHandleAllocation ha; 4963 NoHandleAllocation ha;
4746 ASSERT(args.length() == 1); 4964 ASSERT(args.length() == 1);
4747 CONVERT_CHECKED(String, source, args[0]); 4965 CONVERT_CHECKED(String, source, args[0]);
4748 4966
4749 source->TryFlatten(); 4967 source->TryFlatten();
4750 4968
4751 bool ascii = true; 4969 bool ascii = true;
4752 int length = source->length(); 4970 int length = source->length();
4753 4971
4754 int unescaped_length = 0; 4972 int unescaped_length = 0;
4755 for (int i = 0; i < length; unescaped_length++) { 4973 for (int i = 0; i < length; unescaped_length++) {
4756 int step; 4974 int step;
4757 if (Unescape(source, i, length, &step) > String::kMaxAsciiCharCode) { 4975 if (Unescape(source, i, length, &step) > String::kMaxAsciiCharCode) {
4758 ascii = false; 4976 ascii = false;
4759 } 4977 }
4760 i += step; 4978 i += step;
4761 } 4979 }
4762 4980
4763 // No length change implies no change. Return original string if no change. 4981 // No length change implies no change. Return original string if no change.
4764 if (unescaped_length == length) 4982 if (unescaped_length == length)
4765 return source; 4983 return source;
4766 4984
4767 Object* o; 4985 Object* o;
4768 { MaybeObject* maybe_o = ascii ? 4986 { MaybeObject* maybe_o =
4769 Heap::AllocateRawAsciiString(unescaped_length) : 4987 ascii ?
4770 Heap::AllocateRawTwoByteString(unescaped_length); 4988 isolate->heap()->AllocateRawAsciiString(unescaped_length) :
4989 isolate->heap()->AllocateRawTwoByteString(unescaped_length);
4771 if (!maybe_o->ToObject(&o)) return maybe_o; 4990 if (!maybe_o->ToObject(&o)) return maybe_o;
4772 } 4991 }
4773 String* destination = String::cast(o); 4992 String* destination = String::cast(o);
4774 4993
4775 int dest_position = 0; 4994 int dest_position = 0;
4776 for (int i = 0; i < length; dest_position++) { 4995 for (int i = 0; i < length; dest_position++) {
4777 int step; 4996 int step;
4778 destination->Set(dest_position, Unescape(source, i, length, &step)); 4997 destination->Set(dest_position, Unescape(source, i, length, &step));
4779 i += step; 4998 i += step;
4780 } 4999 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
4850 1, 1, 1, 1, 1, 1, 1, 1, 5069 1, 1, 1, 1, 1, 1, 1, 1,
4851 }; 5070 };
4852 5071
4853 5072
4854 template <typename StringType> 5073 template <typename StringType>
4855 MaybeObject* AllocateRawString(int length); 5074 MaybeObject* AllocateRawString(int length);
4856 5075
4857 5076
4858 template <> 5077 template <>
4859 MaybeObject* AllocateRawString<SeqTwoByteString>(int length) { 5078 MaybeObject* AllocateRawString<SeqTwoByteString>(int length) {
4860 return Heap::AllocateRawTwoByteString(length); 5079 return HEAP->AllocateRawTwoByteString(length);
4861 } 5080 }
4862 5081
4863 5082
4864 template <> 5083 template <>
4865 MaybeObject* AllocateRawString<SeqAsciiString>(int length) { 5084 MaybeObject* AllocateRawString<SeqAsciiString>(int length) {
4866 return Heap::AllocateRawAsciiString(length); 5085 return HEAP->AllocateRawAsciiString(length);
4867 } 5086 }
4868 5087
4869 5088
4870 template <typename Char, typename StringType, bool comma> 5089 template <typename Char, typename StringType, bool comma>
4871 static MaybeObject* SlowQuoteJsonString(Vector<const Char> characters) { 5090 static MaybeObject* SlowQuoteJsonString(Vector<const Char> characters) {
4872 int length = characters.length(); 5091 int length = characters.length();
4873 const Char* read_cursor = characters.start(); 5092 const Char* read_cursor = characters.start();
4874 const Char* end = read_cursor + length; 5093 const Char* end = read_cursor + length;
4875 const int kSpaceForQuotes = 2 + (comma ? 1 :0); 5094 const int kSpaceForQuotes = 2 + (comma ? 1 :0);
4876 int quoted_length = kSpaceForQuotes; 5095 int quoted_length = kSpaceForQuotes;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4909 } 5128 }
4910 } 5129 }
4911 *(write_cursor++) = '"'; 5130 *(write_cursor++) = '"';
4912 return new_string; 5131 return new_string;
4913 } 5132 }
4914 5133
4915 5134
4916 template <typename Char, typename StringType, bool comma> 5135 template <typename Char, typename StringType, bool comma>
4917 static MaybeObject* QuoteJsonString(Vector<const Char> characters) { 5136 static MaybeObject* QuoteJsonString(Vector<const Char> characters) {
4918 int length = characters.length(); 5137 int length = characters.length();
4919 Counters::quote_json_char_count.Increment(length); 5138 COUNTERS->quote_json_char_count()->Increment(length);
4920 const int kSpaceForQuotes = 2 + (comma ? 1 :0); 5139 const int kSpaceForQuotes = 2 + (comma ? 1 :0);
4921 int worst_case_length = length * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; 5140 int worst_case_length = length * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes;
4922 if (worst_case_length > kMaxGuaranteedNewSpaceString) { 5141 if (worst_case_length > kMaxGuaranteedNewSpaceString) {
4923 return SlowQuoteJsonString<Char, StringType, comma>(characters); 5142 return SlowQuoteJsonString<Char, StringType, comma>(characters);
4924 } 5143 }
4925 5144
4926 MaybeObject* new_alloc = AllocateRawString<StringType>(worst_case_length); 5145 MaybeObject* new_alloc = AllocateRawString<StringType>(worst_case_length);
4927 Object* new_object; 5146 Object* new_object;
4928 if (!new_alloc->ToObject(&new_object)) { 5147 if (!new_alloc->ToObject(&new_object)) {
4929 return new_alloc; 5148 return new_alloc;
4930 } 5149 }
4931 if (!Heap::new_space()->Contains(new_object)) { 5150 if (!HEAP->new_space()->Contains(new_object)) {
4932 // Even if our string is small enough to fit in new space we still have to 5151 // Even if our string is small enough to fit in new space we still have to
4933 // handle it being allocated in old space as may happen in the third 5152 // handle it being allocated in old space as may happen in the third
4934 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in 5153 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in
4935 // CEntryStub::GenerateCore. 5154 // CEntryStub::GenerateCore.
4936 return SlowQuoteJsonString<Char, StringType, comma>(characters); 5155 return SlowQuoteJsonString<Char, StringType, comma>(characters);
4937 } 5156 }
4938 StringType* new_string = StringType::cast(new_object); 5157 StringType* new_string = StringType::cast(new_object);
4939 ASSERT(Heap::new_space()->Contains(new_string)); 5158 ASSERT(HEAP->new_space()->Contains(new_string));
4940 5159
4941 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); 5160 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize);
4942 Char* write_cursor = reinterpret_cast<Char*>( 5161 Char* write_cursor = reinterpret_cast<Char*>(
4943 new_string->address() + SeqAsciiString::kHeaderSize); 5162 new_string->address() + SeqAsciiString::kHeaderSize);
4944 if (comma) *(write_cursor++) = ','; 5163 if (comma) *(write_cursor++) = ',';
4945 *(write_cursor++) = '"'; 5164 *(write_cursor++) = '"';
4946 5165
4947 const Char* read_cursor = characters.start(); 5166 const Char* read_cursor = characters.start();
4948 const Char* end = read_cursor + length; 5167 const Char* end = read_cursor + length;
4949 while (read_cursor < end) { 5168 while (read_cursor < end) {
(...skipping 16 matching lines...) Expand all
4966 } 5185 }
4967 } 5186 }
4968 write_cursor += len; 5187 write_cursor += len;
4969 } 5188 }
4970 } 5189 }
4971 *(write_cursor++) = '"'; 5190 *(write_cursor++) = '"';
4972 5191
4973 int final_length = static_cast<int>( 5192 int final_length = static_cast<int>(
4974 write_cursor - reinterpret_cast<Char*>( 5193 write_cursor - reinterpret_cast<Char*>(
4975 new_string->address() + SeqAsciiString::kHeaderSize)); 5194 new_string->address() + SeqAsciiString::kHeaderSize));
4976 Heap::new_space()->ShrinkStringAtAllocationBoundary<StringType>(new_string, 5195 HEAP->new_space()->ShrinkStringAtAllocationBoundary<StringType>(new_string,
4977 final_length); 5196 final_length);
4978 return new_string; 5197 return new_string;
4979 } 5198 }
4980 5199
4981 5200
4982 static MaybeObject* Runtime_QuoteJSONString(Arguments args) { 5201 static MaybeObject* Runtime_QuoteJSONString(RUNTIME_CALLING_CONVENTION) {
5202 RUNTIME_GET_ISOLATE;
4983 NoHandleAllocation ha; 5203 NoHandleAllocation ha;
4984 CONVERT_CHECKED(String, str, args[0]); 5204 CONVERT_CHECKED(String, str, args[0]);
4985 if (!str->IsFlat()) { 5205 if (!str->IsFlat()) {
4986 MaybeObject* try_flatten = str->TryFlatten(); 5206 MaybeObject* try_flatten = str->TryFlatten();
4987 Object* flat; 5207 Object* flat;
4988 if (!try_flatten->ToObject(&flat)) { 5208 if (!try_flatten->ToObject(&flat)) {
4989 return try_flatten; 5209 return try_flatten;
4990 } 5210 }
4991 str = String::cast(flat); 5211 str = String::cast(flat);
4992 ASSERT(str->IsFlat()); 5212 ASSERT(str->IsFlat());
4993 } 5213 }
4994 if (str->IsTwoByteRepresentation()) { 5214 if (str->IsTwoByteRepresentation()) {
4995 return QuoteJsonString<uc16, SeqTwoByteString, false>(str->ToUC16Vector()); 5215 return QuoteJsonString<uc16, SeqTwoByteString, false>(str->ToUC16Vector());
4996 } else { 5216 } else {
4997 return QuoteJsonString<char, SeqAsciiString, false>(str->ToAsciiVector()); 5217 return QuoteJsonString<char, SeqAsciiString, false>(str->ToAsciiVector());
4998 } 5218 }
4999 } 5219 }
5000 5220
5001 5221
5002 static MaybeObject* Runtime_QuoteJSONStringComma(Arguments args) { 5222 static MaybeObject* Runtime_QuoteJSONStringComma(RUNTIME_CALLING_CONVENTION) {
5223 RUNTIME_GET_ISOLATE;
5003 NoHandleAllocation ha; 5224 NoHandleAllocation ha;
5004 CONVERT_CHECKED(String, str, args[0]); 5225 CONVERT_CHECKED(String, str, args[0]);
5005 if (!str->IsFlat()) { 5226 if (!str->IsFlat()) {
5006 MaybeObject* try_flatten = str->TryFlatten(); 5227 MaybeObject* try_flatten = str->TryFlatten();
5007 Object* flat; 5228 Object* flat;
5008 if (!try_flatten->ToObject(&flat)) { 5229 if (!try_flatten->ToObject(&flat)) {
5009 return try_flatten; 5230 return try_flatten;
5010 } 5231 }
5011 str = String::cast(flat); 5232 str = String::cast(flat);
5012 ASSERT(str->IsFlat()); 5233 ASSERT(str->IsFlat());
5013 } 5234 }
5014 if (str->IsTwoByteRepresentation()) { 5235 if (str->IsTwoByteRepresentation()) {
5015 return QuoteJsonString<uc16, SeqTwoByteString, true>(str->ToUC16Vector()); 5236 return QuoteJsonString<uc16, SeqTwoByteString, true>(str->ToUC16Vector());
5016 } else { 5237 } else {
5017 return QuoteJsonString<char, SeqAsciiString, true>(str->ToAsciiVector()); 5238 return QuoteJsonString<char, SeqAsciiString, true>(str->ToAsciiVector());
5018 } 5239 }
5019 } 5240 }
5020 5241
5021 5242 static MaybeObject* Runtime_StringParseInt(RUNTIME_CALLING_CONVENTION) {
5022 static MaybeObject* Runtime_StringParseInt(Arguments args) { 5243 RUNTIME_GET_ISOLATE;
5023 NoHandleAllocation ha; 5244 NoHandleAllocation ha;
5024 5245
5025 CONVERT_CHECKED(String, s, args[0]); 5246 CONVERT_CHECKED(String, s, args[0]);
5026 CONVERT_SMI_CHECKED(radix, args[1]); 5247 CONVERT_SMI_CHECKED(radix, args[1]);
5027 5248
5028 s->TryFlatten(); 5249 s->TryFlatten();
5029 5250
5030 RUNTIME_ASSERT(radix == 0 || (2 <= radix && radix <= 36)); 5251 RUNTIME_ASSERT(radix == 0 || (2 <= radix && radix <= 36));
5031 double value = StringToInt(s, radix); 5252 double value = StringToInt(s, radix);
5032 return Heap::NumberFromDouble(value); 5253 return isolate->heap()->NumberFromDouble(value);
5033 } 5254 }
5034 5255
5035 5256
5036 static MaybeObject* Runtime_StringParseFloat(Arguments args) { 5257 static MaybeObject* Runtime_StringParseFloat(RUNTIME_CALLING_CONVENTION) {
5258 RUNTIME_GET_ISOLATE;
5037 NoHandleAllocation ha; 5259 NoHandleAllocation ha;
5038 CONVERT_CHECKED(String, str, args[0]); 5260 CONVERT_CHECKED(String, str, args[0]);
5039 5261
5040 // ECMA-262 section 15.1.2.3, empty string is NaN 5262 // ECMA-262 section 15.1.2.3, empty string is NaN
5041 double value = StringToDouble(str, ALLOW_TRAILING_JUNK, OS::nan_value()); 5263 double value = StringToDouble(str, ALLOW_TRAILING_JUNK, OS::nan_value());
5042 5264
5043 // Create a number object from the value. 5265 // Create a number object from the value.
5044 return Heap::NumberFromDouble(value); 5266 return isolate->heap()->NumberFromDouble(value);
5045 } 5267 }
5046 5268
5047 5269
5048 static unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping;
5049 static unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping;
5050
5051
5052 template <class Converter> 5270 template <class Converter>
5053 MUST_USE_RESULT static MaybeObject* ConvertCaseHelper( 5271 MUST_USE_RESULT static MaybeObject* ConvertCaseHelper(
5272 Isolate* isolate,
5054 String* s, 5273 String* s,
5055 int length, 5274 int length,
5056 int input_string_length, 5275 int input_string_length,
5057 unibrow::Mapping<Converter, 128>* mapping) { 5276 unibrow::Mapping<Converter, 128>* mapping) {
5058 // We try this twice, once with the assumption that the result is no longer 5277 // We try this twice, once with the assumption that the result is no longer
5059 // than the input and, if that assumption breaks, again with the exact 5278 // than the input and, if that assumption breaks, again with the exact
5060 // length. This may not be pretty, but it is nicer than what was here before 5279 // length. This may not be pretty, but it is nicer than what was here before
5061 // and I hereby claim my vaffel-is. 5280 // and I hereby claim my vaffel-is.
5062 // 5281 //
5063 // Allocate the resulting string. 5282 // Allocate the resulting string.
5064 // 5283 //
5065 // NOTE: This assumes that the upper/lower case of an ascii 5284 // NOTE: This assumes that the upper/lower case of an ascii
5066 // character is also ascii. This is currently the case, but it 5285 // character is also ascii. This is currently the case, but it
5067 // might break in the future if we implement more context and locale 5286 // might break in the future if we implement more context and locale
5068 // dependent upper/lower conversions. 5287 // dependent upper/lower conversions.
5069 Object* o; 5288 Object* o;
5070 { MaybeObject* maybe_o = s->IsAsciiRepresentation() 5289 { MaybeObject* maybe_o = s->IsAsciiRepresentation()
5071 ? Heap::AllocateRawAsciiString(length) 5290 ? isolate->heap()->AllocateRawAsciiString(length)
5072 : Heap::AllocateRawTwoByteString(length); 5291 : isolate->heap()->AllocateRawTwoByteString(length);
5073 if (!maybe_o->ToObject(&o)) return maybe_o; 5292 if (!maybe_o->ToObject(&o)) return maybe_o;
5074 } 5293 }
5075 String* result = String::cast(o); 5294 String* result = String::cast(o);
5076 bool has_changed_character = false; 5295 bool has_changed_character = false;
5077 5296
5078 // Convert all characters to upper case, assuming that they will fit 5297 // Convert all characters to upper case, assuming that they will fit
5079 // in the buffer 5298 // in the buffer
5080 Access<StringInputBuffer> buffer(&runtime_string_input_buffer); 5299 Access<StringInputBuffer> buffer(
5300 isolate->runtime_state()->string_input_buffer());
5081 buffer->Reset(s); 5301 buffer->Reset(s);
5082 unibrow::uchar chars[Converter::kMaxWidth]; 5302 unibrow::uchar chars[Converter::kMaxWidth];
5083 // We can assume that the string is not empty 5303 // We can assume that the string is not empty
5084 uc32 current = buffer->GetNext(); 5304 uc32 current = buffer->GetNext();
5085 for (int i = 0; i < length;) { 5305 for (int i = 0; i < length;) {
5086 bool has_next = buffer->has_more(); 5306 bool has_next = buffer->has_more();
5087 uc32 next = has_next ? buffer->GetNext() : 0; 5307 uc32 next = has_next ? buffer->GetNext() : 0;
5088 int char_length = mapping->get(current, next, chars); 5308 int char_length = mapping->get(current, next, chars);
5089 if (char_length == 0) { 5309 if (char_length == 0) {
5090 // The case conversion of this character is the character itself. 5310 // The case conversion of this character is the character itself.
(...skipping 26 matching lines...) Expand all
5117 while (buffer->has_more()) { 5337 while (buffer->has_more()) {
5118 current = buffer->GetNext(); 5338 current = buffer->GetNext();
5119 // NOTE: we use 0 as the next character here because, while 5339 // NOTE: we use 0 as the next character here because, while
5120 // the next character may affect what a character converts to, 5340 // the next character may affect what a character converts to,
5121 // it does not in any case affect the length of what it convert 5341 // it does not in any case affect the length of what it convert
5122 // to. 5342 // to.
5123 int char_length = mapping->get(current, 0, chars); 5343 int char_length = mapping->get(current, 0, chars);
5124 if (char_length == 0) char_length = 1; 5344 if (char_length == 0) char_length = 1;
5125 current_length += char_length; 5345 current_length += char_length;
5126 if (current_length > Smi::kMaxValue) { 5346 if (current_length > Smi::kMaxValue) {
5127 Top::context()->mark_out_of_memory(); 5347 isolate->context()->mark_out_of_memory();
5128 return Failure::OutOfMemoryException(); 5348 return Failure::OutOfMemoryException();
5129 } 5349 }
5130 } 5350 }
5131 // Try again with the real length. 5351 // Try again with the real length.
5132 return Smi::FromInt(current_length); 5352 return Smi::FromInt(current_length);
5133 } else { 5353 } else {
5134 for (int j = 0; j < char_length; j++) { 5354 for (int j = 0; j < char_length; j++) {
5135 result->Set(i, chars[j]); 5355 result->Set(i, chars[j]);
5136 i++; 5356 i++;
5137 } 5357 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
5275 5495
5276 typedef FastAsciiConverter<ASCII_TO_UPPER> AsciiConverter; 5496 typedef FastAsciiConverter<ASCII_TO_UPPER> AsciiConverter;
5277 }; 5497 };
5278 5498
5279 } // namespace 5499 } // namespace
5280 5500
5281 5501
5282 template <typename ConvertTraits> 5502 template <typename ConvertTraits>
5283 MUST_USE_RESULT static MaybeObject* ConvertCase( 5503 MUST_USE_RESULT static MaybeObject* ConvertCase(
5284 Arguments args, 5504 Arguments args,
5505 Isolate* isolate,
5285 unibrow::Mapping<typename ConvertTraits::UnibrowConverter, 128>* mapping) { 5506 unibrow::Mapping<typename ConvertTraits::UnibrowConverter, 128>* mapping) {
5286 NoHandleAllocation ha; 5507 NoHandleAllocation ha;
5287 CONVERT_CHECKED(String, s, args[0]); 5508 CONVERT_CHECKED(String, s, args[0]);
5288 s = s->TryFlattenGetString(); 5509 s = s->TryFlattenGetString();
5289 5510
5290 const int length = s->length(); 5511 const int length = s->length();
5291 // Assume that the string is not empty; we need this assumption later 5512 // Assume that the string is not empty; we need this assumption later
5292 if (length == 0) return s; 5513 if (length == 0) return s;
5293 5514
5294 // Simpler handling of ascii strings. 5515 // Simpler handling of ascii strings.
5295 // 5516 //
5296 // NOTE: This assumes that the upper/lower case of an ascii 5517 // NOTE: This assumes that the upper/lower case of an ascii
5297 // character is also ascii. This is currently the case, but it 5518 // character is also ascii. This is currently the case, but it
5298 // might break in the future if we implement more context and locale 5519 // might break in the future if we implement more context and locale
5299 // dependent upper/lower conversions. 5520 // dependent upper/lower conversions.
5300 if (s->IsSeqAsciiString()) { 5521 if (s->IsSeqAsciiString()) {
5301 Object* o; 5522 Object* o;
5302 { MaybeObject* maybe_o = Heap::AllocateRawAsciiString(length); 5523 { MaybeObject* maybe_o = isolate->heap()->AllocateRawAsciiString(length);
5303 if (!maybe_o->ToObject(&o)) return maybe_o; 5524 if (!maybe_o->ToObject(&o)) return maybe_o;
5304 } 5525 }
5305 SeqAsciiString* result = SeqAsciiString::cast(o); 5526 SeqAsciiString* result = SeqAsciiString::cast(o);
5306 bool has_changed_character = ConvertTraits::AsciiConverter::Convert( 5527 bool has_changed_character = ConvertTraits::AsciiConverter::Convert(
5307 result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length); 5528 result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length);
5308 return has_changed_character ? result : s; 5529 return has_changed_character ? result : s;
5309 } 5530 }
5310 5531
5311 Object* answer; 5532 Object* answer;
5312 { MaybeObject* maybe_answer = ConvertCaseHelper(s, length, length, mapping); 5533 { MaybeObject* maybe_answer =
5534 ConvertCaseHelper(isolate, s, length, length, mapping);
5313 if (!maybe_answer->ToObject(&answer)) return maybe_answer; 5535 if (!maybe_answer->ToObject(&answer)) return maybe_answer;
5314 } 5536 }
5315 if (answer->IsSmi()) { 5537 if (answer->IsSmi()) {
5316 // Retry with correct length. 5538 // Retry with correct length.
5317 { MaybeObject* maybe_answer = 5539 { MaybeObject* maybe_answer =
5318 ConvertCaseHelper(s, Smi::cast(answer)->value(), length, mapping); 5540 ConvertCaseHelper(isolate,
5541 s, Smi::cast(answer)->value(), length, mapping);
5319 if (!maybe_answer->ToObject(&answer)) return maybe_answer; 5542 if (!maybe_answer->ToObject(&answer)) return maybe_answer;
5320 } 5543 }
5321 } 5544 }
5322 return answer; 5545 return answer;
5323 } 5546 }
5324 5547
5325 5548
5326 static MaybeObject* Runtime_StringToLowerCase(Arguments args) { 5549 static MaybeObject* Runtime_StringToLowerCase(RUNTIME_CALLING_CONVENTION) {
5327 return ConvertCase<ToLowerTraits>(args, &to_lower_mapping); 5550 RUNTIME_GET_ISOLATE;
5551 return ConvertCase<ToLowerTraits>(
5552 args, isolate, isolate->runtime_state()->to_lower_mapping());
5328 } 5553 }
5329 5554
5330 5555
5331 static MaybeObject* Runtime_StringToUpperCase(Arguments args) { 5556 static MaybeObject* Runtime_StringToUpperCase(RUNTIME_CALLING_CONVENTION) {
5332 return ConvertCase<ToUpperTraits>(args, &to_upper_mapping); 5557 RUNTIME_GET_ISOLATE;
5558 return ConvertCase<ToUpperTraits>(
5559 args, isolate, isolate->runtime_state()->to_upper_mapping());
5333 } 5560 }
5334 5561
5335 5562
5336 static inline bool IsTrimWhiteSpace(unibrow::uchar c) { 5563 static inline bool IsTrimWhiteSpace(unibrow::uchar c) {
5337 return unibrow::WhiteSpace::Is(c) || c == 0x200b; 5564 return unibrow::WhiteSpace::Is(c) || c == 0x200b;
5338 } 5565 }
5339 5566
5340 5567
5341 static MaybeObject* Runtime_StringTrim(Arguments args) { 5568 static MaybeObject* Runtime_StringTrim(RUNTIME_CALLING_CONVENTION) {
5569 RUNTIME_GET_ISOLATE;
5342 NoHandleAllocation ha; 5570 NoHandleAllocation ha;
5343 ASSERT(args.length() == 3); 5571 ASSERT(args.length() == 3);
5344 5572
5345 CONVERT_CHECKED(String, s, args[0]); 5573 CONVERT_CHECKED(String, s, args[0]);
5346 CONVERT_BOOLEAN_CHECKED(trimLeft, args[1]); 5574 CONVERT_BOOLEAN_CHECKED(trimLeft, args[1]);
5347 CONVERT_BOOLEAN_CHECKED(trimRight, args[2]); 5575 CONVERT_BOOLEAN_CHECKED(trimRight, args[2]);
5348 5576
5349 s->TryFlatten(); 5577 s->TryFlatten();
5350 int length = s->length(); 5578 int length = s->length();
5351 5579
5352 int left = 0; 5580 int left = 0;
5353 if (trimLeft) { 5581 if (trimLeft) {
5354 while (left < length && IsTrimWhiteSpace(s->Get(left))) { 5582 while (left < length && IsTrimWhiteSpace(s->Get(left))) {
5355 left++; 5583 left++;
5356 } 5584 }
5357 } 5585 }
5358 5586
5359 int right = length; 5587 int right = length;
5360 if (trimRight) { 5588 if (trimRight) {
5361 while (right > left && IsTrimWhiteSpace(s->Get(right - 1))) { 5589 while (right > left && IsTrimWhiteSpace(s->Get(right - 1))) {
5362 right--; 5590 right--;
5363 } 5591 }
5364 } 5592 }
5365 return s->SubString(left, right); 5593 return s->SubString(left, right);
5366 } 5594 }
5367 5595
5368 5596
5369 template <typename SubjectChar, typename PatternChar> 5597 template <typename SubjectChar, typename PatternChar>
5370 void FindStringIndices(Vector<const SubjectChar> subject, 5598 void FindStringIndices(Isolate* isolate,
5599 Vector<const SubjectChar> subject,
5371 Vector<const PatternChar> pattern, 5600 Vector<const PatternChar> pattern,
5372 ZoneList<int>* indices, 5601 ZoneList<int>* indices,
5373 unsigned int limit) { 5602 unsigned int limit) {
5374 ASSERT(limit > 0); 5603 ASSERT(limit > 0);
5375 // Collect indices of pattern in subject, and the end-of-string index. 5604 // Collect indices of pattern in subject, and the end-of-string index.
5376 // Stop after finding at most limit values. 5605 // Stop after finding at most limit values.
5377 StringSearch<PatternChar, SubjectChar> search(pattern); 5606 StringSearch<PatternChar, SubjectChar> search(isolate, pattern);
5378 int pattern_length = pattern.length(); 5607 int pattern_length = pattern.length();
5379 int index = 0; 5608 int index = 0;
5380 while (limit > 0) { 5609 while (limit > 0) {
5381 index = search.Search(subject, index); 5610 index = search.Search(subject, index);
5382 if (index < 0) return; 5611 if (index < 0) return;
5383 indices->Add(index); 5612 indices->Add(index);
5384 index += pattern_length; 5613 index += pattern_length;
5385 limit--; 5614 limit--;
5386 } 5615 }
5387 } 5616 }
5388 5617
5389 5618
5390 static MaybeObject* Runtime_StringSplit(Arguments args) { 5619 static MaybeObject* Runtime_StringSplit(RUNTIME_CALLING_CONVENTION) {
5620 RUNTIME_GET_ISOLATE;
5391 ASSERT(args.length() == 3); 5621 ASSERT(args.length() == 3);
5392 HandleScope handle_scope; 5622 HandleScope handle_scope(isolate);
5393 CONVERT_ARG_CHECKED(String, subject, 0); 5623 CONVERT_ARG_CHECKED(String, subject, 0);
5394 CONVERT_ARG_CHECKED(String, pattern, 1); 5624 CONVERT_ARG_CHECKED(String, pattern, 1);
5395 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); 5625 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
5396 5626
5397 int subject_length = subject->length(); 5627 int subject_length = subject->length();
5398 int pattern_length = pattern->length(); 5628 int pattern_length = pattern->length();
5399 RUNTIME_ASSERT(pattern_length > 0); 5629 RUNTIME_ASSERT(pattern_length > 0);
5400 5630
5401 // The limit can be very large (0xffffffffu), but since the pattern 5631 // The limit can be very large (0xffffffffu), but since the pattern
5402 // isn't empty, we can never create more parts than ~half the length 5632 // isn't empty, we can never create more parts than ~half the length
5403 // of the subject. 5633 // of the subject.
5404 5634
5405 if (!subject->IsFlat()) FlattenString(subject); 5635 if (!subject->IsFlat()) FlattenString(subject);
5406 5636
5407 static const int kMaxInitialListCapacity = 16; 5637 static const int kMaxInitialListCapacity = 16;
5408 5638
5409 ZoneScope scope(DELETE_ON_EXIT); 5639 ZoneScope scope(DELETE_ON_EXIT);
5410 5640
5411 // Find (up to limit) indices of separator and end-of-string in subject 5641 // Find (up to limit) indices of separator and end-of-string in subject
5412 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); 5642 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit);
5413 ZoneList<int> indices(initial_capacity); 5643 ZoneList<int> indices(initial_capacity);
5414 if (!pattern->IsFlat()) FlattenString(pattern); 5644 if (!pattern->IsFlat()) FlattenString(pattern);
5415 5645
5416 // No allocation block. 5646 // No allocation block.
5417 { 5647 {
5418 AssertNoAllocation nogc; 5648 AssertNoAllocation nogc;
5419 if (subject->IsAsciiRepresentation()) { 5649 if (subject->IsAsciiRepresentation()) {
5420 Vector<const char> subject_vector = subject->ToAsciiVector(); 5650 Vector<const char> subject_vector = subject->ToAsciiVector();
5421 if (pattern->IsAsciiRepresentation()) { 5651 if (pattern->IsAsciiRepresentation()) {
5422 FindStringIndices(subject_vector, 5652 FindStringIndices(isolate,
5653 subject_vector,
5423 pattern->ToAsciiVector(), 5654 pattern->ToAsciiVector(),
5424 &indices, 5655 &indices,
5425 limit); 5656 limit);
5426 } else { 5657 } else {
5427 FindStringIndices(subject_vector, 5658 FindStringIndices(isolate,
5659 subject_vector,
5428 pattern->ToUC16Vector(), 5660 pattern->ToUC16Vector(),
5429 &indices, 5661 &indices,
5430 limit); 5662 limit);
5431 } 5663 }
5432 } else { 5664 } else {
5433 Vector<const uc16> subject_vector = subject->ToUC16Vector(); 5665 Vector<const uc16> subject_vector = subject->ToUC16Vector();
5434 if (pattern->IsAsciiRepresentation()) { 5666 if (pattern->IsAsciiRepresentation()) {
5435 FindStringIndices(subject_vector, 5667 FindStringIndices(isolate,
5668 subject_vector,
5436 pattern->ToAsciiVector(), 5669 pattern->ToAsciiVector(),
5437 &indices, 5670 &indices,
5438 limit); 5671 limit);
5439 } else { 5672 } else {
5440 FindStringIndices(subject_vector, 5673 FindStringIndices(isolate,
5674 subject_vector,
5441 pattern->ToUC16Vector(), 5675 pattern->ToUC16Vector(),
5442 &indices, 5676 &indices,
5443 limit); 5677 limit);
5444 } 5678 }
5445 } 5679 }
5446 } 5680 }
5447 5681
5448 if (static_cast<uint32_t>(indices.length()) < limit) { 5682 if (static_cast<uint32_t>(indices.length()) < limit) {
5449 indices.Add(subject_length); 5683 indices.Add(subject_length);
5450 } 5684 }
5451 5685
5452 // The list indices now contains the end of each part to create. 5686 // The list indices now contains the end of each part to create.
5453 5687
5454 // Create JSArray of substrings separated by separator. 5688 // Create JSArray of substrings separated by separator.
5455 int part_count = indices.length(); 5689 int part_count = indices.length();
5456 5690
5457 Handle<JSArray> result = Factory::NewJSArray(part_count); 5691 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count);
5458 result->set_length(Smi::FromInt(part_count)); 5692 result->set_length(Smi::FromInt(part_count));
5459 5693
5460 ASSERT(result->HasFastElements()); 5694 ASSERT(result->HasFastElements());
5461 5695
5462 if (part_count == 1 && indices.at(0) == subject_length) { 5696 if (part_count == 1 && indices.at(0) == subject_length) {
5463 FixedArray::cast(result->elements())->set(0, *subject); 5697 FixedArray::cast(result->elements())->set(0, *subject);
5464 return *result; 5698 return *result;
5465 } 5699 }
5466 5700
5467 Handle<FixedArray> elements(FixedArray::cast(result->elements())); 5701 Handle<FixedArray> elements(FixedArray::cast(result->elements()));
5468 int part_start = 0; 5702 int part_start = 0;
5469 for (int i = 0; i < part_count; i++) { 5703 for (int i = 0; i < part_count; i++) {
5470 HandleScope local_loop_handle; 5704 HandleScope local_loop_handle;
5471 int part_end = indices.at(i); 5705 int part_end = indices.at(i);
5472 Handle<String> substring = 5706 Handle<String> substring =
5473 Factory::NewSubString(subject, part_start, part_end); 5707 isolate->factory()->NewSubString(subject, part_start, part_end);
5474 elements->set(i, *substring); 5708 elements->set(i, *substring);
5475 part_start = part_end + pattern_length; 5709 part_start = part_end + pattern_length;
5476 } 5710 }
5477 5711
5478 return *result; 5712 return *result;
5479 } 5713 }
5480 5714
5481 5715
5482 // Copies ascii characters to the given fixed array looking up 5716 // Copies ascii characters to the given fixed array looking up
5483 // one-char strings in the cache. Gives up on the first char that is 5717 // one-char strings in the cache. Gives up on the first char that is
5484 // not in the cache and fills the remainder with smi zeros. Returns 5718 // not in the cache and fills the remainder with smi zeros. Returns
5485 // the length of the successfully copied prefix. 5719 // the length of the successfully copied prefix.
5486 static int CopyCachedAsciiCharsToArray(const char* chars, 5720 static int CopyCachedAsciiCharsToArray(Heap* heap,
5721 const char* chars,
5487 FixedArray* elements, 5722 FixedArray* elements,
5488 int length) { 5723 int length) {
5489 AssertNoAllocation nogc; 5724 AssertNoAllocation nogc;
5490 FixedArray* ascii_cache = Heap::single_character_string_cache(); 5725 FixedArray* ascii_cache = heap->single_character_string_cache();
5491 Object* undefined = Heap::undefined_value(); 5726 Object* undefined = heap->undefined_value();
5492 int i; 5727 int i;
5493 for (i = 0; i < length; ++i) { 5728 for (i = 0; i < length; ++i) {
5494 Object* value = ascii_cache->get(chars[i]); 5729 Object* value = ascii_cache->get(chars[i]);
5495 if (value == undefined) break; 5730 if (value == undefined) break;
5496 ASSERT(!Heap::InNewSpace(value)); 5731 ASSERT(!heap->InNewSpace(value));
5497 elements->set(i, value, SKIP_WRITE_BARRIER); 5732 elements->set(i, value, SKIP_WRITE_BARRIER);
5498 } 5733 }
5499 if (i < length) { 5734 if (i < length) {
5500 ASSERT(Smi::FromInt(0) == 0); 5735 ASSERT(Smi::FromInt(0) == 0);
5501 memset(elements->data_start() + i, 0, kPointerSize * (length - i)); 5736 memset(elements->data_start() + i, 0, kPointerSize * (length - i));
5502 } 5737 }
5503 #ifdef DEBUG 5738 #ifdef DEBUG
5504 for (int j = 0; j < length; ++j) { 5739 for (int j = 0; j < length; ++j) {
5505 Object* element = elements->get(j); 5740 Object* element = elements->get(j);
5506 ASSERT(element == Smi::FromInt(0) || 5741 ASSERT(element == Smi::FromInt(0) ||
5507 (element->IsString() && String::cast(element)->LooksValid())); 5742 (element->IsString() && String::cast(element)->LooksValid()));
5508 } 5743 }
5509 #endif 5744 #endif
5510 return i; 5745 return i;
5511 } 5746 }
5512 5747
5513 5748
5514 // Converts a String to JSArray. 5749 // Converts a String to JSArray.
5515 // For example, "foo" => ["f", "o", "o"]. 5750 // For example, "foo" => ["f", "o", "o"].
5516 static MaybeObject* Runtime_StringToArray(Arguments args) { 5751 static MaybeObject* Runtime_StringToArray(RUNTIME_CALLING_CONVENTION) {
5517 HandleScope scope; 5752 RUNTIME_GET_ISOLATE;
5753 HandleScope scope(isolate);
5518 ASSERT(args.length() == 2); 5754 ASSERT(args.length() == 2);
5519 CONVERT_ARG_CHECKED(String, s, 0); 5755 CONVERT_ARG_CHECKED(String, s, 0);
5520 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); 5756 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]);
5521 5757
5522 s->TryFlatten(); 5758 s->TryFlatten();
5523 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); 5759 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit));
5524 5760
5525 Handle<FixedArray> elements; 5761 Handle<FixedArray> elements;
5526 if (s->IsFlat() && s->IsAsciiRepresentation()) { 5762 if (s->IsFlat() && s->IsAsciiRepresentation()) {
5527 Object* obj; 5763 Object* obj;
5528 { MaybeObject* maybe_obj = Heap::AllocateUninitializedFixedArray(length); 5764 { MaybeObject* maybe_obj =
5765 isolate->heap()->AllocateUninitializedFixedArray(length);
5529 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 5766 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
5530 } 5767 }
5531 elements = Handle<FixedArray>(FixedArray::cast(obj)); 5768 elements = Handle<FixedArray>(FixedArray::cast(obj), isolate);
5532 5769
5533 Vector<const char> chars = s->ToAsciiVector(); 5770 Vector<const char> chars = s->ToAsciiVector();
5534 // Note, this will initialize all elements (not only the prefix) 5771 // Note, this will initialize all elements (not only the prefix)
5535 // to prevent GC from seeing partially initialized array. 5772 // to prevent GC from seeing partially initialized array.
5536 int num_copied_from_cache = CopyCachedAsciiCharsToArray(chars.start(), 5773 int num_copied_from_cache = CopyCachedAsciiCharsToArray(isolate->heap(),
5774 chars.start(),
5537 *elements, 5775 *elements,
5538 length); 5776 length);
5539 5777
5540 for (int i = num_copied_from_cache; i < length; ++i) { 5778 for (int i = num_copied_from_cache; i < length; ++i) {
5541 Handle<Object> str = LookupSingleCharacterStringFromCode(chars[i]); 5779 Handle<Object> str = LookupSingleCharacterStringFromCode(chars[i]);
5542 elements->set(i, *str); 5780 elements->set(i, *str);
5543 } 5781 }
5544 } else { 5782 } else {
5545 elements = Factory::NewFixedArray(length); 5783 elements = isolate->factory()->NewFixedArray(length);
5546 for (int i = 0; i < length; ++i) { 5784 for (int i = 0; i < length; ++i) {
5547 Handle<Object> str = LookupSingleCharacterStringFromCode(s->Get(i)); 5785 Handle<Object> str = LookupSingleCharacterStringFromCode(s->Get(i));
5548 elements->set(i, *str); 5786 elements->set(i, *str);
5549 } 5787 }
5550 } 5788 }
5551 5789
5552 #ifdef DEBUG 5790 #ifdef DEBUG
5553 for (int i = 0; i < length; ++i) { 5791 for (int i = 0; i < length; ++i) {
5554 ASSERT(String::cast(elements->get(i))->length() == 1); 5792 ASSERT(String::cast(elements->get(i))->length() == 1);
5555 } 5793 }
5556 #endif 5794 #endif
5557 5795
5558 return *Factory::NewJSArrayWithElements(elements); 5796 return *isolate->factory()->NewJSArrayWithElements(elements);
5559 } 5797 }
5560 5798
5561 5799
5562 static MaybeObject* Runtime_NewStringWrapper(Arguments args) { 5800 static MaybeObject* Runtime_NewStringWrapper(RUNTIME_CALLING_CONVENTION) {
5801 RUNTIME_GET_ISOLATE;
5563 NoHandleAllocation ha; 5802 NoHandleAllocation ha;
5564 ASSERT(args.length() == 1); 5803 ASSERT(args.length() == 1);
5565 CONVERT_CHECKED(String, value, args[0]); 5804 CONVERT_CHECKED(String, value, args[0]);
5566 return value->ToObject(); 5805 return value->ToObject();
5567 } 5806 }
5568 5807
5569 5808
5570 bool Runtime::IsUpperCaseChar(uint16_t ch) { 5809 bool Runtime::IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch) {
5571 unibrow::uchar chars[unibrow::ToUppercase::kMaxWidth]; 5810 unibrow::uchar chars[unibrow::ToUppercase::kMaxWidth];
5572 int char_length = to_upper_mapping.get(ch, 0, chars); 5811 int char_length = runtime_state->to_upper_mapping()->get(ch, 0, chars);
5573 return char_length == 0; 5812 return char_length == 0;
5574 } 5813 }
5575 5814
5576 5815
5577 static MaybeObject* Runtime_NumberToString(Arguments args) { 5816 static MaybeObject* Runtime_NumberToString(RUNTIME_CALLING_CONVENTION) {
5817 RUNTIME_GET_ISOLATE;
5578 NoHandleAllocation ha; 5818 NoHandleAllocation ha;
5579 ASSERT(args.length() == 1); 5819 ASSERT(args.length() == 1);
5580 5820
5581 Object* number = args[0]; 5821 Object* number = args[0];
5582 RUNTIME_ASSERT(number->IsNumber()); 5822 RUNTIME_ASSERT(number->IsNumber());
5583 5823
5584 return Heap::NumberToString(number); 5824 return isolate->heap()->NumberToString(number);
5585 } 5825 }
5586 5826
5587 5827
5588 static MaybeObject* Runtime_NumberToStringSkipCache(Arguments args) { 5828 static MaybeObject* Runtime_NumberToStringSkipCache(
5829 RUNTIME_CALLING_CONVENTION) {
5830 RUNTIME_GET_ISOLATE;
5589 NoHandleAllocation ha; 5831 NoHandleAllocation ha;
5590 ASSERT(args.length() == 1); 5832 ASSERT(args.length() == 1);
5591 5833
5592 Object* number = args[0]; 5834 Object* number = args[0];
5593 RUNTIME_ASSERT(number->IsNumber()); 5835 RUNTIME_ASSERT(number->IsNumber());
5594 5836
5595 return Heap::NumberToString(number, false); 5837 return isolate->heap()->NumberToString(number, false);
5596 } 5838 }
5597 5839
5598 5840
5599 static MaybeObject* Runtime_NumberToInteger(Arguments args) { 5841 static MaybeObject* Runtime_NumberToInteger(RUNTIME_CALLING_CONVENTION) {
5842 RUNTIME_GET_ISOLATE;
5600 NoHandleAllocation ha; 5843 NoHandleAllocation ha;
5601 ASSERT(args.length() == 1); 5844 ASSERT(args.length() == 1);
5602 5845
5603 CONVERT_DOUBLE_CHECKED(number, args[0]); 5846 CONVERT_DOUBLE_CHECKED(number, args[0]);
5604 5847
5605 // We do not include 0 so that we don't have to treat +0 / -0 cases. 5848 // We do not include 0 so that we don't have to treat +0 / -0 cases.
5606 if (number > 0 && number <= Smi::kMaxValue) { 5849 if (number > 0 && number <= Smi::kMaxValue) {
5607 return Smi::FromInt(static_cast<int>(number)); 5850 return Smi::FromInt(static_cast<int>(number));
5608 } 5851 }
5609 return Heap::NumberFromDouble(DoubleToInteger(number)); 5852 return isolate->heap()->NumberFromDouble(DoubleToInteger(number));
5610 } 5853 }
5611 5854
5612 5855
5613 static MaybeObject* Runtime_NumberToIntegerMapMinusZero(Arguments args) { 5856 static MaybeObject* Runtime_NumberToIntegerMapMinusZero(
5857 RUNTIME_CALLING_CONVENTION) {
5858 RUNTIME_GET_ISOLATE;
5614 NoHandleAllocation ha; 5859 NoHandleAllocation ha;
5615 ASSERT(args.length() == 1); 5860 ASSERT(args.length() == 1);
5616 5861
5617 CONVERT_DOUBLE_CHECKED(number, args[0]); 5862 CONVERT_DOUBLE_CHECKED(number, args[0]);
5618 5863
5619 // We do not include 0 so that we don't have to treat +0 / -0 cases. 5864 // We do not include 0 so that we don't have to treat +0 / -0 cases.
5620 if (number > 0 && number <= Smi::kMaxValue) { 5865 if (number > 0 && number <= Smi::kMaxValue) {
5621 return Smi::FromInt(static_cast<int>(number)); 5866 return Smi::FromInt(static_cast<int>(number));
5622 } 5867 }
5623 5868
5624 double double_value = DoubleToInteger(number); 5869 double double_value = DoubleToInteger(number);
5625 // Map both -0 and +0 to +0. 5870 // Map both -0 and +0 to +0.
5626 if (double_value == 0) double_value = 0; 5871 if (double_value == 0) double_value = 0;
5627 5872
5628 return Heap::NumberFromDouble(double_value); 5873 return isolate->heap()->NumberFromDouble(double_value);
5629 } 5874 }
5630 5875
5631 5876
5632 static MaybeObject* Runtime_NumberToJSUint32(Arguments args) { 5877 static MaybeObject* Runtime_NumberToJSUint32(RUNTIME_CALLING_CONVENTION) {
5878 RUNTIME_GET_ISOLATE;
5633 NoHandleAllocation ha; 5879 NoHandleAllocation ha;
5634 ASSERT(args.length() == 1); 5880 ASSERT(args.length() == 1);
5635 5881
5636 CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, args[0]); 5882 CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, args[0]);
5637 return Heap::NumberFromUint32(number); 5883 return isolate->heap()->NumberFromUint32(number);
5638 } 5884 }
5639 5885
5640 5886
5641 static MaybeObject* Runtime_NumberToJSInt32(Arguments args) { 5887 static MaybeObject* Runtime_NumberToJSInt32(RUNTIME_CALLING_CONVENTION) {
5888 RUNTIME_GET_ISOLATE;
5642 NoHandleAllocation ha; 5889 NoHandleAllocation ha;
5643 ASSERT(args.length() == 1); 5890 ASSERT(args.length() == 1);
5644 5891
5645 CONVERT_DOUBLE_CHECKED(number, args[0]); 5892 CONVERT_DOUBLE_CHECKED(number, args[0]);
5646 5893
5647 // We do not include 0 so that we don't have to treat +0 / -0 cases. 5894 // We do not include 0 so that we don't have to treat +0 / -0 cases.
5648 if (number > 0 && number <= Smi::kMaxValue) { 5895 if (number > 0 && number <= Smi::kMaxValue) {
5649 return Smi::FromInt(static_cast<int>(number)); 5896 return Smi::FromInt(static_cast<int>(number));
5650 } 5897 }
5651 return Heap::NumberFromInt32(DoubleToInt32(number)); 5898 return isolate->heap()->NumberFromInt32(DoubleToInt32(number));
5652 } 5899 }
5653 5900
5654 5901
5655 // Converts a Number to a Smi, if possible. Returns NaN if the number is not 5902 // Converts a Number to a Smi, if possible. Returns NaN if the number is not
5656 // a small integer. 5903 // a small integer.
5657 static MaybeObject* Runtime_NumberToSmi(Arguments args) { 5904 static MaybeObject* Runtime_NumberToSmi(RUNTIME_CALLING_CONVENTION) {
5905 RUNTIME_GET_ISOLATE;
5658 NoHandleAllocation ha; 5906 NoHandleAllocation ha;
5659 ASSERT(args.length() == 1); 5907 ASSERT(args.length() == 1);
5660 5908
5661 Object* obj = args[0]; 5909 Object* obj = args[0];
5662 if (obj->IsSmi()) { 5910 if (obj->IsSmi()) {
5663 return obj; 5911 return obj;
5664 } 5912 }
5665 if (obj->IsHeapNumber()) { 5913 if (obj->IsHeapNumber()) {
5666 double value = HeapNumber::cast(obj)->value(); 5914 double value = HeapNumber::cast(obj)->value();
5667 int int_value = FastD2I(value); 5915 int int_value = FastD2I(value);
5668 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { 5916 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
5669 return Smi::FromInt(int_value); 5917 return Smi::FromInt(int_value);
5670 } 5918 }
5671 } 5919 }
5672 return Heap::nan_value(); 5920 return isolate->heap()->nan_value();
5673 } 5921 }
5674 5922
5675 5923
5676 static MaybeObject* Runtime_StoreBufferOverflow(Arguments args) { 5924 static MaybeObject* Runtime_AllocateHeapNumber(RUNTIME_CALLING_CONVENTION) {
5677 StoreBuffer::Compact(); 5925 RUNTIME_GET_ISOLATE;
5678 return Heap::undefined_value(); 5926 NoHandleAllocation ha;
5927 ASSERT(args.length() == 0);
5928 return isolate->heap()->AllocateHeapNumber(0);
5679 } 5929 }
5680 5930
5681 5931
5682 static MaybeObject* Runtime_AllocateHeapNumber(Arguments args) { 5932 static MaybeObject* Runtime_NumberAdd(RUNTIME_CALLING_CONVENTION) {
5683 NoHandleAllocation ha; 5933 RUNTIME_GET_ISOLATE;
5684 ASSERT(args.length() == 0);
5685 return Heap::AllocateHeapNumber(0);
5686 }
5687
5688
5689 static MaybeObject* Runtime_NumberAdd(Arguments args) {
5690 NoHandleAllocation ha; 5934 NoHandleAllocation ha;
5691 ASSERT(args.length() == 2); 5935 ASSERT(args.length() == 2);
5692 5936
5693 CONVERT_DOUBLE_CHECKED(x, args[0]); 5937 CONVERT_DOUBLE_CHECKED(x, args[0]);
5694 CONVERT_DOUBLE_CHECKED(y, args[1]); 5938 CONVERT_DOUBLE_CHECKED(y, args[1]);
5695 return Heap::NumberFromDouble(x + y); 5939 return isolate->heap()->NumberFromDouble(x + y);
5696 } 5940 }
5697 5941
5698 5942
5699 static MaybeObject* Runtime_NumberSub(Arguments args) { 5943 static MaybeObject* Runtime_NumberSub(RUNTIME_CALLING_CONVENTION) {
5944 RUNTIME_GET_ISOLATE;
5700 NoHandleAllocation ha; 5945 NoHandleAllocation ha;
5701 ASSERT(args.length() == 2); 5946 ASSERT(args.length() == 2);
5702 5947
5703 CONVERT_DOUBLE_CHECKED(x, args[0]); 5948 CONVERT_DOUBLE_CHECKED(x, args[0]);
5704 CONVERT_DOUBLE_CHECKED(y, args[1]); 5949 CONVERT_DOUBLE_CHECKED(y, args[1]);
5705 return Heap::NumberFromDouble(x - y); 5950 return isolate->heap()->NumberFromDouble(x - y);
5706 } 5951 }
5707 5952
5708 5953
5709 static MaybeObject* Runtime_NumberMul(Arguments args) { 5954 static MaybeObject* Runtime_NumberMul(RUNTIME_CALLING_CONVENTION) {
5955 RUNTIME_GET_ISOLATE;
5710 NoHandleAllocation ha; 5956 NoHandleAllocation ha;
5711 ASSERT(args.length() == 2); 5957 ASSERT(args.length() == 2);
5712 5958
5713 CONVERT_DOUBLE_CHECKED(x, args[0]); 5959 CONVERT_DOUBLE_CHECKED(x, args[0]);
5714 CONVERT_DOUBLE_CHECKED(y, args[1]); 5960 CONVERT_DOUBLE_CHECKED(y, args[1]);
5715 return Heap::NumberFromDouble(x * y); 5961 return isolate->heap()->NumberFromDouble(x * y);
5716 } 5962 }
5717 5963
5718 5964
5719 static MaybeObject* Runtime_NumberUnaryMinus(Arguments args) { 5965 static MaybeObject* Runtime_NumberUnaryMinus(RUNTIME_CALLING_CONVENTION) {
5966 RUNTIME_GET_ISOLATE;
5720 NoHandleAllocation ha; 5967 NoHandleAllocation ha;
5721 ASSERT(args.length() == 1); 5968 ASSERT(args.length() == 1);
5722 5969
5723 CONVERT_DOUBLE_CHECKED(x, args[0]); 5970 CONVERT_DOUBLE_CHECKED(x, args[0]);
5724 return Heap::NumberFromDouble(-x); 5971 return isolate->heap()->NumberFromDouble(-x);
5725 } 5972 }
5726 5973
5727 5974
5728 static MaybeObject* Runtime_NumberAlloc(Arguments args) { 5975 static MaybeObject* Runtime_NumberAlloc(RUNTIME_CALLING_CONVENTION) {
5976 RUNTIME_GET_ISOLATE;
5729 NoHandleAllocation ha; 5977 NoHandleAllocation ha;
5730 ASSERT(args.length() == 0); 5978 ASSERT(args.length() == 0);
5731 5979
5732 return Heap::NumberFromDouble(9876543210.0); 5980 return isolate->heap()->NumberFromDouble(9876543210.0);
5733 } 5981 }
5734 5982
5735 5983
5736 static MaybeObject* Runtime_NumberDiv(Arguments args) { 5984 static MaybeObject* Runtime_NumberDiv(RUNTIME_CALLING_CONVENTION) {
5985 RUNTIME_GET_ISOLATE;
5737 NoHandleAllocation ha; 5986 NoHandleAllocation ha;
5738 ASSERT(args.length() == 2); 5987 ASSERT(args.length() == 2);
5739 5988
5740 CONVERT_DOUBLE_CHECKED(x, args[0]); 5989 CONVERT_DOUBLE_CHECKED(x, args[0]);
5741 CONVERT_DOUBLE_CHECKED(y, args[1]); 5990 CONVERT_DOUBLE_CHECKED(y, args[1]);
5742 return Heap::NumberFromDouble(x / y); 5991 return isolate->heap()->NumberFromDouble(x / y);
5743 } 5992 }
5744 5993
5745 5994
5746 static MaybeObject* Runtime_NumberMod(Arguments args) { 5995 static MaybeObject* Runtime_NumberMod(RUNTIME_CALLING_CONVENTION) {
5996 RUNTIME_GET_ISOLATE;
5747 NoHandleAllocation ha; 5997 NoHandleAllocation ha;
5748 ASSERT(args.length() == 2); 5998 ASSERT(args.length() == 2);
5749 5999
5750 CONVERT_DOUBLE_CHECKED(x, args[0]); 6000 CONVERT_DOUBLE_CHECKED(x, args[0]);
5751 CONVERT_DOUBLE_CHECKED(y, args[1]); 6001 CONVERT_DOUBLE_CHECKED(y, args[1]);
5752 6002
5753 x = modulo(x, y); 6003 x = modulo(x, y);
5754 // NumberFromDouble may return a Smi instead of a Number object 6004 // NumberFromDouble may return a Smi instead of a Number object
5755 return Heap::NumberFromDouble(x); 6005 return isolate->heap()->NumberFromDouble(x);
5756 } 6006 }
5757 6007
5758 6008
5759 static MaybeObject* Runtime_StringAdd(Arguments args) { 6009 static MaybeObject* Runtime_StringAdd(RUNTIME_CALLING_CONVENTION) {
6010 RUNTIME_GET_ISOLATE;
5760 NoHandleAllocation ha; 6011 NoHandleAllocation ha;
5761 ASSERT(args.length() == 2); 6012 ASSERT(args.length() == 2);
5762 CONVERT_CHECKED(String, str1, args[0]); 6013 CONVERT_CHECKED(String, str1, args[0]);
5763 CONVERT_CHECKED(String, str2, args[1]); 6014 CONVERT_CHECKED(String, str2, args[1]);
5764 Counters::string_add_runtime.Increment(); 6015 isolate->counters()->string_add_runtime()->Increment();
5765 return Heap::AllocateConsString(str1, str2); 6016 return isolate->heap()->AllocateConsString(str1, str2);
5766 } 6017 }
5767 6018
5768 6019
5769 template <typename sinkchar> 6020 template <typename sinkchar>
5770 static inline void StringBuilderConcatHelper(String* special, 6021 static inline void StringBuilderConcatHelper(String* special,
5771 sinkchar* sink, 6022 sinkchar* sink,
5772 FixedArray* fixed_array, 6023 FixedArray* fixed_array,
5773 int array_length) { 6024 int array_length) {
5774 int position = 0; 6025 int position = 0;
5775 for (int i = 0; i < array_length; i++) { 6026 for (int i = 0; i < array_length; i++) {
(...skipping 22 matching lines...) Expand all
5798 } else { 6049 } else {
5799 String* string = String::cast(element); 6050 String* string = String::cast(element);
5800 int element_length = string->length(); 6051 int element_length = string->length();
5801 String::WriteToFlat(string, sink + position, 0, element_length); 6052 String::WriteToFlat(string, sink + position, 0, element_length);
5802 position += element_length; 6053 position += element_length;
5803 } 6054 }
5804 } 6055 }
5805 } 6056 }
5806 6057
5807 6058
5808 static MaybeObject* Runtime_StringBuilderConcat(Arguments args) { 6059 static MaybeObject* Runtime_StringBuilderConcat(RUNTIME_CALLING_CONVENTION) {
6060 RUNTIME_GET_ISOLATE;
5809 NoHandleAllocation ha; 6061 NoHandleAllocation ha;
5810 ASSERT(args.length() == 3); 6062 ASSERT(args.length() == 3);
5811 CONVERT_CHECKED(JSArray, array, args[0]); 6063 CONVERT_CHECKED(JSArray, array, args[0]);
5812 if (!args[1]->IsSmi()) { 6064 if (!args[1]->IsSmi()) {
5813 Top::context()->mark_out_of_memory(); 6065 isolate->context()->mark_out_of_memory();
5814 return Failure::OutOfMemoryException(); 6066 return Failure::OutOfMemoryException();
5815 } 6067 }
5816 int array_length = Smi::cast(args[1])->value(); 6068 int array_length = Smi::cast(args[1])->value();
5817 CONVERT_CHECKED(String, special, args[2]); 6069 CONVERT_CHECKED(String, special, args[2]);
5818 6070
5819 // This assumption is used by the slice encoding in one or two smis. 6071 // This assumption is used by the slice encoding in one or two smis.
5820 ASSERT(Smi::kMaxValue >= String::kMaxLength); 6072 ASSERT(Smi::kMaxValue >= String::kMaxLength);
5821 6073
5822 int special_length = special->length(); 6074 int special_length = special->length();
5823 if (!array->HasFastElements()) { 6075 if (!array->HasFastElements()) {
5824 return Top::Throw(Heap::illegal_argument_symbol()); 6076 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5825 } 6077 }
5826 FixedArray* fixed_array = FixedArray::cast(array->elements()); 6078 FixedArray* fixed_array = FixedArray::cast(array->elements());
5827 if (fixed_array->length() < array_length) { 6079 if (fixed_array->length() < array_length) {
5828 array_length = fixed_array->length(); 6080 array_length = fixed_array->length();
5829 } 6081 }
5830 6082
5831 if (array_length == 0) { 6083 if (array_length == 0) {
5832 return Heap::empty_string(); 6084 return isolate->heap()->empty_string();
5833 } else if (array_length == 1) { 6085 } else if (array_length == 1) {
5834 Object* first = fixed_array->get(0); 6086 Object* first = fixed_array->get(0);
5835 if (first->IsString()) return first; 6087 if (first->IsString()) return first;
5836 } 6088 }
5837 6089
5838 bool ascii = special->HasOnlyAsciiChars(); 6090 bool ascii = special->HasOnlyAsciiChars();
5839 int position = 0; 6091 int position = 0;
5840 for (int i = 0; i < array_length; i++) { 6092 for (int i = 0; i < array_length; i++) {
5841 int increment = 0; 6093 int increment = 0;
5842 Object* elt = fixed_array->get(i); 6094 Object* elt = fixed_array->get(i);
5843 if (elt->IsSmi()) { 6095 if (elt->IsSmi()) {
5844 // Smi encoding of position and length. 6096 // Smi encoding of position and length.
5845 int smi_value = Smi::cast(elt)->value(); 6097 int smi_value = Smi::cast(elt)->value();
5846 int pos; 6098 int pos;
5847 int len; 6099 int len;
5848 if (smi_value > 0) { 6100 if (smi_value > 0) {
5849 // Position and length encoded in one smi. 6101 // Position and length encoded in one smi.
5850 pos = StringBuilderSubstringPosition::decode(smi_value); 6102 pos = StringBuilderSubstringPosition::decode(smi_value);
5851 len = StringBuilderSubstringLength::decode(smi_value); 6103 len = StringBuilderSubstringLength::decode(smi_value);
5852 } else { 6104 } else {
5853 // Position and length encoded in two smis. 6105 // Position and length encoded in two smis.
5854 len = -smi_value; 6106 len = -smi_value;
5855 // Get the position and check that it is a positive smi. 6107 // Get the position and check that it is a positive smi.
5856 i++; 6108 i++;
5857 if (i >= array_length) { 6109 if (i >= array_length) {
5858 return Top::Throw(Heap::illegal_argument_symbol()); 6110 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5859 } 6111 }
5860 Object* next_smi = fixed_array->get(i); 6112 Object* next_smi = fixed_array->get(i);
5861 if (!next_smi->IsSmi()) { 6113 if (!next_smi->IsSmi()) {
5862 return Top::Throw(Heap::illegal_argument_symbol()); 6114 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5863 } 6115 }
5864 pos = Smi::cast(next_smi)->value(); 6116 pos = Smi::cast(next_smi)->value();
5865 if (pos < 0) { 6117 if (pos < 0) {
5866 return Top::Throw(Heap::illegal_argument_symbol()); 6118 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5867 } 6119 }
5868 } 6120 }
5869 ASSERT(pos >= 0); 6121 ASSERT(pos >= 0);
5870 ASSERT(len >= 0); 6122 ASSERT(len >= 0);
5871 if (pos > special_length || len > special_length - pos) { 6123 if (pos > special_length || len > special_length - pos) {
5872 return Top::Throw(Heap::illegal_argument_symbol()); 6124 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5873 } 6125 }
5874 increment = len; 6126 increment = len;
5875 } else if (elt->IsString()) { 6127 } else if (elt->IsString()) {
5876 String* element = String::cast(elt); 6128 String* element = String::cast(elt);
5877 int element_length = element->length(); 6129 int element_length = element->length();
5878 increment = element_length; 6130 increment = element_length;
5879 if (ascii && !element->HasOnlyAsciiChars()) { 6131 if (ascii && !element->HasOnlyAsciiChars()) {
5880 ascii = false; 6132 ascii = false;
5881 } 6133 }
5882 } else { 6134 } else {
5883 return Top::Throw(Heap::illegal_argument_symbol()); 6135 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5884 } 6136 }
5885 if (increment > String::kMaxLength - position) { 6137 if (increment > String::kMaxLength - position) {
5886 Top::context()->mark_out_of_memory(); 6138 isolate->context()->mark_out_of_memory();
5887 return Failure::OutOfMemoryException(); 6139 return Failure::OutOfMemoryException();
5888 } 6140 }
5889 position += increment; 6141 position += increment;
5890 } 6142 }
5891 6143
5892 int length = position; 6144 int length = position;
5893 Object* object; 6145 Object* object;
5894 6146
5895 if (ascii) { 6147 if (ascii) {
5896 { MaybeObject* maybe_object = Heap::AllocateRawAsciiString(length); 6148 { MaybeObject* maybe_object =
6149 isolate->heap()->AllocateRawAsciiString(length);
5897 if (!maybe_object->ToObject(&object)) return maybe_object; 6150 if (!maybe_object->ToObject(&object)) return maybe_object;
5898 } 6151 }
5899 SeqAsciiString* answer = SeqAsciiString::cast(object); 6152 SeqAsciiString* answer = SeqAsciiString::cast(object);
5900 StringBuilderConcatHelper(special, 6153 StringBuilderConcatHelper(special,
5901 answer->GetChars(), 6154 answer->GetChars(),
5902 fixed_array, 6155 fixed_array,
5903 array_length); 6156 array_length);
5904 return answer; 6157 return answer;
5905 } else { 6158 } else {
5906 { MaybeObject* maybe_object = Heap::AllocateRawTwoByteString(length); 6159 { MaybeObject* maybe_object =
6160 isolate->heap()->AllocateRawTwoByteString(length);
5907 if (!maybe_object->ToObject(&object)) return maybe_object; 6161 if (!maybe_object->ToObject(&object)) return maybe_object;
5908 } 6162 }
5909 SeqTwoByteString* answer = SeqTwoByteString::cast(object); 6163 SeqTwoByteString* answer = SeqTwoByteString::cast(object);
5910 StringBuilderConcatHelper(special, 6164 StringBuilderConcatHelper(special,
5911 answer->GetChars(), 6165 answer->GetChars(),
5912 fixed_array, 6166 fixed_array,
5913 array_length); 6167 array_length);
5914 return answer; 6168 return answer;
5915 } 6169 }
5916 } 6170 }
5917 6171
5918 6172
5919 static MaybeObject* Runtime_StringBuilderJoin(Arguments args) { 6173 static MaybeObject* Runtime_StringBuilderJoin(RUNTIME_CALLING_CONVENTION) {
6174 RUNTIME_GET_ISOLATE;
5920 NoHandleAllocation ha; 6175 NoHandleAllocation ha;
5921 ASSERT(args.length() == 3); 6176 ASSERT(args.length() == 3);
5922 CONVERT_CHECKED(JSArray, array, args[0]); 6177 CONVERT_CHECKED(JSArray, array, args[0]);
5923 if (!args[1]->IsSmi()) { 6178 if (!args[1]->IsSmi()) {
5924 Top::context()->mark_out_of_memory(); 6179 isolate->context()->mark_out_of_memory();
5925 return Failure::OutOfMemoryException(); 6180 return Failure::OutOfMemoryException();
5926 } 6181 }
5927 int array_length = Smi::cast(args[1])->value(); 6182 int array_length = Smi::cast(args[1])->value();
5928 CONVERT_CHECKED(String, separator, args[2]); 6183 CONVERT_CHECKED(String, separator, args[2]);
5929 6184
5930 if (!array->HasFastElements()) { 6185 if (!array->HasFastElements()) {
5931 return Top::Throw(Heap::illegal_argument_symbol()); 6186 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5932 } 6187 }
5933 FixedArray* fixed_array = FixedArray::cast(array->elements()); 6188 FixedArray* fixed_array = FixedArray::cast(array->elements());
5934 if (fixed_array->length() < array_length) { 6189 if (fixed_array->length() < array_length) {
5935 array_length = fixed_array->length(); 6190 array_length = fixed_array->length();
5936 } 6191 }
5937 6192
5938 if (array_length == 0) { 6193 if (array_length == 0) {
5939 return Heap::empty_string(); 6194 return isolate->heap()->empty_string();
5940 } else if (array_length == 1) { 6195 } else if (array_length == 1) {
5941 Object* first = fixed_array->get(0); 6196 Object* first = fixed_array->get(0);
5942 if (first->IsString()) return first; 6197 if (first->IsString()) return first;
5943 } 6198 }
5944 6199
5945 int separator_length = separator->length(); 6200 int separator_length = separator->length();
5946 int max_nof_separators = 6201 int max_nof_separators =
5947 (String::kMaxLength + separator_length - 1) / separator_length; 6202 (String::kMaxLength + separator_length - 1) / separator_length;
5948 if (max_nof_separators < (array_length - 1)) { 6203 if (max_nof_separators < (array_length - 1)) {
5949 Top::context()->mark_out_of_memory(); 6204 isolate->context()->mark_out_of_memory();
5950 return Failure::OutOfMemoryException(); 6205 return Failure::OutOfMemoryException();
5951 } 6206 }
5952 int length = (array_length - 1) * separator_length; 6207 int length = (array_length - 1) * separator_length;
5953 for (int i = 0; i < array_length; i++) { 6208 for (int i = 0; i < array_length; i++) {
5954 Object* element_obj = fixed_array->get(i); 6209 Object* element_obj = fixed_array->get(i);
5955 if (!element_obj->IsString()) { 6210 if (!element_obj->IsString()) {
5956 // TODO(1161): handle this case. 6211 // TODO(1161): handle this case.
5957 return Top::Throw(Heap::illegal_argument_symbol()); 6212 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
5958 } 6213 }
5959 String* element = String::cast(element_obj); 6214 String* element = String::cast(element_obj);
5960 int increment = element->length(); 6215 int increment = element->length();
5961 if (increment > String::kMaxLength - length) { 6216 if (increment > String::kMaxLength - length) {
5962 Top::context()->mark_out_of_memory(); 6217 isolate->context()->mark_out_of_memory();
5963 return Failure::OutOfMemoryException(); 6218 return Failure::OutOfMemoryException();
5964 } 6219 }
5965 length += increment; 6220 length += increment;
5966 } 6221 }
5967 6222
5968 Object* object; 6223 Object* object;
5969 { MaybeObject* maybe_object = Heap::AllocateRawTwoByteString(length); 6224 { MaybeObject* maybe_object =
6225 isolate->heap()->AllocateRawTwoByteString(length);
5970 if (!maybe_object->ToObject(&object)) return maybe_object; 6226 if (!maybe_object->ToObject(&object)) return maybe_object;
5971 } 6227 }
5972 SeqTwoByteString* answer = SeqTwoByteString::cast(object); 6228 SeqTwoByteString* answer = SeqTwoByteString::cast(object);
5973 6229
5974 uc16* sink = answer->GetChars(); 6230 uc16* sink = answer->GetChars();
5975 #ifdef DEBUG 6231 #ifdef DEBUG
5976 uc16* end = sink + length; 6232 uc16* end = sink + length;
5977 #endif 6233 #endif
5978 6234
5979 String* first = String::cast(fixed_array->get(0)); 6235 String* first = String::cast(fixed_array->get(0));
(...skipping 12 matching lines...) Expand all
5992 String::WriteToFlat(element, sink, 0, element_length); 6248 String::WriteToFlat(element, sink, 0, element_length);
5993 sink += element_length; 6249 sink += element_length;
5994 } 6250 }
5995 ASSERT(sink == end); 6251 ASSERT(sink == end);
5996 6252
5997 ASSERT(!answer->HasOnlyAsciiChars()); // Use %_FastAsciiArrayJoin instead. 6253 ASSERT(!answer->HasOnlyAsciiChars()); // Use %_FastAsciiArrayJoin instead.
5998 return answer; 6254 return answer;
5999 } 6255 }
6000 6256
6001 6257
6002 static MaybeObject* Runtime_NumberOr(Arguments args) { 6258 static MaybeObject* Runtime_NumberOr(RUNTIME_CALLING_CONVENTION) {
6259 RUNTIME_GET_ISOLATE;
6003 NoHandleAllocation ha; 6260 NoHandleAllocation ha;
6004 ASSERT(args.length() == 2); 6261 ASSERT(args.length() == 2);
6005 6262
6006 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6263 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6007 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6264 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6008 return Heap::NumberFromInt32(x | y); 6265 return isolate->heap()->NumberFromInt32(x | y);
6009 } 6266 }
6010 6267
6011 6268
6012 static MaybeObject* Runtime_NumberAnd(Arguments args) { 6269 static MaybeObject* Runtime_NumberAnd(RUNTIME_CALLING_CONVENTION) {
6270 RUNTIME_GET_ISOLATE;
6013 NoHandleAllocation ha; 6271 NoHandleAllocation ha;
6014 ASSERT(args.length() == 2); 6272 ASSERT(args.length() == 2);
6015 6273
6016 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6274 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6017 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6275 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6018 return Heap::NumberFromInt32(x & y); 6276 return isolate->heap()->NumberFromInt32(x & y);
6019 } 6277 }
6020 6278
6021 6279
6022 static MaybeObject* Runtime_NumberXor(Arguments args) { 6280 static MaybeObject* Runtime_NumberXor(RUNTIME_CALLING_CONVENTION) {
6281 RUNTIME_GET_ISOLATE;
6023 NoHandleAllocation ha; 6282 NoHandleAllocation ha;
6024 ASSERT(args.length() == 2); 6283 ASSERT(args.length() == 2);
6025 6284
6026 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6285 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6027 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6286 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6028 return Heap::NumberFromInt32(x ^ y); 6287 return isolate->heap()->NumberFromInt32(x ^ y);
6029 } 6288 }
6030 6289
6031 6290
6032 static MaybeObject* Runtime_NumberNot(Arguments args) { 6291 static MaybeObject* Runtime_NumberNot(RUNTIME_CALLING_CONVENTION) {
6292 RUNTIME_GET_ISOLATE;
6033 NoHandleAllocation ha; 6293 NoHandleAllocation ha;
6034 ASSERT(args.length() == 1); 6294 ASSERT(args.length() == 1);
6035 6295
6036 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6296 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6037 return Heap::NumberFromInt32(~x); 6297 return isolate->heap()->NumberFromInt32(~x);
6038 } 6298 }
6039 6299
6040 6300
6041 static MaybeObject* Runtime_NumberShl(Arguments args) { 6301 static MaybeObject* Runtime_NumberShl(RUNTIME_CALLING_CONVENTION) {
6302 RUNTIME_GET_ISOLATE;
6042 NoHandleAllocation ha; 6303 NoHandleAllocation ha;
6043 ASSERT(args.length() == 2); 6304 ASSERT(args.length() == 2);
6044 6305
6045 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6306 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6046 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6307 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6047 return Heap::NumberFromInt32(x << (y & 0x1f)); 6308 return isolate->heap()->NumberFromInt32(x << (y & 0x1f));
6048 } 6309 }
6049 6310
6050 6311
6051 static MaybeObject* Runtime_NumberShr(Arguments args) { 6312 static MaybeObject* Runtime_NumberShr(RUNTIME_CALLING_CONVENTION) {
6313 RUNTIME_GET_ISOLATE;
6052 NoHandleAllocation ha; 6314 NoHandleAllocation ha;
6053 ASSERT(args.length() == 2); 6315 ASSERT(args.length() == 2);
6054 6316
6055 CONVERT_NUMBER_CHECKED(uint32_t, x, Uint32, args[0]); 6317 CONVERT_NUMBER_CHECKED(uint32_t, x, Uint32, args[0]);
6056 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6318 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6057 return Heap::NumberFromUint32(x >> (y & 0x1f)); 6319 return isolate->heap()->NumberFromUint32(x >> (y & 0x1f));
6058 } 6320 }
6059 6321
6060 6322
6061 static MaybeObject* Runtime_NumberSar(Arguments args) { 6323 static MaybeObject* Runtime_NumberSar(RUNTIME_CALLING_CONVENTION) {
6324 RUNTIME_GET_ISOLATE;
6062 NoHandleAllocation ha; 6325 NoHandleAllocation ha;
6063 ASSERT(args.length() == 2); 6326 ASSERT(args.length() == 2);
6064 6327
6065 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6328 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6066 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6329 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6067 return Heap::NumberFromInt32(ArithmeticShiftRight(x, y & 0x1f)); 6330 return isolate->heap()->NumberFromInt32(ArithmeticShiftRight(x, y & 0x1f));
6068 } 6331 }
6069 6332
6070 6333
6071 static MaybeObject* Runtime_NumberEquals(Arguments args) { 6334 static MaybeObject* Runtime_NumberEquals(RUNTIME_CALLING_CONVENTION) {
6335 RUNTIME_GET_ISOLATE;
6072 NoHandleAllocation ha; 6336 NoHandleAllocation ha;
6073 ASSERT(args.length() == 2); 6337 ASSERT(args.length() == 2);
6074 6338
6075 CONVERT_DOUBLE_CHECKED(x, args[0]); 6339 CONVERT_DOUBLE_CHECKED(x, args[0]);
6076 CONVERT_DOUBLE_CHECKED(y, args[1]); 6340 CONVERT_DOUBLE_CHECKED(y, args[1]);
6077 if (isnan(x)) return Smi::FromInt(NOT_EQUAL); 6341 if (isnan(x)) return Smi::FromInt(NOT_EQUAL);
6078 if (isnan(y)) return Smi::FromInt(NOT_EQUAL); 6342 if (isnan(y)) return Smi::FromInt(NOT_EQUAL);
6079 if (x == y) return Smi::FromInt(EQUAL); 6343 if (x == y) return Smi::FromInt(EQUAL);
6080 Object* result; 6344 Object* result;
6081 if ((fpclassify(x) == FP_ZERO) && (fpclassify(y) == FP_ZERO)) { 6345 if ((fpclassify(x) == FP_ZERO) && (fpclassify(y) == FP_ZERO)) {
6082 result = Smi::FromInt(EQUAL); 6346 result = Smi::FromInt(EQUAL);
6083 } else { 6347 } else {
6084 result = Smi::FromInt(NOT_EQUAL); 6348 result = Smi::FromInt(NOT_EQUAL);
6085 } 6349 }
6086 return result; 6350 return result;
6087 } 6351 }
6088 6352
6089 6353
6090 static MaybeObject* Runtime_StringEquals(Arguments args) { 6354 static MaybeObject* Runtime_StringEquals(RUNTIME_CALLING_CONVENTION) {
6355 RUNTIME_GET_ISOLATE;
6091 NoHandleAllocation ha; 6356 NoHandleAllocation ha;
6092 ASSERT(args.length() == 2); 6357 ASSERT(args.length() == 2);
6093 6358
6094 CONVERT_CHECKED(String, x, args[0]); 6359 CONVERT_CHECKED(String, x, args[0]);
6095 CONVERT_CHECKED(String, y, args[1]); 6360 CONVERT_CHECKED(String, y, args[1]);
6096 6361
6097 bool not_equal = !x->Equals(y); 6362 bool not_equal = !x->Equals(y);
6098 // This is slightly convoluted because the value that signifies 6363 // This is slightly convoluted because the value that signifies
6099 // equality is 0 and inequality is 1 so we have to negate the result 6364 // equality is 0 and inequality is 1 so we have to negate the result
6100 // from String::Equals. 6365 // from String::Equals.
6101 ASSERT(not_equal == 0 || not_equal == 1); 6366 ASSERT(not_equal == 0 || not_equal == 1);
6102 STATIC_CHECK(EQUAL == 0); 6367 STATIC_CHECK(EQUAL == 0);
6103 STATIC_CHECK(NOT_EQUAL == 1); 6368 STATIC_CHECK(NOT_EQUAL == 1);
6104 return Smi::FromInt(not_equal); 6369 return Smi::FromInt(not_equal);
6105 } 6370 }
6106 6371
6107 6372
6108 static MaybeObject* Runtime_NumberCompare(Arguments args) { 6373 static MaybeObject* Runtime_NumberCompare(RUNTIME_CALLING_CONVENTION) {
6374 RUNTIME_GET_ISOLATE;
6109 NoHandleAllocation ha; 6375 NoHandleAllocation ha;
6110 ASSERT(args.length() == 3); 6376 ASSERT(args.length() == 3);
6111 6377
6112 CONVERT_DOUBLE_CHECKED(x, args[0]); 6378 CONVERT_DOUBLE_CHECKED(x, args[0]);
6113 CONVERT_DOUBLE_CHECKED(y, args[1]); 6379 CONVERT_DOUBLE_CHECKED(y, args[1]);
6114 if (isnan(x) || isnan(y)) return args[2]; 6380 if (isnan(x) || isnan(y)) return args[2];
6115 if (x == y) return Smi::FromInt(EQUAL); 6381 if (x == y) return Smi::FromInt(EQUAL);
6116 if (isless(x, y)) return Smi::FromInt(LESS); 6382 if (isless(x, y)) return Smi::FromInt(LESS);
6117 return Smi::FromInt(GREATER); 6383 return Smi::FromInt(GREATER);
6118 } 6384 }
6119 6385
6120 6386
6121 // Compare two Smis as if they were converted to strings and then 6387 // Compare two Smis as if they were converted to strings and then
6122 // compared lexicographically. 6388 // compared lexicographically.
6123 static MaybeObject* Runtime_SmiLexicographicCompare(Arguments args) { 6389 static MaybeObject* Runtime_SmiLexicographicCompare(
6390 RUNTIME_CALLING_CONVENTION) {
6391 RUNTIME_GET_ISOLATE;
6124 NoHandleAllocation ha; 6392 NoHandleAllocation ha;
6125 ASSERT(args.length() == 2); 6393 ASSERT(args.length() == 2);
6126 6394
6127 // Arrays for the individual characters of the two Smis. Smis are
6128 // 31 bit integers and 10 decimal digits are therefore enough.
6129 static int x_elms[10];
6130 static int y_elms[10];
6131
6132 // Extract the integer values from the Smis. 6395 // Extract the integer values from the Smis.
6133 CONVERT_CHECKED(Smi, x, args[0]); 6396 CONVERT_CHECKED(Smi, x, args[0]);
6134 CONVERT_CHECKED(Smi, y, args[1]); 6397 CONVERT_CHECKED(Smi, y, args[1]);
6135 int x_value = x->value(); 6398 int x_value = x->value();
6136 int y_value = y->value(); 6399 int y_value = y->value();
6137 6400
6138 // If the integers are equal so are the string representations. 6401 // If the integers are equal so are the string representations.
6139 if (x_value == y_value) return Smi::FromInt(EQUAL); 6402 if (x_value == y_value) return Smi::FromInt(EQUAL);
6140 6403
6141 // If one of the integers are zero the normal integer order is the 6404 // If one of the integers are zero the normal integer order is the
6142 // same as the lexicographic order of the string representations. 6405 // same as the lexicographic order of the string representations.
6143 if (x_value == 0 || y_value == 0) return Smi::FromInt(x_value - y_value); 6406 if (x_value == 0 || y_value == 0) return Smi::FromInt(x_value - y_value);
6144 6407
6145 // If only one of the integers is negative the negative number is 6408 // If only one of the integers is negative the negative number is
6146 // smallest because the char code of '-' is less than the char code 6409 // smallest because the char code of '-' is less than the char code
6147 // of any digit. Otherwise, we make both values positive. 6410 // of any digit. Otherwise, we make both values positive.
6148 if (x_value < 0 || y_value < 0) { 6411 if (x_value < 0 || y_value < 0) {
6149 if (y_value >= 0) return Smi::FromInt(LESS); 6412 if (y_value >= 0) return Smi::FromInt(LESS);
6150 if (x_value >= 0) return Smi::FromInt(GREATER); 6413 if (x_value >= 0) return Smi::FromInt(GREATER);
6151 x_value = -x_value; 6414 x_value = -x_value;
6152 y_value = -y_value; 6415 y_value = -y_value;
6153 } 6416 }
6154 6417
6418 // Arrays for the individual characters of the two Smis. Smis are
6419 // 31 bit integers and 10 decimal digits are therefore enough.
6420 // TODO(isolates): maybe we should simply allocate 20 bytes on the stack.
6421 int* x_elms = isolate->runtime_state()->smi_lexicographic_compare_x_elms();
6422 int* y_elms = isolate->runtime_state()->smi_lexicographic_compare_y_elms();
6423
6424
6155 // Convert the integers to arrays of their decimal digits. 6425 // Convert the integers to arrays of their decimal digits.
6156 int x_index = 0; 6426 int x_index = 0;
6157 int y_index = 0; 6427 int y_index = 0;
6158 while (x_value > 0) { 6428 while (x_value > 0) {
6159 x_elms[x_index++] = x_value % 10; 6429 x_elms[x_index++] = x_value % 10;
6160 x_value /= 10; 6430 x_value /= 10;
6161 } 6431 }
6162 while (y_value > 0) { 6432 while (y_value > 0) {
6163 y_elms[y_index++] = y_value % 10; 6433 y_elms[y_index++] = y_value % 10;
6164 y_value /= 10; 6434 y_value /= 10;
6165 } 6435 }
6166 6436
6167 // Loop through the arrays of decimal digits finding the first place 6437 // Loop through the arrays of decimal digits finding the first place
6168 // where they differ. 6438 // where they differ.
6169 while (--x_index >= 0 && --y_index >= 0) { 6439 while (--x_index >= 0 && --y_index >= 0) {
6170 int diff = x_elms[x_index] - y_elms[y_index]; 6440 int diff = x_elms[x_index] - y_elms[y_index];
6171 if (diff != 0) return Smi::FromInt(diff); 6441 if (diff != 0) return Smi::FromInt(diff);
6172 } 6442 }
6173 6443
6174 // If one array is a suffix of the other array, the longest array is 6444 // If one array is a suffix of the other array, the longest array is
6175 // the representation of the largest of the Smis in the 6445 // the representation of the largest of the Smis in the
6176 // lexicographic ordering. 6446 // lexicographic ordering.
6177 return Smi::FromInt(x_index - y_index); 6447 return Smi::FromInt(x_index - y_index);
6178 } 6448 }
6179 6449
6180 6450
6181 static Object* StringInputBufferCompare(String* x, String* y) { 6451 static Object* StringInputBufferCompare(RuntimeState* state,
6182 static StringInputBuffer bufx; 6452 String* x,
6183 static StringInputBuffer bufy; 6453 String* y) {
6454 StringInputBuffer& bufx = *state->string_input_buffer_compare_bufx();
6455 StringInputBuffer& bufy = *state->string_input_buffer_compare_bufy();
6184 bufx.Reset(x); 6456 bufx.Reset(x);
6185 bufy.Reset(y); 6457 bufy.Reset(y);
6186 while (bufx.has_more() && bufy.has_more()) { 6458 while (bufx.has_more() && bufy.has_more()) {
6187 int d = bufx.GetNext() - bufy.GetNext(); 6459 int d = bufx.GetNext() - bufy.GetNext();
6188 if (d < 0) return Smi::FromInt(LESS); 6460 if (d < 0) return Smi::FromInt(LESS);
6189 else if (d > 0) return Smi::FromInt(GREATER); 6461 else if (d > 0) return Smi::FromInt(GREATER);
6190 } 6462 }
6191 6463
6192 // x is (non-trivial) prefix of y: 6464 // x is (non-trivial) prefix of y:
6193 if (bufy.has_more()) return Smi::FromInt(LESS); 6465 if (bufy.has_more()) return Smi::FromInt(LESS);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
6226 Vector<const uc16> y_chars = y->ToUC16Vector(); 6498 Vector<const uc16> y_chars = y->ToUC16Vector();
6227 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); 6499 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
6228 } 6500 }
6229 } 6501 }
6230 Object* result; 6502 Object* result;
6231 if (r == 0) { 6503 if (r == 0) {
6232 result = equal_prefix_result; 6504 result = equal_prefix_result;
6233 } else { 6505 } else {
6234 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); 6506 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER);
6235 } 6507 }
6236 ASSERT(result == StringInputBufferCompare(x, y)); 6508 ASSERT(result ==
6509 StringInputBufferCompare(Isolate::Current()->runtime_state(), x, y));
6237 return result; 6510 return result;
6238 } 6511 }
6239 6512
6240 6513
6241 static MaybeObject* Runtime_StringCompare(Arguments args) { 6514 static MaybeObject* Runtime_StringCompare(RUNTIME_CALLING_CONVENTION) {
6515 RUNTIME_GET_ISOLATE;
6242 NoHandleAllocation ha; 6516 NoHandleAllocation ha;
6243 ASSERT(args.length() == 2); 6517 ASSERT(args.length() == 2);
6244 6518
6245 CONVERT_CHECKED(String, x, args[0]); 6519 CONVERT_CHECKED(String, x, args[0]);
6246 CONVERT_CHECKED(String, y, args[1]); 6520 CONVERT_CHECKED(String, y, args[1]);
6247 6521
6248 Counters::string_compare_runtime.Increment(); 6522 isolate->counters()->string_compare_runtime()->Increment();
6249 6523
6250 // A few fast case tests before we flatten. 6524 // A few fast case tests before we flatten.
6251 if (x == y) return Smi::FromInt(EQUAL); 6525 if (x == y) return Smi::FromInt(EQUAL);
6252 if (y->length() == 0) { 6526 if (y->length() == 0) {
6253 if (x->length() == 0) return Smi::FromInt(EQUAL); 6527 if (x->length() == 0) return Smi::FromInt(EQUAL);
6254 return Smi::FromInt(GREATER); 6528 return Smi::FromInt(GREATER);
6255 } else if (x->length() == 0) { 6529 } else if (x->length() == 0) {
6256 return Smi::FromInt(LESS); 6530 return Smi::FromInt(LESS);
6257 } 6531 }
6258 6532
6259 int d = x->Get(0) - y->Get(0); 6533 int d = x->Get(0) - y->Get(0);
6260 if (d < 0) return Smi::FromInt(LESS); 6534 if (d < 0) return Smi::FromInt(LESS);
6261 else if (d > 0) return Smi::FromInt(GREATER); 6535 else if (d > 0) return Smi::FromInt(GREATER);
6262 6536
6263 Object* obj; 6537 Object* obj;
6264 { MaybeObject* maybe_obj = Heap::PrepareForCompare(x); 6538 { MaybeObject* maybe_obj = isolate->heap()->PrepareForCompare(x);
6265 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 6539 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
6266 } 6540 }
6267 { MaybeObject* maybe_obj = Heap::PrepareForCompare(y); 6541 { MaybeObject* maybe_obj = isolate->heap()->PrepareForCompare(y);
6268 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 6542 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
6269 } 6543 }
6270 6544
6271 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) 6545 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
6272 : StringInputBufferCompare(x, y); 6546 : StringInputBufferCompare(isolate->runtime_state(), x, y);
6273 } 6547 }
6274 6548
6275 6549
6276 static MaybeObject* Runtime_Math_acos(Arguments args) { 6550 static MaybeObject* Runtime_Math_acos(RUNTIME_CALLING_CONVENTION) {
6551 RUNTIME_GET_ISOLATE;
6277 NoHandleAllocation ha; 6552 NoHandleAllocation ha;
6278 ASSERT(args.length() == 1); 6553 ASSERT(args.length() == 1);
6279 Counters::math_acos.Increment(); 6554 isolate->counters()->math_acos()->Increment();
6280 6555
6281 CONVERT_DOUBLE_CHECKED(x, args[0]); 6556 CONVERT_DOUBLE_CHECKED(x, args[0]);
6282 return TranscendentalCache::Get(TranscendentalCache::ACOS, x); 6557 return isolate->transcendental_cache()->Get(TranscendentalCache::ACOS, x);
6283 } 6558 }
6284 6559
6285 6560
6286 static MaybeObject* Runtime_Math_asin(Arguments args) { 6561 static MaybeObject* Runtime_Math_asin(RUNTIME_CALLING_CONVENTION) {
6562 RUNTIME_GET_ISOLATE;
6287 NoHandleAllocation ha; 6563 NoHandleAllocation ha;
6288 ASSERT(args.length() == 1); 6564 ASSERT(args.length() == 1);
6289 Counters::math_asin.Increment(); 6565 isolate->counters()->math_asin()->Increment();
6290 6566
6291 CONVERT_DOUBLE_CHECKED(x, args[0]); 6567 CONVERT_DOUBLE_CHECKED(x, args[0]);
6292 return TranscendentalCache::Get(TranscendentalCache::ASIN, x); 6568 return isolate->transcendental_cache()->Get(TranscendentalCache::ASIN, x);
6293 } 6569 }
6294 6570
6295 6571
6296 static MaybeObject* Runtime_Math_atan(Arguments args) { 6572 static MaybeObject* Runtime_Math_atan(RUNTIME_CALLING_CONVENTION) {
6573 RUNTIME_GET_ISOLATE;
6297 NoHandleAllocation ha; 6574 NoHandleAllocation ha;
6298 ASSERT(args.length() == 1); 6575 ASSERT(args.length() == 1);
6299 Counters::math_atan.Increment(); 6576 isolate->counters()->math_atan()->Increment();
6300 6577
6301 CONVERT_DOUBLE_CHECKED(x, args[0]); 6578 CONVERT_DOUBLE_CHECKED(x, args[0]);
6302 return TranscendentalCache::Get(TranscendentalCache::ATAN, x); 6579 return isolate->transcendental_cache()->Get(TranscendentalCache::ATAN, x);
6303 } 6580 }
6304 6581
6305 6582
6306 static MaybeObject* Runtime_Math_atan2(Arguments args) { 6583 static const double kPiDividedBy4 = 0.78539816339744830962;
6584
6585
6586 static MaybeObject* Runtime_Math_atan2(RUNTIME_CALLING_CONVENTION) {
6587 RUNTIME_GET_ISOLATE;
6307 NoHandleAllocation ha; 6588 NoHandleAllocation ha;
6308 ASSERT(args.length() == 2); 6589 ASSERT(args.length() == 2);
6309 Counters::math_atan2.Increment(); 6590 isolate->counters()->math_atan2()->Increment();
6310 6591
6311 CONVERT_DOUBLE_CHECKED(x, args[0]); 6592 CONVERT_DOUBLE_CHECKED(x, args[0]);
6312 CONVERT_DOUBLE_CHECKED(y, args[1]); 6593 CONVERT_DOUBLE_CHECKED(y, args[1]);
6313 double result; 6594 double result;
6314 if (isinf(x) && isinf(y)) { 6595 if (isinf(x) && isinf(y)) {
6315 // Make sure that the result in case of two infinite arguments 6596 // Make sure that the result in case of two infinite arguments
6316 // is a multiple of Pi / 4. The sign of the result is determined 6597 // is a multiple of Pi / 4. The sign of the result is determined
6317 // by the first argument (x) and the sign of the second argument 6598 // by the first argument (x) and the sign of the second argument
6318 // determines the multiplier: one or three. 6599 // determines the multiplier: one or three.
6319 static double kPiDividedBy4 = 0.78539816339744830962;
6320 int multiplier = (x < 0) ? -1 : 1; 6600 int multiplier = (x < 0) ? -1 : 1;
6321 if (y < 0) multiplier *= 3; 6601 if (y < 0) multiplier *= 3;
6322 result = multiplier * kPiDividedBy4; 6602 result = multiplier * kPiDividedBy4;
6323 } else { 6603 } else {
6324 result = atan2(x, y); 6604 result = atan2(x, y);
6325 } 6605 }
6326 return Heap::AllocateHeapNumber(result); 6606 return isolate->heap()->AllocateHeapNumber(result);
6327 } 6607 }
6328 6608
6329 6609
6330 static MaybeObject* Runtime_Math_ceil(Arguments args) { 6610 static MaybeObject* Runtime_Math_ceil(RUNTIME_CALLING_CONVENTION) {
6611 RUNTIME_GET_ISOLATE;
6331 NoHandleAllocation ha; 6612 NoHandleAllocation ha;
6332 ASSERT(args.length() == 1); 6613 ASSERT(args.length() == 1);
6333 Counters::math_ceil.Increment(); 6614 isolate->counters()->math_ceil()->Increment();
6334 6615
6335 CONVERT_DOUBLE_CHECKED(x, args[0]); 6616 CONVERT_DOUBLE_CHECKED(x, args[0]);
6336 return Heap::NumberFromDouble(ceiling(x)); 6617 return isolate->heap()->NumberFromDouble(ceiling(x));
6337 } 6618 }
6338 6619
6339 6620
6340 static MaybeObject* Runtime_Math_cos(Arguments args) { 6621 static MaybeObject* Runtime_Math_cos(RUNTIME_CALLING_CONVENTION) {
6622 RUNTIME_GET_ISOLATE;
6341 NoHandleAllocation ha; 6623 NoHandleAllocation ha;
6342 ASSERT(args.length() == 1); 6624 ASSERT(args.length() == 1);
6343 Counters::math_cos.Increment(); 6625 isolate->counters()->math_cos()->Increment();
6344 6626
6345 CONVERT_DOUBLE_CHECKED(x, args[0]); 6627 CONVERT_DOUBLE_CHECKED(x, args[0]);
6346 return TranscendentalCache::Get(TranscendentalCache::COS, x); 6628 return isolate->transcendental_cache()->Get(TranscendentalCache::COS, x);
6347 } 6629 }
6348 6630
6349 6631
6350 static MaybeObject* Runtime_Math_exp(Arguments args) { 6632 static MaybeObject* Runtime_Math_exp(RUNTIME_CALLING_CONVENTION) {
6633 RUNTIME_GET_ISOLATE;
6351 NoHandleAllocation ha; 6634 NoHandleAllocation ha;
6352 ASSERT(args.length() == 1); 6635 ASSERT(args.length() == 1);
6353 Counters::math_exp.Increment(); 6636 isolate->counters()->math_exp()->Increment();
6354 6637
6355 CONVERT_DOUBLE_CHECKED(x, args[0]); 6638 CONVERT_DOUBLE_CHECKED(x, args[0]);
6356 return TranscendentalCache::Get(TranscendentalCache::EXP, x); 6639 return isolate->transcendental_cache()->Get(TranscendentalCache::EXP, x);
6357 } 6640 }
6358 6641
6359 6642
6360 static MaybeObject* Runtime_Math_floor(Arguments args) { 6643 static MaybeObject* Runtime_Math_floor(RUNTIME_CALLING_CONVENTION) {
6644 RUNTIME_GET_ISOLATE;
6361 NoHandleAllocation ha; 6645 NoHandleAllocation ha;
6362 ASSERT(args.length() == 1); 6646 ASSERT(args.length() == 1);
6363 Counters::math_floor.Increment(); 6647 isolate->counters()->math_floor()->Increment();
6364 6648
6365 CONVERT_DOUBLE_CHECKED(x, args[0]); 6649 CONVERT_DOUBLE_CHECKED(x, args[0]);
6366 return Heap::NumberFromDouble(floor(x)); 6650 return isolate->heap()->NumberFromDouble(floor(x));
6367 } 6651 }
6368 6652
6369 6653
6370 static MaybeObject* Runtime_Math_log(Arguments args) { 6654 static MaybeObject* Runtime_Math_log(RUNTIME_CALLING_CONVENTION) {
6655 RUNTIME_GET_ISOLATE;
6371 NoHandleAllocation ha; 6656 NoHandleAllocation ha;
6372 ASSERT(args.length() == 1); 6657 ASSERT(args.length() == 1);
6373 Counters::math_log.Increment(); 6658 isolate->counters()->math_log()->Increment();
6374 6659
6375 CONVERT_DOUBLE_CHECKED(x, args[0]); 6660 CONVERT_DOUBLE_CHECKED(x, args[0]);
6376 return TranscendentalCache::Get(TranscendentalCache::LOG, x); 6661 return isolate->transcendental_cache()->Get(TranscendentalCache::LOG, x);
6377 } 6662 }
6378 6663
6379 6664
6380 static MaybeObject* Runtime_Math_pow(Arguments args) { 6665 static MaybeObject* Runtime_Math_pow(RUNTIME_CALLING_CONVENTION) {
6666 RUNTIME_GET_ISOLATE;
6381 NoHandleAllocation ha; 6667 NoHandleAllocation ha;
6382 ASSERT(args.length() == 2); 6668 ASSERT(args.length() == 2);
6383 Counters::math_pow.Increment(); 6669 isolate->counters()->math_pow()->Increment();
6384 6670
6385 CONVERT_DOUBLE_CHECKED(x, args[0]); 6671 CONVERT_DOUBLE_CHECKED(x, args[0]);
6386 6672
6387 // If the second argument is a smi, it is much faster to call the 6673 // If the second argument is a smi, it is much faster to call the
6388 // custom powi() function than the generic pow(). 6674 // custom powi() function than the generic pow().
6389 if (args[1]->IsSmi()) { 6675 if (args[1]->IsSmi()) {
6390 int y = Smi::cast(args[1])->value(); 6676 int y = Smi::cast(args[1])->value();
6391 return Heap::NumberFromDouble(power_double_int(x, y)); 6677 return isolate->heap()->NumberFromDouble(power_double_int(x, y));
6392 } 6678 }
6393 6679
6394 CONVERT_DOUBLE_CHECKED(y, args[1]); 6680 CONVERT_DOUBLE_CHECKED(y, args[1]);
6395 return Heap::AllocateHeapNumber(power_double_double(x, y)); 6681 return isolate->heap()->AllocateHeapNumber(power_double_double(x, y));
6396 } 6682 }
6397 6683
6398 // Fast version of Math.pow if we know that y is not an integer and 6684 // Fast version of Math.pow if we know that y is not an integer and
6399 // y is not -0.5 or 0.5. Used as slowcase from codegen. 6685 // y is not -0.5 or 0.5. Used as slowcase from codegen.
6400 static MaybeObject* Runtime_Math_pow_cfunction(Arguments args) { 6686 static MaybeObject* Runtime_Math_pow_cfunction(RUNTIME_CALLING_CONVENTION) {
6687 RUNTIME_GET_ISOLATE;
6401 NoHandleAllocation ha; 6688 NoHandleAllocation ha;
6402 ASSERT(args.length() == 2); 6689 ASSERT(args.length() == 2);
6403 CONVERT_DOUBLE_CHECKED(x, args[0]); 6690 CONVERT_DOUBLE_CHECKED(x, args[0]);
6404 CONVERT_DOUBLE_CHECKED(y, args[1]); 6691 CONVERT_DOUBLE_CHECKED(y, args[1]);
6405 if (y == 0) { 6692 if (y == 0) {
6406 return Smi::FromInt(1); 6693 return Smi::FromInt(1);
6407 } else if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) { 6694 } else if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
6408 return Heap::nan_value(); 6695 return isolate->heap()->nan_value();
6409 } else { 6696 } else {
6410 return Heap::AllocateHeapNumber(pow(x, y)); 6697 return isolate->heap()->AllocateHeapNumber(pow(x, y));
6411 } 6698 }
6412 } 6699 }
6413 6700
6414 6701
6415 static MaybeObject* Runtime_RoundNumber(Arguments args) { 6702 static MaybeObject* Runtime_RoundNumber(RUNTIME_CALLING_CONVENTION) {
6703 RUNTIME_GET_ISOLATE;
6416 NoHandleAllocation ha; 6704 NoHandleAllocation ha;
6417 ASSERT(args.length() == 1); 6705 ASSERT(args.length() == 1);
6418 Counters::math_round.Increment(); 6706 isolate->counters()->math_round()->Increment();
6419 6707
6420 if (!args[0]->IsHeapNumber()) { 6708 if (!args[0]->IsHeapNumber()) {
6421 // Must be smi. Return the argument unchanged for all the other types 6709 // Must be smi. Return the argument unchanged for all the other types
6422 // to make fuzz-natives test happy. 6710 // to make fuzz-natives test happy.
6423 return args[0]; 6711 return args[0];
6424 } 6712 }
6425 6713
6426 HeapNumber* number = reinterpret_cast<HeapNumber*>(args[0]); 6714 HeapNumber* number = reinterpret_cast<HeapNumber*>(args[0]);
6427 6715
6428 double value = number->value(); 6716 double value = number->value();
6429 int exponent = number->get_exponent(); 6717 int exponent = number->get_exponent();
6430 int sign = number->get_sign(); 6718 int sign = number->get_sign();
6431 6719
6432 // We compare with kSmiValueSize - 3 because (2^30 - 0.1) has exponent 29 and 6720 // We compare with kSmiValueSize - 3 because (2^30 - 0.1) has exponent 29 and
6433 // should be rounded to 2^30, which is not smi. 6721 // should be rounded to 2^30, which is not smi.
6434 if (!sign && exponent <= kSmiValueSize - 3) { 6722 if (!sign && exponent <= kSmiValueSize - 3) {
6435 return Smi::FromInt(static_cast<int>(value + 0.5)); 6723 return Smi::FromInt(static_cast<int>(value + 0.5));
6436 } 6724 }
6437 6725
6438 // If the magnitude is big enough, there's no place for fraction part. If we 6726 // If the magnitude is big enough, there's no place for fraction part. If we
6439 // try to add 0.5 to this number, 1.0 will be added instead. 6727 // try to add 0.5 to this number, 1.0 will be added instead.
6440 if (exponent >= 52) { 6728 if (exponent >= 52) {
6441 return number; 6729 return number;
6442 } 6730 }
6443 6731
6444 if (sign && value >= -0.5) return Heap::minus_zero_value(); 6732 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value();
6445 6733
6446 // Do not call NumberFromDouble() to avoid extra checks. 6734 // Do not call NumberFromDouble() to avoid extra checks.
6447 return Heap::AllocateHeapNumber(floor(value + 0.5)); 6735 return isolate->heap()->AllocateHeapNumber(floor(value + 0.5));
6448 } 6736 }
6449 6737
6450 6738
6451 static MaybeObject* Runtime_Math_sin(Arguments args) { 6739 static MaybeObject* Runtime_Math_sin(RUNTIME_CALLING_CONVENTION) {
6740 RUNTIME_GET_ISOLATE;
6452 NoHandleAllocation ha; 6741 NoHandleAllocation ha;
6453 ASSERT(args.length() == 1); 6742 ASSERT(args.length() == 1);
6454 Counters::math_sin.Increment(); 6743 isolate->counters()->math_sin()->Increment();
6455 6744
6456 CONVERT_DOUBLE_CHECKED(x, args[0]); 6745 CONVERT_DOUBLE_CHECKED(x, args[0]);
6457 return TranscendentalCache::Get(TranscendentalCache::SIN, x); 6746 return isolate->transcendental_cache()->Get(TranscendentalCache::SIN, x);
6458 } 6747 }
6459 6748
6460 6749
6461 static MaybeObject* Runtime_Math_sqrt(Arguments args) { 6750 static MaybeObject* Runtime_Math_sqrt(RUNTIME_CALLING_CONVENTION) {
6751 RUNTIME_GET_ISOLATE;
6462 NoHandleAllocation ha; 6752 NoHandleAllocation ha;
6463 ASSERT(args.length() == 1); 6753 ASSERT(args.length() == 1);
6464 Counters::math_sqrt.Increment(); 6754 isolate->counters()->math_sqrt()->Increment();
6465 6755
6466 CONVERT_DOUBLE_CHECKED(x, args[0]); 6756 CONVERT_DOUBLE_CHECKED(x, args[0]);
6467 return Heap::AllocateHeapNumber(sqrt(x)); 6757 return isolate->heap()->AllocateHeapNumber(sqrt(x));
6468 } 6758 }
6469 6759
6470 6760
6471 static MaybeObject* Runtime_Math_tan(Arguments args) { 6761 static MaybeObject* Runtime_Math_tan(RUNTIME_CALLING_CONVENTION) {
6762 RUNTIME_GET_ISOLATE;
6472 NoHandleAllocation ha; 6763 NoHandleAllocation ha;
6473 ASSERT(args.length() == 1); 6764 ASSERT(args.length() == 1);
6474 Counters::math_tan.Increment(); 6765 isolate->counters()->math_tan()->Increment();
6475 6766
6476 CONVERT_DOUBLE_CHECKED(x, args[0]); 6767 CONVERT_DOUBLE_CHECKED(x, args[0]);
6477 return TranscendentalCache::Get(TranscendentalCache::TAN, x); 6768 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
6478 } 6769 }
6479 6770
6480 6771
6481 static int MakeDay(int year, int month, int day) { 6772 static int MakeDay(int year, int month, int day) {
6482 static const int day_from_month[] = {0, 31, 59, 90, 120, 151, 6773 static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
6483 181, 212, 243, 273, 304, 334}; 6774 181, 212, 243, 273, 304, 334};
6484 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152, 6775 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
6485 182, 213, 244, 274, 305, 335}; 6776 182, 213, 244, 274, 305, 335};
6486 6777
6487 year += month / 12; 6778 year += month / 12;
(...skipping 28 matching lines...) Expand all
6516 base_day; 6807 base_day;
6517 6808
6518 if (year % 4 || (year % 100 == 0 && year % 400 != 0)) { 6809 if (year % 4 || (year % 100 == 0 && year % 400 != 0)) {
6519 return day_from_year + day_from_month[month] + day - 1; 6810 return day_from_year + day_from_month[month] + day - 1;
6520 } 6811 }
6521 6812
6522 return day_from_year + day_from_month_leap[month] + day - 1; 6813 return day_from_year + day_from_month_leap[month] + day - 1;
6523 } 6814 }
6524 6815
6525 6816
6526 static MaybeObject* Runtime_DateMakeDay(Arguments args) { 6817 static MaybeObject* Runtime_DateMakeDay(RUNTIME_CALLING_CONVENTION) {
6818 RUNTIME_GET_ISOLATE;
6527 NoHandleAllocation ha; 6819 NoHandleAllocation ha;
6528 ASSERT(args.length() == 3); 6820 ASSERT(args.length() == 3);
6529 6821
6530 CONVERT_SMI_CHECKED(year, args[0]); 6822 CONVERT_SMI_CHECKED(year, args[0]);
6531 CONVERT_SMI_CHECKED(month, args[1]); 6823 CONVERT_SMI_CHECKED(month, args[1]);
6532 CONVERT_SMI_CHECKED(date, args[2]); 6824 CONVERT_SMI_CHECKED(date, args[2]);
6533 6825
6534 return Smi::FromInt(MakeDay(year, month, date)); 6826 return Smi::FromInt(MakeDay(year, month, date));
6535 } 6827 }
6536 6828
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
6815 static inline void DateYMDFromTime(int date, 7107 static inline void DateYMDFromTime(int date,
6816 int& year, int& month, int& day) { 7108 int& year, int& month, int& day) {
6817 if (date >= 0 && date < 32 * kDaysIn4Years) { 7109 if (date >= 0 && date < 32 * kDaysIn4Years) {
6818 DateYMDFromTimeAfter1970(date, year, month, day); 7110 DateYMDFromTimeAfter1970(date, year, month, day);
6819 } else { 7111 } else {
6820 DateYMDFromTimeSlow(date, year, month, day); 7112 DateYMDFromTimeSlow(date, year, month, day);
6821 } 7113 }
6822 } 7114 }
6823 7115
6824 7116
6825 static MaybeObject* Runtime_DateYMDFromTime(Arguments args) { 7117 static MaybeObject* Runtime_DateYMDFromTime(RUNTIME_CALLING_CONVENTION) {
7118 RUNTIME_GET_ISOLATE;
6826 NoHandleAllocation ha; 7119 NoHandleAllocation ha;
6827 ASSERT(args.length() == 2); 7120 ASSERT(args.length() == 2);
6828 7121
6829 CONVERT_DOUBLE_CHECKED(t, args[0]); 7122 CONVERT_DOUBLE_CHECKED(t, args[0]);
6830 CONVERT_CHECKED(JSArray, res_array, args[1]); 7123 CONVERT_CHECKED(JSArray, res_array, args[1]);
6831 7124
6832 int year, month, day; 7125 int year, month, day;
6833 DateYMDFromTime(static_cast<int>(floor(t / 86400000)), year, month, day); 7126 DateYMDFromTime(static_cast<int>(floor(t / 86400000)), year, month, day);
6834 7127
6835 RUNTIME_ASSERT(res_array->elements()->map() == Heap::fixed_array_map()); 7128 RUNTIME_ASSERT(res_array->elements()->map() ==
7129 isolate->heap()->fixed_array_map());
6836 FixedArray* elms = FixedArray::cast(res_array->elements()); 7130 FixedArray* elms = FixedArray::cast(res_array->elements());
6837 RUNTIME_ASSERT(elms->length() == 3); 7131 RUNTIME_ASSERT(elms->length() == 3);
6838 7132
6839 elms->set(0, Smi::FromInt(year)); 7133 elms->set(0, Smi::FromInt(year));
6840 elms->set(1, Smi::FromInt(month)); 7134 elms->set(1, Smi::FromInt(month));
6841 elms->set(2, Smi::FromInt(day)); 7135 elms->set(2, Smi::FromInt(day));
6842 7136
6843 return Heap::undefined_value(); 7137 return isolate->heap()->undefined_value();
6844 } 7138 }
6845 7139
6846 7140
6847 static MaybeObject* Runtime_NewArgumentsFast(Arguments args) { 7141 static MaybeObject* Runtime_NewArgumentsFast(RUNTIME_CALLING_CONVENTION) {
7142 RUNTIME_GET_ISOLATE;
6848 NoHandleAllocation ha; 7143 NoHandleAllocation ha;
6849 ASSERT(args.length() == 3); 7144 ASSERT(args.length() == 3);
6850 7145
6851 JSFunction* callee = JSFunction::cast(args[0]); 7146 JSFunction* callee = JSFunction::cast(args[0]);
6852 Object** parameters = reinterpret_cast<Object**>(args[1]); 7147 Object** parameters = reinterpret_cast<Object**>(args[1]);
6853 const int length = Smi::cast(args[2])->value(); 7148 const int length = Smi::cast(args[2])->value();
6854 7149
6855 Object* result; 7150 Object* result;
6856 { MaybeObject* maybe_result = Heap::AllocateArgumentsObject(callee, length); 7151 { MaybeObject* maybe_result =
7152 isolate->heap()->AllocateArgumentsObject(callee, length);
6857 if (!maybe_result->ToObject(&result)) return maybe_result; 7153 if (!maybe_result->ToObject(&result)) return maybe_result;
6858 } 7154 }
6859 // Allocate the elements if needed. 7155 // Allocate the elements if needed.
6860 if (length > 0) { 7156 if (length > 0) {
6861 // Allocate the fixed array. 7157 // Allocate the fixed array.
6862 Object* obj; 7158 Object* obj;
6863 { MaybeObject* maybe_obj = Heap::AllocateRawFixedArray(length); 7159 { MaybeObject* maybe_obj = isolate->heap()->AllocateRawFixedArray(length);
6864 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 7160 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
6865 } 7161 }
6866 7162
6867 AssertNoAllocation no_gc; 7163 AssertNoAllocation no_gc;
6868 FixedArray* array = reinterpret_cast<FixedArray*>(obj); 7164 FixedArray* array = reinterpret_cast<FixedArray*>(obj);
6869 array->set_map(Heap::fixed_array_map()); 7165 array->set_map(isolate->heap()->fixed_array_map());
6870 array->set_length(length); 7166 array->set_length(length);
6871 7167
6872 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); 7168 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc);
6873 for (int i = 0; i < length; i++) { 7169 for (int i = 0; i < length; i++) {
6874 array->set(i, *--parameters, mode); 7170 array->set(i, *--parameters, mode);
6875 } 7171 }
6876 JSObject::cast(result)->set_elements(FixedArray::cast(obj)); 7172 JSObject::cast(result)->set_elements(FixedArray::cast(obj));
6877 } 7173 }
6878 return result; 7174 return result;
6879 } 7175 }
6880 7176
6881 7177
6882 static MaybeObject* Runtime_NewClosure(Arguments args) { 7178 static MaybeObject* Runtime_NewClosure(RUNTIME_CALLING_CONVENTION) {
6883 HandleScope scope; 7179 RUNTIME_GET_ISOLATE;
7180 HandleScope scope(isolate);
6884 ASSERT(args.length() == 3); 7181 ASSERT(args.length() == 3);
6885 CONVERT_ARG_CHECKED(Context, context, 0); 7182 CONVERT_ARG_CHECKED(Context, context, 0);
6886 CONVERT_ARG_CHECKED(SharedFunctionInfo, shared, 1); 7183 CONVERT_ARG_CHECKED(SharedFunctionInfo, shared, 1);
6887 CONVERT_BOOLEAN_CHECKED(pretenure, args[2]); 7184 CONVERT_BOOLEAN_CHECKED(pretenure, args[2]);
6888 7185
6889 // Allocate global closures in old space and allocate local closures 7186 // Allocate global closures in old space and allocate local closures
6890 // in new space. Additionally pretenure closures that are assigned 7187 // in new space. Additionally pretenure closures that are assigned
6891 // directly to properties. 7188 // directly to properties.
6892 pretenure = pretenure || (context->global_context() == *context); 7189 pretenure = pretenure || (context->global_context() == *context);
6893 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; 7190 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED;
6894 Handle<JSFunction> result = 7191 Handle<JSFunction> result =
6895 Factory::NewFunctionFromSharedFunctionInfo(shared, 7192 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
6896 context, 7193 context,
6897 pretenure_flag); 7194 pretenure_flag);
6898 return *result; 7195 return *result;
6899 } 7196 }
6900 7197
6901 7198 static MaybeObject* Runtime_NewObjectFromBound(RUNTIME_CALLING_CONVENTION) {
6902 static MaybeObject* Runtime_NewObjectFromBound(Arguments args) { 7199 RUNTIME_GET_ISOLATE;
6903 HandleScope scope; 7200 HandleScope scope(isolate);
6904 ASSERT(args.length() == 2); 7201 ASSERT(args.length() == 2);
6905 // First argument is a function to use as a constructor. 7202 // First argument is a function to use as a constructor.
6906 CONVERT_ARG_CHECKED(JSFunction, function, 0); 7203 CONVERT_ARG_CHECKED(JSFunction, function, 0);
6907 7204
6908 // Second argument is either null or an array of bound arguments. 7205 // Second argument is either null or an array of bound arguments.
6909 FixedArray* bound_args = NULL; 7206 FixedArray* bound_args = NULL;
6910 int bound_argc = 0; 7207 int bound_argc = 0;
6911 if (!args[1]->IsNull()) { 7208 if (!args[1]->IsNull()) {
6912 CONVERT_ARG_CHECKED(JSArray, params, 1); 7209 CONVERT_ARG_CHECKED(JSArray, params, 1);
6913 RUNTIME_ASSERT(params->HasFastElements()); 7210 RUNTIME_ASSERT(params->HasFastElements());
(...skipping 26 matching lines...) Expand all
6940 Execution::New(function, total_argc, *param_data, &exception); 7237 Execution::New(function, total_argc, *param_data, &exception);
6941 if (exception) { 7238 if (exception) {
6942 return Failure::Exception(); 7239 return Failure::Exception();
6943 } 7240 }
6944 7241
6945 ASSERT(!result.is_null()); 7242 ASSERT(!result.is_null());
6946 return *result; 7243 return *result;
6947 } 7244 }
6948 7245
6949 7246
6950 static void TrySettingInlineConstructStub(Handle<JSFunction> function) { 7247 static void TrySettingInlineConstructStub(Isolate* isolate,
6951 Handle<Object> prototype = Factory::null_value(); 7248 Handle<JSFunction> function) {
7249 Handle<Object> prototype = isolate->factory()->null_value();
6952 if (function->has_instance_prototype()) { 7250 if (function->has_instance_prototype()) {
6953 prototype = Handle<Object>(function->instance_prototype()); 7251 prototype = Handle<Object>(function->instance_prototype(), isolate);
6954 } 7252 }
6955 if (function->shared()->CanGenerateInlineConstructor(*prototype)) { 7253 if (function->shared()->CanGenerateInlineConstructor(*prototype)) {
6956 ConstructStubCompiler compiler; 7254 ConstructStubCompiler compiler;
6957 MaybeObject* code = compiler.CompileConstructStub(*function); 7255 MaybeObject* code = compiler.CompileConstructStub(*function);
6958 if (!code->IsFailure()) { 7256 if (!code->IsFailure()) {
6959 function->shared()->set_construct_stub( 7257 function->shared()->set_construct_stub(
6960 Code::cast(code->ToObjectUnchecked())); 7258 Code::cast(code->ToObjectUnchecked()));
6961 } 7259 }
6962 } 7260 }
6963 } 7261 }
6964 7262
6965 7263
6966 static MaybeObject* Runtime_NewObject(Arguments args) { 7264 static MaybeObject* Runtime_NewObject(RUNTIME_CALLING_CONVENTION) {
6967 HandleScope scope; 7265 RUNTIME_GET_ISOLATE;
7266 HandleScope scope(isolate);
6968 ASSERT(args.length() == 1); 7267 ASSERT(args.length() == 1);
6969 7268
6970 Handle<Object> constructor = args.at<Object>(0); 7269 Handle<Object> constructor = args.at<Object>(0);
6971 7270
6972 // If the constructor isn't a proper function we throw a type error. 7271 // If the constructor isn't a proper function we throw a type error.
6973 if (!constructor->IsJSFunction()) { 7272 if (!constructor->IsJSFunction()) {
6974 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1); 7273 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1);
6975 Handle<Object> type_error = 7274 Handle<Object> type_error =
6976 Factory::NewTypeError("not_constructor", arguments); 7275 isolate->factory()->NewTypeError("not_constructor", arguments);
6977 return Top::Throw(*type_error); 7276 return isolate->Throw(*type_error);
6978 } 7277 }
6979 7278
6980 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor); 7279 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor);
6981 7280
6982 // If function should not have prototype, construction is not allowed. In this 7281 // If function should not have prototype, construction is not allowed. In this
6983 // case generated code bailouts here, since function has no initial_map. 7282 // case generated code bailouts here, since function has no initial_map.
6984 if (!function->should_have_prototype()) { 7283 if (!function->should_have_prototype()) {
6985 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1); 7284 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1);
6986 Handle<Object> type_error = 7285 Handle<Object> type_error =
6987 Factory::NewTypeError("not_constructor", arguments); 7286 isolate->factory()->NewTypeError("not_constructor", arguments);
6988 return Top::Throw(*type_error); 7287 return isolate->Throw(*type_error);
6989 } 7288 }
6990 7289
6991 #ifdef ENABLE_DEBUGGER_SUPPORT 7290 #ifdef ENABLE_DEBUGGER_SUPPORT
7291 Debug* debug = isolate->debug();
6992 // Handle stepping into constructors if step into is active. 7292 // Handle stepping into constructors if step into is active.
6993 if (Debug::StepInActive()) { 7293 if (debug->StepInActive()) {
6994 Debug::HandleStepIn(function, Handle<Object>::null(), 0, true); 7294 debug->HandleStepIn(function, Handle<Object>::null(), 0, true);
6995 } 7295 }
6996 #endif 7296 #endif
6997 7297
6998 if (function->has_initial_map()) { 7298 if (function->has_initial_map()) {
6999 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { 7299 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) {
7000 // The 'Function' function ignores the receiver object when 7300 // The 'Function' function ignores the receiver object when
7001 // called using 'new' and creates a new JSFunction object that 7301 // called using 'new' and creates a new JSFunction object that
7002 // is returned. The receiver object is only used for error 7302 // is returned. The receiver object is only used for error
7003 // reporting if an error occurs when constructing the new 7303 // reporting if an error occurs when constructing the new
7004 // JSFunction. Factory::NewJSObject() should not be used to 7304 // JSFunction. FACTORY->NewJSObject() should not be used to
7005 // allocate JSFunctions since it does not properly initialize 7305 // allocate JSFunctions since it does not properly initialize
7006 // the shared part of the function. Since the receiver is 7306 // the shared part of the function. Since the receiver is
7007 // ignored anyway, we use the global object as the receiver 7307 // ignored anyway, we use the global object as the receiver
7008 // instead of a new JSFunction object. This way, errors are 7308 // instead of a new JSFunction object. This way, errors are
7009 // reported the same way whether or not 'Function' is called 7309 // reported the same way whether or not 'Function' is called
7010 // using 'new'. 7310 // using 'new'.
7011 return Top::context()->global(); 7311 return isolate->context()->global();
7012 } 7312 }
7013 } 7313 }
7014 7314
7015 // The function should be compiled for the optimization hints to be 7315 // The function should be compiled for the optimization hints to be
7016 // available. We cannot use EnsureCompiled because that forces a 7316 // available. We cannot use EnsureCompiled because that forces a
7017 // compilation through the shared function info which makes it 7317 // compilation through the shared function info which makes it
7018 // impossible for us to optimize. 7318 // impossible for us to optimize.
7019 Handle<SharedFunctionInfo> shared(function->shared()); 7319 Handle<SharedFunctionInfo> shared(function->shared(), isolate);
7020 if (!function->is_compiled()) CompileLazy(function, CLEAR_EXCEPTION); 7320 if (!function->is_compiled()) CompileLazy(function, CLEAR_EXCEPTION);
7021 7321
7022 if (!function->has_initial_map() && 7322 if (!function->has_initial_map() &&
7023 shared->IsInobjectSlackTrackingInProgress()) { 7323 shared->IsInobjectSlackTrackingInProgress()) {
7024 // The tracking is already in progress for another function. We can only 7324 // The tracking is already in progress for another function. We can only
7025 // track one initial_map at a time, so we force the completion before the 7325 // track one initial_map at a time, so we force the completion before the
7026 // function is called as a constructor for the first time. 7326 // function is called as a constructor for the first time.
7027 shared->CompleteInobjectSlackTracking(); 7327 shared->CompleteInobjectSlackTracking();
7028 } 7328 }
7029 7329
7030 bool first_allocation = !shared->live_objects_may_exist(); 7330 bool first_allocation = !shared->live_objects_may_exist();
7031 Handle<JSObject> result = Factory::NewJSObject(function); 7331 Handle<JSObject> result = isolate->factory()->NewJSObject(function);
7032 RETURN_IF_EMPTY_HANDLE(result); 7332 RETURN_IF_EMPTY_HANDLE(isolate, result);
7033 // Delay setting the stub if inobject slack tracking is in progress. 7333 // Delay setting the stub if inobject slack tracking is in progress.
7034 if (first_allocation && !shared->IsInobjectSlackTrackingInProgress()) { 7334 if (first_allocation && !shared->IsInobjectSlackTrackingInProgress()) {
7035 TrySettingInlineConstructStub(function); 7335 TrySettingInlineConstructStub(isolate, function);
7036 } 7336 }
7037 7337
7038 Counters::constructed_objects.Increment(); 7338 isolate->counters()->constructed_objects()->Increment();
7039 Counters::constructed_objects_runtime.Increment(); 7339 isolate->counters()->constructed_objects_runtime()->Increment();
7040 7340
7041 return *result; 7341 return *result;
7042 } 7342 }
7043 7343
7044 7344
7045 static MaybeObject* Runtime_FinalizeInstanceSize(Arguments args) { 7345 static MaybeObject* Runtime_FinalizeInstanceSize(RUNTIME_CALLING_CONVENTION) {
7046 HandleScope scope; 7346 RUNTIME_GET_ISOLATE;
7347 HandleScope scope(isolate);
7047 ASSERT(args.length() == 1); 7348 ASSERT(args.length() == 1);
7048 7349
7049 CONVERT_ARG_CHECKED(JSFunction, function, 0); 7350 CONVERT_ARG_CHECKED(JSFunction, function, 0);
7050 function->shared()->CompleteInobjectSlackTracking(); 7351 function->shared()->CompleteInobjectSlackTracking();
7051 TrySettingInlineConstructStub(function); 7352 TrySettingInlineConstructStub(isolate, function);
7052 7353
7053 return Heap::undefined_value(); 7354 return isolate->heap()->undefined_value();
7054 } 7355 }
7055 7356
7056 7357
7057 static MaybeObject* Runtime_LazyCompile(Arguments args) { 7358 static MaybeObject* Runtime_LazyCompile(RUNTIME_CALLING_CONVENTION) {
7058 HandleScope scope; 7359 RUNTIME_GET_ISOLATE;
7360 HandleScope scope(isolate);
7059 ASSERT(args.length() == 1); 7361 ASSERT(args.length() == 1);
7060 7362
7061 Handle<JSFunction> function = args.at<JSFunction>(0); 7363 Handle<JSFunction> function = args.at<JSFunction>(0);
7062 #ifdef DEBUG 7364 #ifdef DEBUG
7063 if (FLAG_trace_lazy && !function->shared()->is_compiled()) { 7365 if (FLAG_trace_lazy && !function->shared()->is_compiled()) {
7064 PrintF("[lazy: "); 7366 PrintF("[lazy: ");
7065 function->PrintName(); 7367 function->PrintName();
7066 PrintF("]\n"); 7368 PrintF("]\n");
7067 } 7369 }
7068 #endif 7370 #endif
7069 7371
7070 // Compile the target function. Here we compile using CompileLazyInLoop in 7372 // Compile the target function. Here we compile using CompileLazyInLoop in
7071 // order to get the optimized version. This helps code like delta-blue 7373 // order to get the optimized version. This helps code like delta-blue
7072 // that calls performance-critical routines through constructors. A 7374 // that calls performance-critical routines through constructors. A
7073 // constructor call doesn't use a CallIC, it uses a LoadIC followed by a 7375 // constructor call doesn't use a CallIC, it uses a LoadIC followed by a
7074 // direct call. Since the in-loop tracking takes place through CallICs 7376 // direct call. Since the in-loop tracking takes place through CallICs
7075 // this means that things called through constructors are never known to 7377 // this means that things called through constructors are never known to
7076 // be in loops. We compile them as if they are in loops here just in case. 7378 // be in loops. We compile them as if they are in loops here just in case.
7077 ASSERT(!function->is_compiled()); 7379 ASSERT(!function->is_compiled());
7078 if (!CompileLazyInLoop(function, KEEP_EXCEPTION)) { 7380 if (!CompileLazyInLoop(function, KEEP_EXCEPTION)) {
7079 return Failure::Exception(); 7381 return Failure::Exception();
7080 } 7382 }
7081 7383
7082 // All done. Return the compiled code. 7384 // All done. Return the compiled code.
7083 ASSERT(function->is_compiled()); 7385 ASSERT(function->is_compiled());
7084 return function->code(); 7386 return function->code();
7085 } 7387 }
7086 7388
7087 7389
7088 static MaybeObject* Runtime_LazyRecompile(Arguments args) { 7390 static MaybeObject* Runtime_LazyRecompile(RUNTIME_CALLING_CONVENTION) {
7089 HandleScope scope; 7391 RUNTIME_GET_ISOLATE;
7392 HandleScope scope(isolate);
7090 ASSERT(args.length() == 1); 7393 ASSERT(args.length() == 1);
7091 Handle<JSFunction> function = args.at<JSFunction>(0); 7394 Handle<JSFunction> function = args.at<JSFunction>(0);
7092 // If the function is not optimizable or debugger is active continue using the 7395 // If the function is not optimizable or debugger is active continue using the
7093 // code from the full compiler. 7396 // code from the full compiler.
7094 if (!function->shared()->code()->optimizable() || 7397 if (!function->shared()->code()->optimizable() ||
7095 Debug::has_break_points()) { 7398 isolate->debug()->has_break_points()) {
7096 if (FLAG_trace_opt) { 7399 if (FLAG_trace_opt) {
7097 PrintF("[failed to optimize "); 7400 PrintF("[failed to optimize ");
7098 function->PrintName(); 7401 function->PrintName();
7099 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", 7402 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n",
7100 function->shared()->code()->optimizable() ? "T" : "F", 7403 function->shared()->code()->optimizable() ? "T" : "F",
7101 Debug::has_break_points() ? "T" : "F"); 7404 isolate->debug()->has_break_points() ? "T" : "F");
7102 } 7405 }
7103 function->ReplaceCode(function->shared()->code()); 7406 function->ReplaceCode(function->shared()->code());
7104 return function->code(); 7407 return function->code();
7105 } 7408 }
7106 if (CompileOptimized(function, AstNode::kNoNumber, CLEAR_EXCEPTION)) { 7409 if (CompileOptimized(function, AstNode::kNoNumber, CLEAR_EXCEPTION)) {
7107 return function->code(); 7410 return function->code();
7108 } 7411 }
7109 if (FLAG_trace_opt) { 7412 if (FLAG_trace_opt) {
7110 PrintF("[failed to optimize "); 7413 PrintF("[failed to optimize ");
7111 function->PrintName(); 7414 function->PrintName();
7112 PrintF(": optimized compilation failed]\n"); 7415 PrintF(": optimized compilation failed]\n");
7113 } 7416 }
7114 function->ReplaceCode(function->shared()->code()); 7417 function->ReplaceCode(function->shared()->code());
7115 return function->code(); 7418 return function->code();
7116 } 7419 }
7117 7420
7118 7421
7119 static MaybeObject* Runtime_NotifyDeoptimized(Arguments args) { 7422 static MaybeObject* Runtime_NotifyDeoptimized(RUNTIME_CALLING_CONVENTION) {
7120 HandleScope scope; 7423 RUNTIME_GET_ISOLATE;
7424 HandleScope scope(isolate);
7121 ASSERT(args.length() == 1); 7425 ASSERT(args.length() == 1);
7122 RUNTIME_ASSERT(args[0]->IsSmi()); 7426 RUNTIME_ASSERT(args[0]->IsSmi());
7123 Deoptimizer::BailoutType type = 7427 Deoptimizer::BailoutType type =
7124 static_cast<Deoptimizer::BailoutType>(Smi::cast(args[0])->value()); 7428 static_cast<Deoptimizer::BailoutType>(Smi::cast(args[0])->value());
7125 Deoptimizer* deoptimizer = Deoptimizer::Grab(); 7429 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
7126 ASSERT(Heap::IsAllocationAllowed()); 7430 ASSERT(isolate->heap()->IsAllocationAllowed());
7127 int frames = deoptimizer->output_count(); 7431 int frames = deoptimizer->output_count();
7128 7432
7129 JavaScriptFrameIterator it; 7433 JavaScriptFrameIterator it;
7130 JavaScriptFrame* frame = NULL; 7434 JavaScriptFrame* frame = NULL;
7131 for (int i = 0; i < frames; i++) { 7435 for (int i = 0; i < frames; i++) {
7132 if (i != 0) it.Advance(); 7436 if (i != 0) it.Advance();
7133 frame = it.frame(); 7437 frame = it.frame();
7134 deoptimizer->InsertHeapNumberValues(frames - i - 1, frame); 7438 deoptimizer->InsertHeapNumberValues(frames - i - 1, frame);
7135 } 7439 }
7136 delete deoptimizer; 7440 delete deoptimizer;
7137 7441
7138 RUNTIME_ASSERT(frame->function()->IsJSFunction()); 7442 RUNTIME_ASSERT(frame->function()->IsJSFunction());
7139 Handle<JSFunction> function(JSFunction::cast(frame->function())); 7443 Handle<JSFunction> function(JSFunction::cast(frame->function()), isolate);
7140 Handle<Object> arguments; 7444 Handle<Object> arguments;
7141 for (int i = frame->ComputeExpressionsCount() - 1; i >= 0; --i) { 7445 for (int i = frame->ComputeExpressionsCount() - 1; i >= 0; --i) {
7142 if (frame->GetExpression(i) == Heap::arguments_marker()) { 7446 if (frame->GetExpression(i) == isolate->heap()->arguments_marker()) {
7143 if (arguments.is_null()) { 7447 if (arguments.is_null()) {
7144 // FunctionGetArguments can't throw an exception, so cast away the 7448 // FunctionGetArguments can't throw an exception, so cast away the
7145 // doubt with an assert. 7449 // doubt with an assert.
7146 arguments = Handle<Object>( 7450 arguments = Handle<Object>(
7147 Accessors::FunctionGetArguments(*function, 7451 Accessors::FunctionGetArguments(*function,
7148 NULL)->ToObjectUnchecked()); 7452 NULL)->ToObjectUnchecked());
7149 ASSERT(*arguments != Heap::null_value()); 7453 ASSERT(*arguments != isolate->heap()->null_value());
7150 ASSERT(*arguments != Heap::undefined_value()); 7454 ASSERT(*arguments != isolate->heap()->undefined_value());
7151 } 7455 }
7152 frame->SetExpression(i, *arguments); 7456 frame->SetExpression(i, *arguments);
7153 } 7457 }
7154 } 7458 }
7155 7459
7156 CompilationCache::MarkForLazyOptimizing(function); 7460 isolate->compilation_cache()->MarkForLazyOptimizing(function);
7157 if (type == Deoptimizer::EAGER) { 7461 if (type == Deoptimizer::EAGER) {
7158 RUNTIME_ASSERT(function->IsOptimized()); 7462 RUNTIME_ASSERT(function->IsOptimized());
7159 } else { 7463 } else {
7160 RUNTIME_ASSERT(!function->IsOptimized()); 7464 RUNTIME_ASSERT(!function->IsOptimized());
7161 } 7465 }
7162 7466
7163 // Avoid doing too much work when running with --always-opt and keep 7467 // Avoid doing too much work when running with --always-opt and keep
7164 // the optimized code around. 7468 // the optimized code around.
7165 if (FLAG_always_opt || type == Deoptimizer::LAZY) { 7469 if (FLAG_always_opt || type == Deoptimizer::LAZY) {
7166 return Heap::undefined_value(); 7470 return isolate->heap()->undefined_value();
7167 } 7471 }
7168 7472
7169 // Count the number of optimized activations of the function. 7473 // Count the number of optimized activations of the function.
7170 int activations = 0; 7474 int activations = 0;
7171 while (!it.done()) { 7475 while (!it.done()) {
7172 JavaScriptFrame* frame = it.frame(); 7476 JavaScriptFrame* frame = it.frame();
7173 if (frame->is_optimized() && frame->function() == *function) { 7477 if (frame->is_optimized() && frame->function() == *function) {
7174 activations++; 7478 activations++;
7175 } 7479 }
7176 it.Advance(); 7480 it.Advance();
7177 } 7481 }
7178 7482
7179 // TODO(kasperl): For now, we cannot support removing the optimized 7483 // TODO(kasperl): For now, we cannot support removing the optimized
7180 // code when we have recursive invocations of the same function. 7484 // code when we have recursive invocations of the same function.
7181 if (activations == 0) { 7485 if (activations == 0) {
7182 if (FLAG_trace_deopt) { 7486 if (FLAG_trace_deopt) {
7183 PrintF("[removing optimized code for: "); 7487 PrintF("[removing optimized code for: ");
7184 function->PrintName(); 7488 function->PrintName();
7185 PrintF("]\n"); 7489 PrintF("]\n");
7186 } 7490 }
7187 function->ReplaceCode(function->shared()->code()); 7491 function->ReplaceCode(function->shared()->code());
7188 } 7492 }
7189 return Heap::undefined_value(); 7493 return isolate->heap()->undefined_value();
7190 } 7494 }
7191 7495
7192 7496
7193 static MaybeObject* Runtime_NotifyOSR(Arguments args) { 7497 static MaybeObject* Runtime_NotifyOSR(RUNTIME_CALLING_CONVENTION) {
7194 Deoptimizer* deoptimizer = Deoptimizer::Grab(); 7498 RUNTIME_GET_ISOLATE;
7499 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
7195 delete deoptimizer; 7500 delete deoptimizer;
7196 return Heap::undefined_value(); 7501 return isolate->heap()->undefined_value();
7197 } 7502 }
7198 7503
7199 7504
7200 static MaybeObject* Runtime_DeoptimizeFunction(Arguments args) { 7505 static MaybeObject* Runtime_DeoptimizeFunction(RUNTIME_CALLING_CONVENTION) {
7201 HandleScope scope; 7506 RUNTIME_GET_ISOLATE;
7507 HandleScope scope(isolate);
7202 ASSERT(args.length() == 1); 7508 ASSERT(args.length() == 1);
7203 CONVERT_ARG_CHECKED(JSFunction, function, 0); 7509 CONVERT_ARG_CHECKED(JSFunction, function, 0);
7204 if (!function->IsOptimized()) return Heap::undefined_value(); 7510 if (!function->IsOptimized()) return isolate->heap()->undefined_value();
7205 7511
7206 Deoptimizer::DeoptimizeFunction(*function); 7512 Deoptimizer::DeoptimizeFunction(*function);
7207 7513
7208 return Heap::undefined_value(); 7514 return isolate->heap()->undefined_value();
7209 } 7515 }
7210 7516
7211 7517
7212 static MaybeObject* Runtime_CompileForOnStackReplacement(Arguments args) { 7518 static MaybeObject* Runtime_CompileForOnStackReplacement(
7213 HandleScope scope; 7519 RUNTIME_CALLING_CONVENTION) {
7520 RUNTIME_GET_ISOLATE;
7521 HandleScope scope(isolate);
7214 ASSERT(args.length() == 1); 7522 ASSERT(args.length() == 1);
7215 CONVERT_ARG_CHECKED(JSFunction, function, 0); 7523 CONVERT_ARG_CHECKED(JSFunction, function, 0);
7216 7524
7217 // We're not prepared to handle a function with arguments object. 7525 // We're not prepared to handle a function with arguments object.
7218 ASSERT(!function->shared()->scope_info()->HasArgumentsShadow()); 7526 ASSERT(!function->shared()->scope_info()->HasArgumentsShadow());
7219 7527
7220 // We have hit a back edge in an unoptimized frame for a function that was 7528 // We have hit a back edge in an unoptimized frame for a function that was
7221 // selected for on-stack replacement. Find the unoptimized code object. 7529 // selected for on-stack replacement. Find the unoptimized code object.
7222 Handle<Code> unoptimized(function->shared()->code()); 7530 Handle<Code> unoptimized(function->shared()->code(), isolate);
7223 // Keep track of whether we've succeeded in optimizing. 7531 // Keep track of whether we've succeeded in optimizing.
7224 bool succeeded = unoptimized->optimizable(); 7532 bool succeeded = unoptimized->optimizable();
7225 if (succeeded) { 7533 if (succeeded) {
7226 // If we are trying to do OSR when there are already optimized 7534 // If we are trying to do OSR when there are already optimized
7227 // activations of the function, it means (a) the function is directly or 7535 // activations of the function, it means (a) the function is directly or
7228 // indirectly recursive and (b) an optimized invocation has been 7536 // indirectly recursive and (b) an optimized invocation has been
7229 // deoptimized so that we are currently in an unoptimized activation. 7537 // deoptimized so that we are currently in an unoptimized activation.
7230 // Check for optimized activations of this function. 7538 // Check for optimized activations of this function.
7231 JavaScriptFrameIterator it; 7539 JavaScriptFrameIterator it;
7232 while (succeeded && !it.done()) { 7540 while (succeeded && !it.done()) {
7233 JavaScriptFrame* frame = it.frame(); 7541 JavaScriptFrame* frame = it.frame();
7234 succeeded = !frame->is_optimized() || frame->function() != *function; 7542 succeeded = !frame->is_optimized() || frame->function() != *function;
7235 it.Advance(); 7543 it.Advance();
7236 } 7544 }
7237 } 7545 }
7238 7546
7239 int ast_id = AstNode::kNoNumber; 7547 int ast_id = AstNode::kNoNumber;
7240 if (succeeded) { 7548 if (succeeded) {
7241 // The top JS function is this one, the PC is somewhere in the 7549 // The top JS function is this one, the PC is somewhere in the
7242 // unoptimized code. 7550 // unoptimized code.
7243 JavaScriptFrameIterator it; 7551 JavaScriptFrameIterator it;
7244 JavaScriptFrame* frame = it.frame(); 7552 JavaScriptFrame* frame = it.frame();
7245 ASSERT(frame->function() == *function); 7553 ASSERT(frame->function() == *function);
7246 ASSERT(frame->code() == *unoptimized); 7554 ASSERT(frame->LookupCode(isolate) == *unoptimized);
7247 ASSERT(unoptimized->contains(frame->pc())); 7555 ASSERT(unoptimized->contains(frame->pc()));
7248 7556
7249 // Use linear search of the unoptimized code's stack check table to find 7557 // Use linear search of the unoptimized code's stack check table to find
7250 // the AST id matching the PC. 7558 // the AST id matching the PC.
7251 Address start = unoptimized->instruction_start(); 7559 Address start = unoptimized->instruction_start();
7252 unsigned target_pc_offset = static_cast<unsigned>(frame->pc() - start); 7560 unsigned target_pc_offset = static_cast<unsigned>(frame->pc() - start);
7253 Address table_cursor = start + unoptimized->stack_check_table_offset(); 7561 Address table_cursor = start + unoptimized->stack_check_table_offset();
7254 uint32_t table_length = Memory::uint32_at(table_cursor); 7562 uint32_t table_length = Memory::uint32_at(table_cursor);
7255 table_cursor += kIntSize; 7563 table_cursor += kIntSize;
7256 for (unsigned i = 0; i < table_length; ++i) { 7564 for (unsigned i = 0; i < table_length; ++i) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7294 7602
7295 // Revert to the original stack checks in the original unoptimized code. 7603 // Revert to the original stack checks in the original unoptimized code.
7296 if (FLAG_trace_osr) { 7604 if (FLAG_trace_osr) {
7297 PrintF("[restoring original stack checks in "); 7605 PrintF("[restoring original stack checks in ");
7298 function->PrintName(); 7606 function->PrintName();
7299 PrintF("]\n"); 7607 PrintF("]\n");
7300 } 7608 }
7301 StackCheckStub check_stub; 7609 StackCheckStub check_stub;
7302 Handle<Code> check_code = check_stub.GetCode(); 7610 Handle<Code> check_code = check_stub.GetCode();
7303 Handle<Code> replacement_code( 7611 Handle<Code> replacement_code(
7304 Builtins::builtin(Builtins::OnStackReplacement)); 7612 isolate->builtins()->builtin(Builtins::OnStackReplacement));
7305 Deoptimizer::RevertStackCheckCode(*unoptimized, 7613 Deoptimizer::RevertStackCheckCode(*unoptimized,
7306 *check_code, 7614 *check_code,
7307 *replacement_code); 7615 *replacement_code);
7308 7616
7309 // Allow OSR only at nesting level zero again. 7617 // Allow OSR only at nesting level zero again.
7310 unoptimized->set_allow_osr_at_loop_nesting_level(0); 7618 unoptimized->set_allow_osr_at_loop_nesting_level(0);
7311 7619
7312 // If the optimization attempt succeeded, return the AST id tagged as a 7620 // If the optimization attempt succeeded, return the AST id tagged as a
7313 // smi. This tells the builtin that we need to translate the unoptimized 7621 // smi. This tells the builtin that we need to translate the unoptimized
7314 // frame to an optimized one. 7622 // frame to an optimized one.
7315 if (succeeded) { 7623 if (succeeded) {
7316 ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION); 7624 ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION);
7317 return Smi::FromInt(ast_id); 7625 return Smi::FromInt(ast_id);
7318 } else { 7626 } else {
7319 if (function->IsMarkedForLazyRecompilation()) { 7627 if (function->IsMarkedForLazyRecompilation()) {
7320 function->ReplaceCode(function->shared()->code()); 7628 function->ReplaceCode(function->shared()->code());
7321 } 7629 }
7322 return Smi::FromInt(-1); 7630 return Smi::FromInt(-1);
7323 } 7631 }
7324 } 7632 }
7325 7633
7326 7634
7327 static MaybeObject* Runtime_GetFunctionDelegate(Arguments args) { 7635 static MaybeObject* Runtime_GetFunctionDelegate(RUNTIME_CALLING_CONVENTION) {
7328 HandleScope scope; 7636 RUNTIME_GET_ISOLATE;
7637 HandleScope scope(isolate);
7329 ASSERT(args.length() == 1); 7638 ASSERT(args.length() == 1);
7330 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 7639 RUNTIME_ASSERT(!args[0]->IsJSFunction());
7331 return *Execution::GetFunctionDelegate(args.at<Object>(0)); 7640 return *Execution::GetFunctionDelegate(args.at<Object>(0));
7332 } 7641 }
7333 7642
7334 7643
7335 static MaybeObject* Runtime_GetConstructorDelegate(Arguments args) { 7644 static MaybeObject* Runtime_GetConstructorDelegate(RUNTIME_CALLING_CONVENTION) {
7336 HandleScope scope; 7645 RUNTIME_GET_ISOLATE;
7646 HandleScope scope(isolate);
7337 ASSERT(args.length() == 1); 7647 ASSERT(args.length() == 1);
7338 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 7648 RUNTIME_ASSERT(!args[0]->IsJSFunction());
7339 return *Execution::GetConstructorDelegate(args.at<Object>(0)); 7649 return *Execution::GetConstructorDelegate(args.at<Object>(0));
7340 } 7650 }
7341 7651
7342 7652
7343 static MaybeObject* Runtime_NewContext(Arguments args) { 7653 static MaybeObject* Runtime_NewContext(RUNTIME_CALLING_CONVENTION) {
7654 RUNTIME_GET_ISOLATE;
7344 NoHandleAllocation ha; 7655 NoHandleAllocation ha;
7345 ASSERT(args.length() == 1); 7656 ASSERT(args.length() == 1);
7346 7657
7347 CONVERT_CHECKED(JSFunction, function, args[0]); 7658 CONVERT_CHECKED(JSFunction, function, args[0]);
7348 int length = function->shared()->scope_info()->NumberOfContextSlots(); 7659 int length = function->shared()->scope_info()->NumberOfContextSlots();
7349 Object* result; 7660 Object* result;
7350 { MaybeObject* maybe_result = Heap::AllocateFunctionContext(length, function); 7661 { MaybeObject* maybe_result =
7662 isolate->heap()->AllocateFunctionContext(length, function);
7351 if (!maybe_result->ToObject(&result)) return maybe_result; 7663 if (!maybe_result->ToObject(&result)) return maybe_result;
7352 } 7664 }
7353 7665
7354 Top::set_context(Context::cast(result)); 7666 isolate->set_context(Context::cast(result));
7355 7667
7356 return result; // non-failure 7668 return result; // non-failure
7357 } 7669 }
7358 7670
7359 7671
7360 MUST_USE_RESULT static MaybeObject* PushContextHelper(Object* object, 7672 MUST_USE_RESULT static MaybeObject* PushContextHelper(Isolate* isolate,
7673 Object* object,
7361 bool is_catch_context) { 7674 bool is_catch_context) {
7362 // Convert the object to a proper JavaScript object. 7675 // Convert the object to a proper JavaScript object.
7363 Object* js_object = object; 7676 Object* js_object = object;
7364 if (!js_object->IsJSObject()) { 7677 if (!js_object->IsJSObject()) {
7365 MaybeObject* maybe_js_object = js_object->ToObject(); 7678 MaybeObject* maybe_js_object = js_object->ToObject();
7366 if (!maybe_js_object->ToObject(&js_object)) { 7679 if (!maybe_js_object->ToObject(&js_object)) {
7367 if (!Failure::cast(maybe_js_object)->IsInternalError()) { 7680 if (!Failure::cast(maybe_js_object)->IsInternalError()) {
7368 return maybe_js_object; 7681 return maybe_js_object;
7369 } 7682 }
7370 HandleScope scope; 7683 HandleScope scope(isolate);
7371 Handle<Object> handle(object); 7684 Handle<Object> handle(object, isolate);
7372 Handle<Object> result = 7685 Handle<Object> result =
7373 Factory::NewTypeError("with_expression", HandleVector(&handle, 1)); 7686 isolate->factory()->NewTypeError("with_expression",
7374 return Top::Throw(*result); 7687 HandleVector(&handle, 1));
7688 return isolate->Throw(*result);
7375 } 7689 }
7376 } 7690 }
7377 7691
7378 Object* result; 7692 Object* result;
7379 { MaybeObject* maybe_result = 7693 { MaybeObject* maybe_result = isolate->heap()->AllocateWithContext(
7380 Heap::AllocateWithContext(Top::context(), 7694 isolate->context(), JSObject::cast(js_object), is_catch_context);
7381 JSObject::cast(js_object),
7382 is_catch_context);
7383 if (!maybe_result->ToObject(&result)) return maybe_result; 7695 if (!maybe_result->ToObject(&result)) return maybe_result;
7384 } 7696 }
7385 7697
7386 Context* context = Context::cast(result); 7698 Context* context = Context::cast(result);
7387 Top::set_context(context); 7699 isolate->set_context(context);
7388 7700
7389 return result; 7701 return result;
7390 } 7702 }
7391 7703
7392 7704
7393 static MaybeObject* Runtime_PushContext(Arguments args) { 7705 static MaybeObject* Runtime_PushContext(RUNTIME_CALLING_CONVENTION) {
7706 RUNTIME_GET_ISOLATE;
7394 NoHandleAllocation ha; 7707 NoHandleAllocation ha;
7395 ASSERT(args.length() == 1); 7708 ASSERT(args.length() == 1);
7396 return PushContextHelper(args[0], false); 7709 return PushContextHelper(isolate, args[0], false);
7397 } 7710 }
7398 7711
7399 7712
7400 static MaybeObject* Runtime_PushCatchContext(Arguments args) { 7713 static MaybeObject* Runtime_PushCatchContext(RUNTIME_CALLING_CONVENTION) {
7714 RUNTIME_GET_ISOLATE;
7401 NoHandleAllocation ha; 7715 NoHandleAllocation ha;
7402 ASSERT(args.length() == 1); 7716 ASSERT(args.length() == 1);
7403 return PushContextHelper(args[0], true); 7717 return PushContextHelper(isolate, args[0], true);
7404 } 7718 }
7405 7719
7406 7720
7407 static MaybeObject* Runtime_DeleteContextSlot(Arguments args) { 7721 static MaybeObject* Runtime_DeleteContextSlot(RUNTIME_CALLING_CONVENTION) {
7408 HandleScope scope; 7722 RUNTIME_GET_ISOLATE;
7723 HandleScope scope(isolate);
7409 ASSERT(args.length() == 2); 7724 ASSERT(args.length() == 2);
7410 7725
7411 CONVERT_ARG_CHECKED(Context, context, 0); 7726 CONVERT_ARG_CHECKED(Context, context, 0);
7412 CONVERT_ARG_CHECKED(String, name, 1); 7727 CONVERT_ARG_CHECKED(String, name, 1);
7413 7728
7414 int index; 7729 int index;
7415 PropertyAttributes attributes; 7730 PropertyAttributes attributes;
7416 ContextLookupFlags flags = FOLLOW_CHAINS; 7731 ContextLookupFlags flags = FOLLOW_CHAINS;
7417 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 7732 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes);
7418 7733
7419 // If the slot was not found the result is true. 7734 // If the slot was not found the result is true.
7420 if (holder.is_null()) { 7735 if (holder.is_null()) {
7421 return Heap::true_value(); 7736 return isolate->heap()->true_value();
7422 } 7737 }
7423 7738
7424 // If the slot was found in a context, it should be DONT_DELETE. 7739 // If the slot was found in a context, it should be DONT_DELETE.
7425 if (holder->IsContext()) { 7740 if (holder->IsContext()) {
7426 return Heap::false_value(); 7741 return isolate->heap()->false_value();
7427 } 7742 }
7428 7743
7429 // The slot was found in a JSObject, either a context extension object, 7744 // The slot was found in a JSObject, either a context extension object,
7430 // the global object, or an arguments object. Try to delete it 7745 // the global object, or an arguments object. Try to delete it
7431 // (respecting DONT_DELETE). For consistency with V8's usual behavior, 7746 // (respecting DONT_DELETE). For consistency with V8's usual behavior,
7432 // which allows deleting all parameters in functions that mention 7747 // which allows deleting all parameters in functions that mention
7433 // 'arguments', we do this even for the case of slots found on an 7748 // 'arguments', we do this even for the case of slots found on an
7434 // arguments object. The slot was found on an arguments object if the 7749 // arguments object. The slot was found on an arguments object if the
7435 // index is non-negative. 7750 // index is non-negative.
7436 Handle<JSObject> object = Handle<JSObject>::cast(holder); 7751 Handle<JSObject> object = Handle<JSObject>::cast(holder);
(...skipping 27 matching lines...) Expand all
7464 } 7779 }
7465 #else 7780 #else
7466 typedef uint64_t ObjectPair; 7781 typedef uint64_t ObjectPair;
7467 static inline ObjectPair MakePair(MaybeObject* x, MaybeObject* y) { 7782 static inline ObjectPair MakePair(MaybeObject* x, MaybeObject* y) {
7468 return reinterpret_cast<uint32_t>(x) | 7783 return reinterpret_cast<uint32_t>(x) |
7469 (reinterpret_cast<ObjectPair>(y) << 32); 7784 (reinterpret_cast<ObjectPair>(y) << 32);
7470 } 7785 }
7471 #endif 7786 #endif
7472 7787
7473 7788
7474 static inline MaybeObject* Unhole(MaybeObject* x, 7789 static inline MaybeObject* Unhole(Heap* heap,
7790 MaybeObject* x,
7475 PropertyAttributes attributes) { 7791 PropertyAttributes attributes) {
7476 ASSERT(!x->IsTheHole() || (attributes & READ_ONLY) != 0); 7792 ASSERT(!x->IsTheHole() || (attributes & READ_ONLY) != 0);
7477 USE(attributes); 7793 USE(attributes);
7478 return x->IsTheHole() ? Heap::undefined_value() : x; 7794 return x->IsTheHole() ? heap->undefined_value() : x;
7479 } 7795 }
7480 7796
7481 7797
7482 static JSObject* ComputeReceiverForNonGlobal(JSObject* holder) { 7798 static JSObject* ComputeReceiverForNonGlobal(Isolate* isolate,
7799 JSObject* holder) {
7483 ASSERT(!holder->IsGlobalObject()); 7800 ASSERT(!holder->IsGlobalObject());
7484 Context* top = Top::context(); 7801 Context* top = isolate->context();
7485 // Get the context extension function. 7802 // Get the context extension function.
7486 JSFunction* context_extension_function = 7803 JSFunction* context_extension_function =
7487 top->global_context()->context_extension_function(); 7804 top->global_context()->context_extension_function();
7488 // If the holder isn't a context extension object, we just return it 7805 // If the holder isn't a context extension object, we just return it
7489 // as the receiver. This allows arguments objects to be used as 7806 // as the receiver. This allows arguments objects to be used as
7490 // receivers, but only if they are put in the context scope chain 7807 // receivers, but only if they are put in the context scope chain
7491 // explicitly via a with-statement. 7808 // explicitly via a with-statement.
7492 Object* constructor = holder->map()->constructor(); 7809 Object* constructor = holder->map()->constructor();
7493 if (constructor != context_extension_function) return holder; 7810 if (constructor != context_extension_function) return holder;
7494 // Fall back to using the global object as the receiver if the 7811 // Fall back to using the global object as the receiver if the
7495 // property turns out to be a local variable allocated in a context 7812 // property turns out to be a local variable allocated in a context
7496 // extension object - introduced via eval. 7813 // extension object - introduced via eval.
7497 return top->global()->global_receiver(); 7814 return top->global()->global_receiver();
7498 } 7815 }
7499 7816
7500 7817
7501 static ObjectPair LoadContextSlotHelper(Arguments args, bool throw_error) { 7818 static ObjectPair LoadContextSlotHelper(Arguments args,
7502 HandleScope scope; 7819 Isolate* isolate,
7820 bool throw_error) {
7821 HandleScope scope(isolate);
7503 ASSERT_EQ(2, args.length()); 7822 ASSERT_EQ(2, args.length());
7504 7823
7505 if (!args[0]->IsContext() || !args[1]->IsString()) { 7824 if (!args[0]->IsContext() || !args[1]->IsString()) {
7506 return MakePair(Top::ThrowIllegalOperation(), NULL); 7825 return MakePair(isolate->ThrowIllegalOperation(), NULL);
7507 } 7826 }
7508 Handle<Context> context = args.at<Context>(0); 7827 Handle<Context> context = args.at<Context>(0);
7509 Handle<String> name = args.at<String>(1); 7828 Handle<String> name = args.at<String>(1);
7510 7829
7511 int index; 7830 int index;
7512 PropertyAttributes attributes; 7831 PropertyAttributes attributes;
7513 ContextLookupFlags flags = FOLLOW_CHAINS; 7832 ContextLookupFlags flags = FOLLOW_CHAINS;
7514 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 7833 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes);
7515 7834
7516 // If the index is non-negative, the slot has been found in a local 7835 // If the index is non-negative, the slot has been found in a local
7517 // variable or a parameter. Read it from the context object or the 7836 // variable or a parameter. Read it from the context object or the
7518 // arguments object. 7837 // arguments object.
7519 if (index >= 0) { 7838 if (index >= 0) {
7520 // If the "property" we were looking for is a local variable or an 7839 // If the "property" we were looking for is a local variable or an
7521 // argument in a context, the receiver is the global object; see 7840 // argument in a context, the receiver is the global object; see
7522 // ECMA-262, 3rd., 10.1.6 and 10.2.3. 7841 // ECMA-262, 3rd., 10.1.6 and 10.2.3.
7523 JSObject* receiver = Top::context()->global()->global_receiver(); 7842 JSObject* receiver =
7843 isolate->context()->global()->global_receiver();
7524 MaybeObject* value = (holder->IsContext()) 7844 MaybeObject* value = (holder->IsContext())
7525 ? Context::cast(*holder)->get(index) 7845 ? Context::cast(*holder)->get(index)
7526 : JSObject::cast(*holder)->GetElement(index); 7846 : JSObject::cast(*holder)->GetElement(index);
7527 return MakePair(Unhole(value, attributes), receiver); 7847 return MakePair(Unhole(isolate->heap(), value, attributes), receiver);
7528 } 7848 }
7529 7849
7530 // If the holder is found, we read the property from it. 7850 // If the holder is found, we read the property from it.
7531 if (!holder.is_null() && holder->IsJSObject()) { 7851 if (!holder.is_null() && holder->IsJSObject()) {
7532 ASSERT(Handle<JSObject>::cast(holder)->HasProperty(*name)); 7852 ASSERT(Handle<JSObject>::cast(holder)->HasProperty(*name));
7533 JSObject* object = JSObject::cast(*holder); 7853 JSObject* object = JSObject::cast(*holder);
7534 JSObject* receiver; 7854 JSObject* receiver;
7535 if (object->IsGlobalObject()) { 7855 if (object->IsGlobalObject()) {
7536 receiver = GlobalObject::cast(object)->global_receiver(); 7856 receiver = GlobalObject::cast(object)->global_receiver();
7537 } else if (context->is_exception_holder(*holder)) { 7857 } else if (context->is_exception_holder(*holder)) {
7538 receiver = Top::context()->global()->global_receiver(); 7858 receiver = isolate->context()->global()->global_receiver();
7539 } else { 7859 } else {
7540 receiver = ComputeReceiverForNonGlobal(object); 7860 receiver = ComputeReceiverForNonGlobal(isolate, object);
7541 } 7861 }
7542 // No need to unhole the value here. This is taken care of by the 7862 // No need to unhole the value here. This is taken care of by the
7543 // GetProperty function. 7863 // GetProperty function.
7544 MaybeObject* value = object->GetProperty(*name); 7864 MaybeObject* value = object->GetProperty(*name);
7545 return MakePair(value, receiver); 7865 return MakePair(value, receiver);
7546 } 7866 }
7547 7867
7548 if (throw_error) { 7868 if (throw_error) {
7549 // The property doesn't exist - throw exception. 7869 // The property doesn't exist - throw exception.
7550 Handle<Object> reference_error = 7870 Handle<Object> reference_error =
7551 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); 7871 isolate->factory()->NewReferenceError("not_defined",
7552 return MakePair(Top::Throw(*reference_error), NULL); 7872 HandleVector(&name, 1));
7873 return MakePair(isolate->Throw(*reference_error), NULL);
7553 } else { 7874 } else {
7554 // The property doesn't exist - return undefined 7875 // The property doesn't exist - return undefined
7555 return MakePair(Heap::undefined_value(), Heap::undefined_value()); 7876 return MakePair(isolate->heap()->undefined_value(),
7877 isolate->heap()->undefined_value());
7556 } 7878 }
7557 } 7879 }
7558 7880
7559 7881
7560 static ObjectPair Runtime_LoadContextSlot(Arguments args) { 7882 static ObjectPair Runtime_LoadContextSlot(RUNTIME_CALLING_CONVENTION) {
7561 return LoadContextSlotHelper(args, true); 7883 RUNTIME_GET_ISOLATE;
7884 return LoadContextSlotHelper(args, isolate, true);
7562 } 7885 }
7563 7886
7564 7887
7565 static ObjectPair Runtime_LoadContextSlotNoReferenceError(Arguments args) { 7888 static ObjectPair Runtime_LoadContextSlotNoReferenceError(
7566 return LoadContextSlotHelper(args, false); 7889 RUNTIME_CALLING_CONVENTION) {
7890 RUNTIME_GET_ISOLATE;
7891 return LoadContextSlotHelper(args, isolate, false);
7567 } 7892 }
7568 7893
7569 7894
7570 static MaybeObject* Runtime_StoreContextSlot(Arguments args) { 7895 static MaybeObject* Runtime_StoreContextSlot(RUNTIME_CALLING_CONVENTION) {
7571 HandleScope scope; 7896 RUNTIME_GET_ISOLATE;
7897 HandleScope scope(isolate);
7572 ASSERT(args.length() == 4); 7898 ASSERT(args.length() == 4);
7573 7899
7574 Handle<Object> value(args[0]); 7900 Handle<Object> value(args[0], isolate);
7575 CONVERT_ARG_CHECKED(Context, context, 1); 7901 CONVERT_ARG_CHECKED(Context, context, 1);
7576 CONVERT_ARG_CHECKED(String, name, 2); 7902 CONVERT_ARG_CHECKED(String, name, 2);
7577 CONVERT_SMI_CHECKED(strict_unchecked, args[3]); 7903 CONVERT_SMI_CHECKED(strict_unchecked, args[3]);
7578 RUNTIME_ASSERT(strict_unchecked == kStrictMode || 7904 RUNTIME_ASSERT(strict_unchecked == kStrictMode ||
7579 strict_unchecked == kNonStrictMode); 7905 strict_unchecked == kNonStrictMode);
7580 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); 7906 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked);
7581 7907
7582 int index; 7908 int index;
7583 PropertyAttributes attributes; 7909 PropertyAttributes attributes;
7584 ContextLookupFlags flags = FOLLOW_CHAINS; 7910 ContextLookupFlags flags = FOLLOW_CHAINS;
7585 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 7911 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes);
7586 7912
7587 if (index >= 0) { 7913 if (index >= 0) {
7588 if (holder->IsContext()) { 7914 if (holder->IsContext()) {
7589 // Ignore if read_only variable. 7915 // Ignore if read_only variable.
7590 if ((attributes & READ_ONLY) == 0) { 7916 if ((attributes & READ_ONLY) == 0) {
7591 // Context is a fixed array and set cannot fail. 7917 // Context is a fixed array and set cannot fail.
7592 Context::cast(*holder)->set(index, *value); 7918 Context::cast(*holder)->set(index, *value);
7593 } else if (strict_mode == kStrictMode) { 7919 } else if (strict_mode == kStrictMode) {
7594 // Setting read only property in strict mode. 7920 // Setting read only property in strict mode.
7595 Handle<Object> error = 7921 Handle<Object> error =
7596 Factory::NewTypeError("strict_cannot_assign", 7922 isolate->factory()->NewTypeError("strict_cannot_assign",
7597 HandleVector(&name, 1)); 7923 HandleVector(&name, 1));
7598 return Top::Throw(*error); 7924 return isolate->Throw(*error);
7599 } 7925 }
7600 } else { 7926 } else {
7601 ASSERT((attributes & READ_ONLY) == 0); 7927 ASSERT((attributes & READ_ONLY) == 0);
7602 Handle<Object> result = 7928 Handle<Object> result =
7603 SetElement(Handle<JSObject>::cast(holder), index, value, strict_mode); 7929 SetElement(Handle<JSObject>::cast(holder), index, value, strict_mode);
7604 if (result.is_null()) { 7930 if (result.is_null()) {
7605 ASSERT(Top::has_pending_exception()); 7931 ASSERT(isolate->has_pending_exception());
7606 return Failure::Exception(); 7932 return Failure::Exception();
7607 } 7933 }
7608 } 7934 }
7609 return *value; 7935 return *value;
7610 } 7936 }
7611 7937
7612 // Slow case: The property is not in a FixedArray context. 7938 // Slow case: The property is not in a FixedArray context.
7613 // It is either in an JSObject extension context or it was not found. 7939 // It is either in an JSObject extension context or it was not found.
7614 Handle<JSObject> context_ext; 7940 Handle<JSObject> context_ext;
7615 7941
7616 if (!holder.is_null()) { 7942 if (!holder.is_null()) {
7617 // The property exists in the extension context. 7943 // The property exists in the extension context.
7618 context_ext = Handle<JSObject>::cast(holder); 7944 context_ext = Handle<JSObject>::cast(holder);
7619 } else { 7945 } else {
7620 // The property was not found. It needs to be stored in the global context. 7946 // The property was not found. It needs to be stored in the global context.
7621 ASSERT(attributes == ABSENT); 7947 ASSERT(attributes == ABSENT);
7622 attributes = NONE; 7948 attributes = NONE;
7623 context_ext = Handle<JSObject>(Top::context()->global()); 7949 context_ext = Handle<JSObject>(isolate->context()->global());
7624 } 7950 }
7625 7951
7626 // Set the property, but ignore if read_only variable on the context 7952 // Set the property, but ignore if read_only variable on the context
7627 // extension object itself. 7953 // extension object itself.
7628 if ((attributes & READ_ONLY) == 0 || 7954 if ((attributes & READ_ONLY) == 0 ||
7629 (context_ext->GetLocalPropertyAttribute(*name) == ABSENT)) { 7955 (context_ext->GetLocalPropertyAttribute(*name) == ABSENT)) {
7630 RETURN_IF_EMPTY_HANDLE( 7956 RETURN_IF_EMPTY_HANDLE(
7957 isolate,
7631 SetProperty(context_ext, name, value, NONE, strict_mode)); 7958 SetProperty(context_ext, name, value, NONE, strict_mode));
7632 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { 7959 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) {
7633 // Setting read only property in strict mode. 7960 // Setting read only property in strict mode.
7634 Handle<Object> error = 7961 Handle<Object> error =
7635 Factory::NewTypeError("strict_cannot_assign", HandleVector(&name, 1)); 7962 isolate->factory()->NewTypeError(
7636 return Top::Throw(*error); 7963 "strict_cannot_assign", HandleVector(&name, 1));
7964 return isolate->Throw(*error);
7637 } 7965 }
7638 return *value; 7966 return *value;
7639 } 7967 }
7640 7968
7641 7969
7642 static MaybeObject* Runtime_Throw(Arguments args) { 7970 static MaybeObject* Runtime_Throw(RUNTIME_CALLING_CONVENTION) {
7643 HandleScope scope; 7971 RUNTIME_GET_ISOLATE;
7972 HandleScope scope(isolate);
7644 ASSERT(args.length() == 1); 7973 ASSERT(args.length() == 1);
7645 7974
7646 return Top::Throw(args[0]); 7975 return isolate->Throw(args[0]);
7647 } 7976 }
7648 7977
7649 7978
7650 static MaybeObject* Runtime_ReThrow(Arguments args) { 7979 static MaybeObject* Runtime_ReThrow(RUNTIME_CALLING_CONVENTION) {
7651 HandleScope scope; 7980 RUNTIME_GET_ISOLATE;
7981 HandleScope scope(isolate);
7652 ASSERT(args.length() == 1); 7982 ASSERT(args.length() == 1);
7653 7983
7654 return Top::ReThrow(args[0]); 7984 return isolate->ReThrow(args[0]);
7655 } 7985 }
7656 7986
7657 7987
7658 static MaybeObject* Runtime_PromoteScheduledException(Arguments args) { 7988 static MaybeObject* Runtime_PromoteScheduledException(
7989 RUNTIME_CALLING_CONVENTION) {
7990 RUNTIME_GET_ISOLATE;
7659 ASSERT_EQ(0, args.length()); 7991 ASSERT_EQ(0, args.length());
7660 return Top::PromoteScheduledException(); 7992 return isolate->PromoteScheduledException();
7661 } 7993 }
7662 7994
7663 7995
7664 static MaybeObject* Runtime_ThrowReferenceError(Arguments args) { 7996 static MaybeObject* Runtime_ThrowReferenceError(RUNTIME_CALLING_CONVENTION) {
7665 HandleScope scope; 7997 RUNTIME_GET_ISOLATE;
7998 HandleScope scope(isolate);
7666 ASSERT(args.length() == 1); 7999 ASSERT(args.length() == 1);
7667 8000
7668 Handle<Object> name(args[0]); 8001 Handle<Object> name(args[0], isolate);
7669 Handle<Object> reference_error = 8002 Handle<Object> reference_error =
7670 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); 8003 isolate->factory()->NewReferenceError("not_defined",
7671 return Top::Throw(*reference_error); 8004 HandleVector(&name, 1));
8005 return isolate->Throw(*reference_error);
7672 } 8006 }
7673 8007
7674 8008
7675 static MaybeObject* Runtime_StackOverflow(Arguments args) { 8009 static MaybeObject* Runtime_StackGuard(RUNTIME_CALLING_CONVENTION) {
7676 NoHandleAllocation na; 8010 RUNTIME_GET_ISOLATE;
7677 return Top::StackOverflow();
7678 }
7679
7680
7681 static MaybeObject* Runtime_StackGuard(Arguments args) {
7682 ASSERT(args.length() == 0); 8011 ASSERT(args.length() == 0);
7683 8012
7684 // First check if this is a real stack overflow. 8013 // First check if this is a real stack overflow.
7685 if (StackGuard::IsStackOverflow()) { 8014 if (isolate->stack_guard()->IsStackOverflow()) {
7686 return Runtime_StackOverflow(args); 8015 NoHandleAllocation na;
8016 return isolate->StackOverflow();
7687 } 8017 }
7688 8018
7689 return Execution::HandleStackGuardInterrupt(); 8019 return Execution::HandleStackGuardInterrupt();
7690 } 8020 }
7691 8021
7692 8022
7693 // NOTE: These PrintXXX functions are defined for all builds (not just 8023 // NOTE: These PrintXXX functions are defined for all builds (not just
7694 // DEBUG builds) because we may want to be able to trace function 8024 // DEBUG builds) because we may want to be able to trace function
7695 // calls in all modes. 8025 // calls in all modes.
7696 static void PrintString(String* str) { 8026 static void PrintString(String* str) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
7769 8099
7770 } else { 8100 } else {
7771 // function result 8101 // function result
7772 PrintF("} -> "); 8102 PrintF("} -> ");
7773 PrintObject(result); 8103 PrintObject(result);
7774 PrintF("\n"); 8104 PrintF("\n");
7775 } 8105 }
7776 } 8106 }
7777 8107
7778 8108
7779 static MaybeObject* Runtime_TraceEnter(Arguments args) { 8109 static MaybeObject* Runtime_TraceEnter(RUNTIME_CALLING_CONVENTION) {
8110 RUNTIME_GET_ISOLATE;
7780 ASSERT(args.length() == 0); 8111 ASSERT(args.length() == 0);
7781 NoHandleAllocation ha; 8112 NoHandleAllocation ha;
7782 PrintTransition(NULL); 8113 PrintTransition(NULL);
7783 return Heap::undefined_value(); 8114 return isolate->heap()->undefined_value();
7784 } 8115 }
7785 8116
7786 8117
7787 static MaybeObject* Runtime_TraceExit(Arguments args) { 8118 static MaybeObject* Runtime_TraceExit(RUNTIME_CALLING_CONVENTION) {
8119 RUNTIME_GET_ISOLATE;
7788 NoHandleAllocation ha; 8120 NoHandleAllocation ha;
7789 PrintTransition(args[0]); 8121 PrintTransition(args[0]);
7790 return args[0]; // return TOS 8122 return args[0]; // return TOS
7791 } 8123 }
7792 8124
7793 8125
7794 static MaybeObject* Runtime_DebugPrint(Arguments args) { 8126 static MaybeObject* Runtime_DebugPrint(RUNTIME_CALLING_CONVENTION) {
8127 RUNTIME_GET_ISOLATE;
7795 NoHandleAllocation ha; 8128 NoHandleAllocation ha;
7796 ASSERT(args.length() == 1); 8129 ASSERT(args.length() == 1);
7797 8130
7798 #ifdef DEBUG 8131 #ifdef DEBUG
7799 if (args[0]->IsString()) { 8132 if (args[0]->IsString()) {
7800 // If we have a string, assume it's a code "marker" 8133 // If we have a string, assume it's a code "marker"
7801 // and print some interesting cpu debugging info. 8134 // and print some interesting cpu debugging info.
7802 JavaScriptFrameIterator it; 8135 JavaScriptFrameIterator it;
7803 JavaScriptFrame* frame = it.frame(); 8136 JavaScriptFrame* frame = it.frame();
7804 PrintF("fp = %p, sp = %p, caller_sp = %p: ", 8137 PrintF("fp = %p, sp = %p, caller_sp = %p: ",
(...skipping 10 matching lines...) Expand all
7815 // ShortPrint is available in release mode. Print is not. 8148 // ShortPrint is available in release mode. Print is not.
7816 args[0]->ShortPrint(); 8149 args[0]->ShortPrint();
7817 #endif 8150 #endif
7818 PrintF("\n"); 8151 PrintF("\n");
7819 Flush(); 8152 Flush();
7820 8153
7821 return args[0]; // return TOS 8154 return args[0]; // return TOS
7822 } 8155 }
7823 8156
7824 8157
7825 static MaybeObject* Runtime_DebugTrace(Arguments args) { 8158 static MaybeObject* Runtime_DebugTrace(RUNTIME_CALLING_CONVENTION) {
8159 RUNTIME_GET_ISOLATE;
7826 ASSERT(args.length() == 0); 8160 ASSERT(args.length() == 0);
7827 NoHandleAllocation ha; 8161 NoHandleAllocation ha;
7828 Top::PrintStack(); 8162 isolate->PrintStack();
7829 return Heap::undefined_value(); 8163 return isolate->heap()->undefined_value();
7830 } 8164 }
7831 8165
7832 8166
7833 static MaybeObject* Runtime_DateCurrentTime(Arguments args) { 8167 static MaybeObject* Runtime_DateCurrentTime(RUNTIME_CALLING_CONVENTION) {
8168 RUNTIME_GET_ISOLATE;
7834 NoHandleAllocation ha; 8169 NoHandleAllocation ha;
7835 ASSERT(args.length() == 0); 8170 ASSERT(args.length() == 0);
7836 8171
7837 // According to ECMA-262, section 15.9.1, page 117, the precision of 8172 // According to ECMA-262, section 15.9.1, page 117, the precision of
7838 // the number in a Date object representing a particular instant in 8173 // the number in a Date object representing a particular instant in
7839 // time is milliseconds. Therefore, we floor the result of getting 8174 // time is milliseconds. Therefore, we floor the result of getting
7840 // the OS time. 8175 // the OS time.
7841 double millis = floor(OS::TimeCurrentMillis()); 8176 double millis = floor(OS::TimeCurrentMillis());
7842 return Heap::NumberFromDouble(millis); 8177 return isolate->heap()->NumberFromDouble(millis);
7843 } 8178 }
7844 8179
7845 8180
7846 static MaybeObject* Runtime_DateParseString(Arguments args) { 8181 static MaybeObject* Runtime_DateParseString(RUNTIME_CALLING_CONVENTION) {
7847 HandleScope scope; 8182 RUNTIME_GET_ISOLATE;
8183 HandleScope scope(isolate);
7848 ASSERT(args.length() == 2); 8184 ASSERT(args.length() == 2);
7849 8185
7850 CONVERT_ARG_CHECKED(String, str, 0); 8186 CONVERT_ARG_CHECKED(String, str, 0);
7851 FlattenString(str); 8187 FlattenString(str);
7852 8188
7853 CONVERT_ARG_CHECKED(JSArray, output, 1); 8189 CONVERT_ARG_CHECKED(JSArray, output, 1);
7854 RUNTIME_ASSERT(output->HasFastElements()); 8190 RUNTIME_ASSERT(output->HasFastElements());
7855 8191
7856 AssertNoAllocation no_allocation; 8192 AssertNoAllocation no_allocation;
7857 8193
7858 FixedArray* output_array = FixedArray::cast(output->elements()); 8194 FixedArray* output_array = FixedArray::cast(output->elements());
7859 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); 8195 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
7860 bool result; 8196 bool result;
7861 if (str->IsAsciiRepresentation()) { 8197 if (str->IsAsciiRepresentation()) {
7862 result = DateParser::Parse(str->ToAsciiVector(), output_array); 8198 result = DateParser::Parse(str->ToAsciiVector(), output_array);
7863 } else { 8199 } else {
7864 ASSERT(str->IsTwoByteRepresentation()); 8200 ASSERT(str->IsTwoByteRepresentation());
7865 result = DateParser::Parse(str->ToUC16Vector(), output_array); 8201 result = DateParser::Parse(str->ToUC16Vector(), output_array);
7866 } 8202 }
7867 8203
7868 if (result) { 8204 if (result) {
7869 return *output; 8205 return *output;
7870 } else { 8206 } else {
7871 return Heap::null_value(); 8207 return isolate->heap()->null_value();
7872 } 8208 }
7873 } 8209 }
7874 8210
7875 8211
7876 static MaybeObject* Runtime_DateLocalTimezone(Arguments args) { 8212 static MaybeObject* Runtime_DateLocalTimezone(RUNTIME_CALLING_CONVENTION) {
8213 RUNTIME_GET_ISOLATE;
7877 NoHandleAllocation ha; 8214 NoHandleAllocation ha;
7878 ASSERT(args.length() == 1); 8215 ASSERT(args.length() == 1);
7879 8216
7880 CONVERT_DOUBLE_CHECKED(x, args[0]); 8217 CONVERT_DOUBLE_CHECKED(x, args[0]);
7881 const char* zone = OS::LocalTimezone(x); 8218 const char* zone = OS::LocalTimezone(x);
7882 return Heap::AllocateStringFromUtf8(CStrVector(zone)); 8219 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone));
7883 } 8220 }
7884 8221
7885 8222
7886 static MaybeObject* Runtime_DateLocalTimeOffset(Arguments args) { 8223 static MaybeObject* Runtime_DateLocalTimeOffset(RUNTIME_CALLING_CONVENTION) {
8224 RUNTIME_GET_ISOLATE;
7887 NoHandleAllocation ha; 8225 NoHandleAllocation ha;
7888 ASSERT(args.length() == 0); 8226 ASSERT(args.length() == 0);
7889 8227
7890 return Heap::NumberFromDouble(OS::LocalTimeOffset()); 8228 return isolate->heap()->NumberFromDouble(OS::LocalTimeOffset());
7891 } 8229 }
7892 8230
7893 8231
7894 static MaybeObject* Runtime_DateDaylightSavingsOffset(Arguments args) { 8232 static MaybeObject* Runtime_DateDaylightSavingsOffset(
8233 RUNTIME_CALLING_CONVENTION) {
8234 RUNTIME_GET_ISOLATE;
7895 NoHandleAllocation ha; 8235 NoHandleAllocation ha;
7896 ASSERT(args.length() == 1); 8236 ASSERT(args.length() == 1);
7897 8237
7898 CONVERT_DOUBLE_CHECKED(x, args[0]); 8238 CONVERT_DOUBLE_CHECKED(x, args[0]);
7899 return Heap::NumberFromDouble(OS::DaylightSavingsOffset(x)); 8239 return isolate->heap()->NumberFromDouble(OS::DaylightSavingsOffset(x));
7900 } 8240 }
7901 8241
7902 8242
7903 static MaybeObject* Runtime_GlobalReceiver(Arguments args) { 8243 static MaybeObject* Runtime_GlobalReceiver(RUNTIME_CALLING_CONVENTION) {
8244 RUNTIME_GET_ISOLATE;
7904 ASSERT(args.length() == 1); 8245 ASSERT(args.length() == 1);
7905 Object* global = args[0]; 8246 Object* global = args[0];
7906 if (!global->IsJSGlobalObject()) return Heap::null_value(); 8247 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value();
7907 return JSGlobalObject::cast(global)->global_receiver(); 8248 return JSGlobalObject::cast(global)->global_receiver();
7908 } 8249 }
7909 8250
7910 8251
7911 static MaybeObject* Runtime_ParseJson(Arguments args) { 8252 static MaybeObject* Runtime_ParseJson(RUNTIME_CALLING_CONVENTION) {
7912 HandleScope scope; 8253 HandleScope scope(isolate);
7913 ASSERT_EQ(1, args.length()); 8254 ASSERT_EQ(1, args.length());
7914 CONVERT_ARG_CHECKED(String, source, 0); 8255 CONVERT_ARG_CHECKED(String, source, 0);
7915 8256
7916 Handle<Object> result = JsonParser::Parse(source); 8257 Handle<Object> result = JsonParser::Parse(source);
7917 if (result.is_null()) { 8258 if (result.is_null()) {
7918 // Syntax error or stack overflow in scanner. 8259 // Syntax error or stack overflow in scanner.
7919 ASSERT(Top::has_pending_exception()); 8260 ASSERT(isolate->has_pending_exception());
7920 return Failure::Exception(); 8261 return Failure::Exception();
7921 } 8262 }
7922 return *result; 8263 return *result;
7923 } 8264 }
7924 8265
7925 8266
7926 static MaybeObject* Runtime_CompileString(Arguments args) { 8267 static MaybeObject* Runtime_CompileString(RUNTIME_CALLING_CONVENTION) {
7927 HandleScope scope; 8268 RUNTIME_GET_ISOLATE;
8269 HandleScope scope(isolate);
7928 ASSERT_EQ(1, args.length()); 8270 ASSERT_EQ(1, args.length());
7929 CONVERT_ARG_CHECKED(String, source, 0); 8271 CONVERT_ARG_CHECKED(String, source, 0);
7930 8272
7931 // Compile source string in the global context. 8273 // Compile source string in the global context.
7932 Handle<Context> context(Top::context()->global_context()); 8274 Handle<Context> context(isolate->context()->global_context());
7933 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, 8275 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source,
7934 context, 8276 context,
7935 true, 8277 true,
7936 kNonStrictMode); 8278 kNonStrictMode);
7937 if (shared.is_null()) return Failure::Exception(); 8279 if (shared.is_null()) return Failure::Exception();
7938 Handle<JSFunction> fun = 8280 Handle<JSFunction> fun =
7939 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); 8281 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
8282 context,
8283 NOT_TENURED);
7940 return *fun; 8284 return *fun;
7941 } 8285 }
7942 8286
7943 8287
7944 static ObjectPair CompileGlobalEval(Handle<String> source, 8288 static ObjectPair CompileGlobalEval(Isolate* isolate,
8289 Handle<String> source,
7945 Handle<Object> receiver, 8290 Handle<Object> receiver,
7946 StrictModeFlag strict_mode) { 8291 StrictModeFlag strict_mode) {
7947 // Deal with a normal eval call with a string argument. Compile it 8292 // Deal with a normal eval call with a string argument. Compile it
7948 // and return the compiled function bound in the local context. 8293 // and return the compiled function bound in the local context.
7949 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 8294 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
7950 source, 8295 source,
7951 Handle<Context>(Top::context()), 8296 Handle<Context>(isolate->context()),
7952 Top::context()->IsGlobalContext(), 8297 isolate->context()->IsGlobalContext(),
7953 strict_mode); 8298 strict_mode);
7954 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); 8299 if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
7955 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo( 8300 Handle<JSFunction> compiled =
7956 shared, 8301 isolate->factory()->NewFunctionFromSharedFunctionInfo(
7957 Handle<Context>(Top::context()), 8302 shared, Handle<Context>(isolate->context()), NOT_TENURED);
7958 NOT_TENURED);
7959 return MakePair(*compiled, *receiver); 8303 return MakePair(*compiled, *receiver);
7960 } 8304 }
7961 8305
7962 8306
7963 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { 8307 static ObjectPair Runtime_ResolvePossiblyDirectEval(
8308 RUNTIME_CALLING_CONVENTION) {
8309 RUNTIME_GET_ISOLATE;
7964 ASSERT(args.length() == 4); 8310 ASSERT(args.length() == 4);
7965 8311
7966 HandleScope scope; 8312 HandleScope scope(isolate);
7967 Handle<Object> callee = args.at<Object>(0); 8313 Handle<Object> callee = args.at<Object>(0);
7968 Handle<Object> receiver; // Will be overwritten. 8314 Handle<Object> receiver; // Will be overwritten.
7969 8315
7970 // Compute the calling context. 8316 // Compute the calling context.
7971 Handle<Context> context = Handle<Context>(Top::context()); 8317 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
7972 #ifdef DEBUG 8318 #ifdef DEBUG
7973 // Make sure Top::context() agrees with the old code that traversed 8319 // Make sure Isolate::context() agrees with the old code that traversed
7974 // the stack frames to compute the context. 8320 // the stack frames to compute the context.
7975 StackFrameLocator locator; 8321 StackFrameLocator locator;
7976 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 8322 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
7977 ASSERT(Context::cast(frame->context()) == *context); 8323 ASSERT(Context::cast(frame->context()) == *context);
7978 #endif 8324 #endif
7979 8325
7980 // Find where the 'eval' symbol is bound. It is unaliased only if 8326 // Find where the 'eval' symbol is bound. It is unaliased only if
7981 // it is bound in the global context. 8327 // it is bound in the global context.
7982 int index = -1; 8328 int index = -1;
7983 PropertyAttributes attributes = ABSENT; 8329 PropertyAttributes attributes = ABSENT;
7984 while (true) { 8330 while (true) {
7985 receiver = context->Lookup(Factory::eval_symbol(), FOLLOW_PROTOTYPE_CHAIN, 8331 receiver = context->Lookup(isolate->factory()->eval_symbol(),
8332 FOLLOW_PROTOTYPE_CHAIN,
7986 &index, &attributes); 8333 &index, &attributes);
7987 // Stop search when eval is found or when the global context is 8334 // Stop search when eval is found or when the global context is
7988 // reached. 8335 // reached.
7989 if (attributes != ABSENT || context->IsGlobalContext()) break; 8336 if (attributes != ABSENT || context->IsGlobalContext()) break;
7990 if (context->is_function_context()) { 8337 if (context->is_function_context()) {
7991 context = Handle<Context>(Context::cast(context->closure()->context())); 8338 context = Handle<Context>(Context::cast(context->closure()->context()),
8339 isolate);
7992 } else { 8340 } else {
7993 context = Handle<Context>(context->previous()); 8341 context = Handle<Context>(context->previous(), isolate);
7994 } 8342 }
7995 } 8343 }
7996 8344
7997 // If eval could not be resolved, it has been deleted and we need to 8345 // If eval could not be resolved, it has been deleted and we need to
7998 // throw a reference error. 8346 // throw a reference error.
7999 if (attributes == ABSENT) { 8347 if (attributes == ABSENT) {
8000 Handle<Object> name = Factory::eval_symbol(); 8348 Handle<Object> name = isolate->factory()->eval_symbol();
8001 Handle<Object> reference_error = 8349 Handle<Object> reference_error =
8002 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); 8350 isolate->factory()->NewReferenceError("not_defined",
8003 return MakePair(Top::Throw(*reference_error), NULL); 8351 HandleVector(&name, 1));
8352 return MakePair(isolate->Throw(*reference_error), NULL);
8004 } 8353 }
8005 8354
8006 if (!context->IsGlobalContext()) { 8355 if (!context->IsGlobalContext()) {
8007 // 'eval' is not bound in the global context. Just call the function 8356 // 'eval' is not bound in the global context. Just call the function
8008 // with the given arguments. This is not necessarily the global eval. 8357 // with the given arguments. This is not necessarily the global eval.
8009 if (receiver->IsContext()) { 8358 if (receiver->IsContext()) {
8010 context = Handle<Context>::cast(receiver); 8359 context = Handle<Context>::cast(receiver);
8011 receiver = Handle<Object>(context->get(index)); 8360 receiver = Handle<Object>(context->get(index), isolate);
8012 } else if (receiver->IsJSContextExtensionObject()) { 8361 } else if (receiver->IsJSContextExtensionObject()) {
8013 receiver = Handle<JSObject>(Top::context()->global()->global_receiver()); 8362 receiver = Handle<JSObject>(
8363 isolate->context()->global()->global_receiver(), isolate);
8014 } 8364 }
8015 return MakePair(*callee, *receiver); 8365 return MakePair(*callee, *receiver);
8016 } 8366 }
8017 8367
8018 // 'eval' is bound in the global context, but it may have been overwritten. 8368 // 'eval' is bound in the global context, but it may have been overwritten.
8019 // Compare it to the builtin 'GlobalEval' function to make sure. 8369 // Compare it to the builtin 'GlobalEval' function to make sure.
8020 if (*callee != Top::global_context()->global_eval_fun() || 8370 if (*callee != isolate->global_context()->global_eval_fun() ||
8021 !args[1]->IsString()) { 8371 !args[1]->IsString()) {
8022 return MakePair(*callee, Top::context()->global()->global_receiver()); 8372 return MakePair(*callee,
8373 isolate->context()->global()->global_receiver());
8023 } 8374 }
8024 8375
8025 ASSERT(args[3]->IsSmi()); 8376 ASSERT(args[3]->IsSmi());
8026 return CompileGlobalEval(args.at<String>(1), 8377 return CompileGlobalEval(isolate,
8378 args.at<String>(1),
8027 args.at<Object>(2), 8379 args.at<Object>(2),
8028 static_cast<StrictModeFlag>( 8380 static_cast<StrictModeFlag>(
8029 Smi::cast(args[3])->value())); 8381 Smi::cast(args[3])->value()));
8030 } 8382 }
8031 8383
8032 8384
8033 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { 8385 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(
8386 RUNTIME_CALLING_CONVENTION) {
8387 RUNTIME_GET_ISOLATE;
8034 ASSERT(args.length() == 4); 8388 ASSERT(args.length() == 4);
8035 8389
8036 HandleScope scope; 8390 HandleScope scope(isolate);
8037 Handle<Object> callee = args.at<Object>(0); 8391 Handle<Object> callee = args.at<Object>(0);
8038 8392
8039 // 'eval' is bound in the global context, but it may have been overwritten. 8393 // 'eval' is bound in the global context, but it may have been overwritten.
8040 // Compare it to the builtin 'GlobalEval' function to make sure. 8394 // Compare it to the builtin 'GlobalEval' function to make sure.
8041 if (*callee != Top::global_context()->global_eval_fun() || 8395 if (*callee != isolate->global_context()->global_eval_fun() ||
8042 !args[1]->IsString()) { 8396 !args[1]->IsString()) {
8043 return MakePair(*callee, Top::context()->global()->global_receiver()); 8397 return MakePair(*callee,
8398 isolate->context()->global()->global_receiver());
8044 } 8399 }
8045 8400
8046 ASSERT(args[3]->IsSmi()); 8401 ASSERT(args[3]->IsSmi());
8047 return CompileGlobalEval(args.at<String>(1), 8402 return CompileGlobalEval(isolate,
8403 args.at<String>(1),
8048 args.at<Object>(2), 8404 args.at<Object>(2),
8049 static_cast<StrictModeFlag>( 8405 static_cast<StrictModeFlag>(
8050 Smi::cast(args[3])->value())); 8406 Smi::cast(args[3])->value()));
8051 } 8407 }
8052 8408
8053 8409
8054 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) { 8410 static MaybeObject* Runtime_SetNewFunctionAttributes(
8411 RUNTIME_CALLING_CONVENTION) {
8412 RUNTIME_GET_ISOLATE;
8055 // This utility adjusts the property attributes for newly created Function 8413 // This utility adjusts the property attributes for newly created Function
8056 // object ("new Function(...)") by changing the map. 8414 // object ("new Function(...)") by changing the map.
8057 // All it does is changing the prototype property to enumerable 8415 // All it does is changing the prototype property to enumerable
8058 // as specified in ECMA262, 15.3.5.2. 8416 // as specified in ECMA262, 15.3.5.2.
8059 HandleScope scope; 8417 HandleScope scope(isolate);
8060 ASSERT(args.length() == 1); 8418 ASSERT(args.length() == 1);
8061 CONVERT_ARG_CHECKED(JSFunction, func, 0); 8419 CONVERT_ARG_CHECKED(JSFunction, func, 0);
8062 8420
8063 Handle<Map> map = func->shared()->strict_mode() 8421 Handle<Map> map = func->shared()->strict_mode()
8064 ? Top::strict_mode_function_instance_map() 8422 ? isolate->strict_mode_function_instance_map()
8065 : Top::function_instance_map(); 8423 : isolate->function_instance_map();
8066 8424
8067 ASSERT(func->map()->instance_type() == map->instance_type()); 8425 ASSERT(func->map()->instance_type() == map->instance_type());
8068 ASSERT(func->map()->instance_size() == map->instance_size()); 8426 ASSERT(func->map()->instance_size() == map->instance_size());
8069 func->set_map(*map); 8427 func->set_map(*map);
8070 return *func; 8428 return *func;
8071 } 8429 }
8072 8430
8073 8431
8074 static MaybeObject* Runtime_AllocateInNewSpace(Arguments args) { 8432 static MaybeObject* Runtime_AllocateInNewSpace(RUNTIME_CALLING_CONVENTION) {
8433 RUNTIME_GET_ISOLATE;
8075 // Allocate a block of memory in NewSpace (filled with a filler). 8434 // Allocate a block of memory in NewSpace (filled with a filler).
8076 // Use as fallback for allocation in generated code when NewSpace 8435 // Use as fallback for allocation in generated code when NewSpace
8077 // is full. 8436 // is full.
8078 ASSERT(args.length() == 1); 8437 ASSERT(args.length() == 1);
8079 CONVERT_ARG_CHECKED(Smi, size_smi, 0); 8438 CONVERT_ARG_CHECKED(Smi, size_smi, 0);
8080 int size = size_smi->value(); 8439 int size = size_smi->value();
8081 RUNTIME_ASSERT(IsAligned(size, kPointerSize)); 8440 RUNTIME_ASSERT(IsAligned(size, kPointerSize));
8082 RUNTIME_ASSERT(size > 0); 8441 RUNTIME_ASSERT(size > 0);
8083 static const int kMinFreeNewSpaceAfterGC = 8442 Heap* heap = isolate->heap();
8084 Heap::InitialSemiSpaceSize() * 3/4; 8443 const int kMinFreeNewSpaceAfterGC = heap->InitialSemiSpaceSize() * 3/4;
8085 RUNTIME_ASSERT(size <= kMinFreeNewSpaceAfterGC); 8444 RUNTIME_ASSERT(size <= kMinFreeNewSpaceAfterGC);
8086 Object* allocation; 8445 Object* allocation;
8087 { MaybeObject* maybe_allocation = Heap::new_space()->AllocateRaw(size); 8446 { MaybeObject* maybe_allocation = heap->new_space()->AllocateRaw(size);
8088 if (maybe_allocation->ToObject(&allocation)) { 8447 if (maybe_allocation->ToObject(&allocation)) {
8089 Heap::CreateFillerObjectAt(HeapObject::cast(allocation)->address(), size); 8448 heap->CreateFillerObjectAt(HeapObject::cast(allocation)->address(), size);
8090 } 8449 }
8091 return maybe_allocation; 8450 return maybe_allocation;
8092 } 8451 }
8093 } 8452 }
8094 8453
8095 8454
8096 // Push an object unto an array of objects if it is not already in the 8455 // Push an object unto an array of objects if it is not already in the
8097 // array. Returns true if the element was pushed on the stack and 8456 // array. Returns true if the element was pushed on the stack and
8098 // false otherwise. 8457 // false otherwise.
8099 static MaybeObject* Runtime_PushIfAbsent(Arguments args) { 8458 static MaybeObject* Runtime_PushIfAbsent(RUNTIME_CALLING_CONVENTION) {
8459 RUNTIME_GET_ISOLATE;
8100 ASSERT(args.length() == 2); 8460 ASSERT(args.length() == 2);
8101 CONVERT_CHECKED(JSArray, array, args[0]); 8461 CONVERT_CHECKED(JSArray, array, args[0]);
8102 CONVERT_CHECKED(JSObject, element, args[1]); 8462 CONVERT_CHECKED(JSObject, element, args[1]);
8103 RUNTIME_ASSERT(array->HasFastElements()); 8463 RUNTIME_ASSERT(array->HasFastElements());
8104 int length = Smi::cast(array->length())->value(); 8464 int length = Smi::cast(array->length())->value();
8105 FixedArray* elements = FixedArray::cast(array->elements()); 8465 FixedArray* elements = FixedArray::cast(array->elements());
8106 for (int i = 0; i < length; i++) { 8466 for (int i = 0; i < length; i++) {
8107 if (elements->get(i) == element) return Heap::false_value(); 8467 if (elements->get(i) == element) return isolate->heap()->false_value();
8108 } 8468 }
8109 Object* obj; 8469 Object* obj;
8110 // Strict not needed. Used for cycle detection in Array join implementation. 8470 // Strict not needed. Used for cycle detection in Array join implementation.
8111 { MaybeObject* maybe_obj = array->SetFastElement(length, element, 8471 { MaybeObject* maybe_obj = array->SetFastElement(length, element,
8112 kNonStrictMode); 8472 kNonStrictMode);
8113 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 8473 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
8114 } 8474 }
8115 return Heap::true_value(); 8475 return isolate->heap()->true_value();
8116 } 8476 }
8117 8477
8118 8478
8119 /** 8479 /**
8120 * A simple visitor visits every element of Array's. 8480 * A simple visitor visits every element of Array's.
8121 * The backend storage can be a fixed array for fast elements case, 8481 * The backend storage can be a fixed array for fast elements case,
8122 * or a dictionary for sparse array. Since Dictionary is a subtype 8482 * or a dictionary for sparse array. Since Dictionary is a subtype
8123 * of FixedArray, the class can be used by both fast and slow cases. 8483 * of FixedArray, the class can be used by both fast and slow cases.
8124 * The second parameter of the constructor, fast_elements, specifies 8484 * The second parameter of the constructor, fast_elements, specifies
8125 * whether the storage is a FixedArray or Dictionary. 8485 * whether the storage is a FixedArray or Dictionary.
8126 * 8486 *
8127 * An index limit is used to deal with the situation that a result array 8487 * An index limit is used to deal with the situation that a result array
8128 * length overflows 32-bit non-negative integer. 8488 * length overflows 32-bit non-negative integer.
8129 */ 8489 */
8130 class ArrayConcatVisitor { 8490 class ArrayConcatVisitor {
8131 public: 8491 public:
8132 ArrayConcatVisitor(Handle<FixedArray> storage, 8492 ArrayConcatVisitor(Isolate* isolate,
8493 Handle<FixedArray> storage,
8133 bool fast_elements) : 8494 bool fast_elements) :
8134 storage_(Handle<FixedArray>::cast(GlobalHandles::Create(*storage))), 8495 isolate_(isolate),
8496 storage_(Handle<FixedArray>::cast(
8497 isolate->global_handles()->Create(*storage))),
8135 index_offset_(0u), 8498 index_offset_(0u),
8136 fast_elements_(fast_elements) { } 8499 fast_elements_(fast_elements) { }
8137 8500
8138 ~ArrayConcatVisitor() { 8501 ~ArrayConcatVisitor() {
8139 clear_storage(); 8502 clear_storage();
8140 } 8503 }
8141 8504
8142 void visit(uint32_t i, Handle<Object> elm) { 8505 void visit(uint32_t i, Handle<Object> elm) {
8143 if (i >= JSObject::kMaxElementCount - index_offset_) return; 8506 if (i >= JSObject::kMaxElementCount - index_offset_) return;
8144 uint32_t index = index_offset_ + i; 8507 uint32_t index = index_offset_ + i;
8145 8508
8146 if (fast_elements_) { 8509 if (fast_elements_) {
8147 if (index < static_cast<uint32_t>(storage_->length())) { 8510 if (index < static_cast<uint32_t>(storage_->length())) {
8148 storage_->set(index, *elm); 8511 storage_->set(index, *elm);
8149 return; 8512 return;
8150 } 8513 }
8151 // Our initial estimate of length was foiled, possibly by 8514 // Our initial estimate of length was foiled, possibly by
8152 // getters on the arrays increasing the length of later arrays 8515 // getters on the arrays increasing the length of later arrays
8153 // during iteration. 8516 // during iteration.
8154 // This shouldn't happen in anything but pathological cases. 8517 // This shouldn't happen in anything but pathological cases.
8155 SetDictionaryMode(index); 8518 SetDictionaryMode(index);
8156 // Fall-through to dictionary mode. 8519 // Fall-through to dictionary mode.
8157 } 8520 }
8158 ASSERT(!fast_elements_); 8521 ASSERT(!fast_elements_);
8159 Handle<NumberDictionary> dict(NumberDictionary::cast(*storage_)); 8522 Handle<NumberDictionary> dict(NumberDictionary::cast(*storage_));
8160 Handle<NumberDictionary> result = 8523 Handle<NumberDictionary> result =
8161 Factory::DictionaryAtNumberPut(dict, index, elm); 8524 isolate_->factory()->DictionaryAtNumberPut(dict, index, elm);
8162 if (!result.is_identical_to(dict)) { 8525 if (!result.is_identical_to(dict)) {
8163 // Dictionary needed to grow. 8526 // Dictionary needed to grow.
8164 clear_storage(); 8527 clear_storage();
8165 set_storage(*result); 8528 set_storage(*result);
8166 } 8529 }
8167 } 8530 }
8168 8531
8169 void increase_index_offset(uint32_t delta) { 8532 void increase_index_offset(uint32_t delta) {
8170 if (JSObject::kMaxElementCount - index_offset_ < delta) { 8533 if (JSObject::kMaxElementCount - index_offset_ < delta) {
8171 index_offset_ = JSObject::kMaxElementCount; 8534 index_offset_ = JSObject::kMaxElementCount;
8172 } else { 8535 } else {
8173 index_offset_ += delta; 8536 index_offset_ += delta;
8174 } 8537 }
8175 } 8538 }
8176 8539
8177 Handle<JSArray> ToArray() { 8540 Handle<JSArray> ToArray() {
8178 Handle<JSArray> array = Factory::NewJSArray(0); 8541 Handle<JSArray> array = isolate_->factory()->NewJSArray(0);
8179 Handle<Object> length = 8542 Handle<Object> length =
8180 Factory::NewNumber(static_cast<double>(index_offset_)); 8543 isolate_->factory()->NewNumber(static_cast<double>(index_offset_));
8181 Handle<Map> map; 8544 Handle<Map> map;
8182 if (fast_elements_) { 8545 if (fast_elements_) {
8183 map = Factory::GetFastElementsMap(Handle<Map>(array->map())); 8546 map = isolate_->factory()->GetFastElementsMap(Handle<Map>(array->map()));
8184 } else { 8547 } else {
8185 map = Factory::GetSlowElementsMap(Handle<Map>(array->map())); 8548 map = isolate_->factory()->GetSlowElementsMap(Handle<Map>(array->map()));
8186 } 8549 }
8187 array->set_map(*map); 8550 array->set_map(*map);
8188 array->set_length(*length); 8551 array->set_length(*length);
8189 array->set_elements(*storage_); 8552 array->set_elements(*storage_);
8190 return array; 8553 return array;
8191 } 8554 }
8192 8555
8193 private: 8556 private:
8194 // Convert storage to dictionary mode. 8557 // Convert storage to dictionary mode.
8195 void SetDictionaryMode(uint32_t index) { 8558 void SetDictionaryMode(uint32_t index) {
8196 ASSERT(fast_elements_); 8559 ASSERT(fast_elements_);
8197 Handle<FixedArray> current_storage(*storage_); 8560 Handle<FixedArray> current_storage(*storage_);
8198 Handle<NumberDictionary> slow_storage( 8561 Handle<NumberDictionary> slow_storage(
8199 Factory::NewNumberDictionary(current_storage->length())); 8562 isolate_->factory()->NewNumberDictionary(current_storage->length()));
8200 uint32_t current_length = static_cast<uint32_t>(current_storage->length()); 8563 uint32_t current_length = static_cast<uint32_t>(current_storage->length());
8201 for (uint32_t i = 0; i < current_length; i++) { 8564 for (uint32_t i = 0; i < current_length; i++) {
8202 HandleScope loop_scope; 8565 HandleScope loop_scope;
8203 Handle<Object> element(current_storage->get(i)); 8566 Handle<Object> element(current_storage->get(i));
8204 if (!element->IsTheHole()) { 8567 if (!element->IsTheHole()) {
8205 Handle<NumberDictionary> new_storage = 8568 Handle<NumberDictionary> new_storage =
8206 Factory::DictionaryAtNumberPut(slow_storage, i, element); 8569 isolate_->factory()->DictionaryAtNumberPut(slow_storage, i, element);
8207 if (!new_storage.is_identical_to(slow_storage)) { 8570 if (!new_storage.is_identical_to(slow_storage)) {
8208 slow_storage = loop_scope.CloseAndEscape(new_storage); 8571 slow_storage = loop_scope.CloseAndEscape(new_storage);
8209 } 8572 }
8210 } 8573 }
8211 } 8574 }
8212 clear_storage(); 8575 clear_storage();
8213 set_storage(*slow_storage); 8576 set_storage(*slow_storage);
8214 fast_elements_ = false; 8577 fast_elements_ = false;
8215 } 8578 }
8216 8579
8217 inline void clear_storage() { 8580 inline void clear_storage() {
8218 GlobalHandles::Destroy(Handle<Object>::cast(storage_).location()); 8581 isolate_->global_handles()->Destroy(
8582 Handle<Object>::cast(storage_).location());
8219 } 8583 }
8220 8584
8221 inline void set_storage(FixedArray* storage) { 8585 inline void set_storage(FixedArray* storage) {
8222 storage_ = Handle<FixedArray>::cast(GlobalHandles::Create(storage)); 8586 storage_ = Handle<FixedArray>::cast(
8587 isolate_->global_handles()->Create(storage));
8223 } 8588 }
8224 8589
8590 Isolate* isolate_;
8225 Handle<FixedArray> storage_; // Always a global handle. 8591 Handle<FixedArray> storage_; // Always a global handle.
8226 // Index after last seen index. Always less than or equal to 8592 // Index after last seen index. Always less than or equal to
8227 // JSObject::kMaxElementCount. 8593 // JSObject::kMaxElementCount.
8228 uint32_t index_offset_; 8594 uint32_t index_offset_;
8229 bool fast_elements_; 8595 bool fast_elements_;
8230 }; 8596 };
8231 8597
8232 8598
8233 static uint32_t EstimateElementCount(Handle<JSArray> array) { 8599 static uint32_t EstimateElementCount(Handle<JSArray> array) {
8234 uint32_t length = static_cast<uint32_t>(array->length()->Number()); 8600 uint32_t length = static_cast<uint32_t>(array->length()->Number());
(...skipping 27 matching lines...) Expand all
8262 return length; 8628 return length;
8263 } 8629 }
8264 // As an estimate, we assume that the prototype doesn't contain any 8630 // As an estimate, we assume that the prototype doesn't contain any
8265 // inherited elements. 8631 // inherited elements.
8266 return element_count; 8632 return element_count;
8267 } 8633 }
8268 8634
8269 8635
8270 8636
8271 template<class ExternalArrayClass, class ElementType> 8637 template<class ExternalArrayClass, class ElementType>
8272 static void IterateExternalArrayElements(Handle<JSObject> receiver, 8638 static void IterateExternalArrayElements(Isolate* isolate,
8639 Handle<JSObject> receiver,
8273 bool elements_are_ints, 8640 bool elements_are_ints,
8274 bool elements_are_guaranteed_smis, 8641 bool elements_are_guaranteed_smis,
8275 ArrayConcatVisitor* visitor) { 8642 ArrayConcatVisitor* visitor) {
8276 Handle<ExternalArrayClass> array( 8643 Handle<ExternalArrayClass> array(
8277 ExternalArrayClass::cast(receiver->elements())); 8644 ExternalArrayClass::cast(receiver->elements()));
8278 uint32_t len = static_cast<uint32_t>(array->length()); 8645 uint32_t len = static_cast<uint32_t>(array->length());
8279 8646
8280 ASSERT(visitor != NULL); 8647 ASSERT(visitor != NULL);
8281 if (elements_are_ints) { 8648 if (elements_are_ints) {
8282 if (elements_are_guaranteed_smis) { 8649 if (elements_are_guaranteed_smis) {
8283 for (uint32_t j = 0; j < len; j++) { 8650 for (uint32_t j = 0; j < len; j++) {
8284 HandleScope loop_scope; 8651 HandleScope loop_scope;
8285 Handle<Smi> e(Smi::FromInt(static_cast<int>(array->get(j)))); 8652 Handle<Smi> e(Smi::FromInt(static_cast<int>(array->get(j))));
8286 visitor->visit(j, e); 8653 visitor->visit(j, e);
8287 } 8654 }
8288 } else { 8655 } else {
8289 for (uint32_t j = 0; j < len; j++) { 8656 for (uint32_t j = 0; j < len; j++) {
8290 HandleScope loop_scope; 8657 HandleScope loop_scope;
8291 int64_t val = static_cast<int64_t>(array->get(j)); 8658 int64_t val = static_cast<int64_t>(array->get(j));
8292 if (Smi::IsValid(static_cast<intptr_t>(val))) { 8659 if (Smi::IsValid(static_cast<intptr_t>(val))) {
8293 Handle<Smi> e(Smi::FromInt(static_cast<int>(val))); 8660 Handle<Smi> e(Smi::FromInt(static_cast<int>(val)));
8294 visitor->visit(j, e); 8661 visitor->visit(j, e);
8295 } else { 8662 } else {
8296 Handle<Object> e = 8663 Handle<Object> e =
8297 Factory::NewNumber(static_cast<ElementType>(val)); 8664 isolate->factory()->NewNumber(static_cast<ElementType>(val));
8298 visitor->visit(j, e); 8665 visitor->visit(j, e);
8299 } 8666 }
8300 } 8667 }
8301 } 8668 }
8302 } else { 8669 } else {
8303 for (uint32_t j = 0; j < len; j++) { 8670 for (uint32_t j = 0; j < len; j++) {
8304 HandleScope loop_scope; 8671 HandleScope loop_scope(isolate);
8305 Handle<Object> e = Factory::NewNumber(array->get(j)); 8672 Handle<Object> e = isolate->factory()->NewNumber(array->get(j));
8306 visitor->visit(j, e); 8673 visitor->visit(j, e);
8307 } 8674 }
8308 } 8675 }
8309 } 8676 }
8310 8677
8311 8678
8312 // Used for sorting indices in a List<uint32_t>. 8679 // Used for sorting indices in a List<uint32_t>.
8313 static int compareUInt32(const uint32_t* ap, const uint32_t* bp) { 8680 static int compareUInt32(const uint32_t* ap, const uint32_t* bp) {
8314 uint32_t a = *ap; 8681 uint32_t a = *ap;
8315 uint32_t b = *bp; 8682 uint32_t b = *bp;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
8424 /** 8791 /**
8425 * A helper function that visits elements of a JSArray in numerical 8792 * A helper function that visits elements of a JSArray in numerical
8426 * order. 8793 * order.
8427 * 8794 *
8428 * The visitor argument called for each existing element in the array 8795 * The visitor argument called for each existing element in the array
8429 * with the element index and the element's value. 8796 * with the element index and the element's value.
8430 * Afterwards it increments the base-index of the visitor by the array 8797 * Afterwards it increments the base-index of the visitor by the array
8431 * length. 8798 * length.
8432 * Returns false if any access threw an exception, otherwise true. 8799 * Returns false if any access threw an exception, otherwise true.
8433 */ 8800 */
8434 static bool IterateElements(Handle<JSArray> receiver, 8801 static bool IterateElements(Isolate* isolate,
8802 Handle<JSArray> receiver,
8435 ArrayConcatVisitor* visitor) { 8803 ArrayConcatVisitor* visitor) {
8436 uint32_t length = static_cast<uint32_t>(receiver->length()->Number()); 8804 uint32_t length = static_cast<uint32_t>(receiver->length()->Number());
8437 switch (receiver->GetElementsKind()) { 8805 switch (receiver->GetElementsKind()) {
8438 case JSObject::FAST_ELEMENTS: { 8806 case JSObject::FAST_ELEMENTS: {
8439 // Run through the elements FixedArray and use HasElement and GetElement 8807 // Run through the elements FixedArray and use HasElement and GetElement
8440 // to check the prototype for missing elements. 8808 // to check the prototype for missing elements.
8441 Handle<FixedArray> elements(FixedArray::cast(receiver->elements())); 8809 Handle<FixedArray> elements(FixedArray::cast(receiver->elements()));
8442 int fast_length = static_cast<int>(length); 8810 int fast_length = static_cast<int>(length);
8443 ASSERT(fast_length <= elements->length()); 8811 ASSERT(fast_length <= elements->length());
8444 for (int j = 0; j < fast_length; j++) { 8812 for (int j = 0; j < fast_length; j++) {
8445 HandleScope loop_scope; 8813 HandleScope loop_scope(isolate);
8446 Handle<Object> element_value(elements->get(j)); 8814 Handle<Object> element_value(elements->get(j), isolate);
8447 if (!element_value->IsTheHole()) { 8815 if (!element_value->IsTheHole()) {
8448 visitor->visit(j, element_value); 8816 visitor->visit(j, element_value);
8449 } else if (receiver->HasElement(j)) { 8817 } else if (receiver->HasElement(j)) {
8450 // Call GetElement on receiver, not its prototype, or getters won't 8818 // Call GetElement on receiver, not its prototype, or getters won't
8451 // have the correct receiver. 8819 // have the correct receiver.
8452 element_value = GetElement(receiver, j); 8820 element_value = GetElement(receiver, j);
8453 if (element_value.is_null()) return false; 8821 if (element_value.is_null()) return false;
8454 visitor->visit(j, element_value); 8822 visitor->visit(j, element_value);
8455 } 8823 }
8456 } 8824 }
(...skipping 25 matching lines...) Expand all
8482 Handle<ExternalPixelArray> pixels(ExternalPixelArray::cast( 8850 Handle<ExternalPixelArray> pixels(ExternalPixelArray::cast(
8483 receiver->elements())); 8851 receiver->elements()));
8484 for (uint32_t j = 0; j < length; j++) { 8852 for (uint32_t j = 0; j < length; j++) {
8485 Handle<Smi> e(Smi::FromInt(pixels->get(j))); 8853 Handle<Smi> e(Smi::FromInt(pixels->get(j)));
8486 visitor->visit(j, e); 8854 visitor->visit(j, e);
8487 } 8855 }
8488 break; 8856 break;
8489 } 8857 }
8490 case JSObject::EXTERNAL_BYTE_ELEMENTS: { 8858 case JSObject::EXTERNAL_BYTE_ELEMENTS: {
8491 IterateExternalArrayElements<ExternalByteArray, int8_t>( 8859 IterateExternalArrayElements<ExternalByteArray, int8_t>(
8492 receiver, true, true, visitor); 8860 isolate, receiver, true, true, visitor);
8493 break; 8861 break;
8494 } 8862 }
8495 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { 8863 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
8496 IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>( 8864 IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>(
8497 receiver, true, true, visitor); 8865 isolate, receiver, true, true, visitor);
8498 break; 8866 break;
8499 } 8867 }
8500 case JSObject::EXTERNAL_SHORT_ELEMENTS: { 8868 case JSObject::EXTERNAL_SHORT_ELEMENTS: {
8501 IterateExternalArrayElements<ExternalShortArray, int16_t>( 8869 IterateExternalArrayElements<ExternalShortArray, int16_t>(
8502 receiver, true, true, visitor); 8870 isolate, receiver, true, true, visitor);
8503 break; 8871 break;
8504 } 8872 }
8505 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { 8873 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
8506 IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>( 8874 IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>(
8507 receiver, true, true, visitor); 8875 isolate, receiver, true, true, visitor);
8508 break; 8876 break;
8509 } 8877 }
8510 case JSObject::EXTERNAL_INT_ELEMENTS: { 8878 case JSObject::EXTERNAL_INT_ELEMENTS: {
8511 IterateExternalArrayElements<ExternalIntArray, int32_t>( 8879 IterateExternalArrayElements<ExternalIntArray, int32_t>(
8512 receiver, true, false, visitor); 8880 isolate, receiver, true, false, visitor);
8513 break; 8881 break;
8514 } 8882 }
8515 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: { 8883 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: {
8516 IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>( 8884 IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>(
8517 receiver, true, false, visitor); 8885 isolate, receiver, true, false, visitor);
8518 break; 8886 break;
8519 } 8887 }
8520 case JSObject::EXTERNAL_FLOAT_ELEMENTS: { 8888 case JSObject::EXTERNAL_FLOAT_ELEMENTS: {
8521 IterateExternalArrayElements<ExternalFloatArray, float>( 8889 IterateExternalArrayElements<ExternalFloatArray, float>(
8522 receiver, false, false, visitor); 8890 isolate, receiver, false, false, visitor);
8523 break; 8891 break;
8524 } 8892 }
8525 default: 8893 default:
8526 UNREACHABLE(); 8894 UNREACHABLE();
8527 break; 8895 break;
8528 } 8896 }
8529 visitor->increase_index_offset(length); 8897 visitor->increase_index_offset(length);
8530 return true; 8898 return true;
8531 } 8899 }
8532 8900
8533 8901
8534 /** 8902 /**
8535 * Array::concat implementation. 8903 * Array::concat implementation.
8536 * See ECMAScript 262, 15.4.4.4. 8904 * See ECMAScript 262, 15.4.4.4.
8537 * TODO(581): Fix non-compliance for very large concatenations and update to 8905 * TODO(581): Fix non-compliance for very large concatenations and update to
8538 * following the ECMAScript 5 specification. 8906 * following the ECMAScript 5 specification.
8539 */ 8907 */
8540 static MaybeObject* Runtime_ArrayConcat(Arguments args) { 8908 static MaybeObject* Runtime_ArrayConcat(RUNTIME_CALLING_CONVENTION) {
8909 RUNTIME_GET_ISOLATE;
8541 ASSERT(args.length() == 1); 8910 ASSERT(args.length() == 1);
8542 HandleScope handle_scope; 8911 HandleScope handle_scope(isolate);
8543 8912
8544 CONVERT_ARG_CHECKED(JSArray, arguments, 0); 8913 CONVERT_ARG_CHECKED(JSArray, arguments, 0);
8545 int argument_count = static_cast<int>(arguments->length()->Number()); 8914 int argument_count = static_cast<int>(arguments->length()->Number());
8546 RUNTIME_ASSERT(arguments->HasFastElements()); 8915 RUNTIME_ASSERT(arguments->HasFastElements());
8547 Handle<FixedArray> elements(FixedArray::cast(arguments->elements())); 8916 Handle<FixedArray> elements(FixedArray::cast(arguments->elements()));
8548 8917
8549 // Pass 1: estimate the length and number of elements of the result. 8918 // Pass 1: estimate the length and number of elements of the result.
8550 // The actual length can be larger if any of the arguments have getters 8919 // The actual length can be larger if any of the arguments have getters
8551 // that mutate other arguments (but will otherwise be precise). 8920 // that mutate other arguments (but will otherwise be precise).
8552 // The number of elements is precise if there are no inherited elements. 8921 // The number of elements is precise if there are no inherited elements.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
8587 8956
8588 // If estimated number of elements is more than half of length, a 8957 // If estimated number of elements is more than half of length, a
8589 // fixed array (fast case) is more time and space-efficient than a 8958 // fixed array (fast case) is more time and space-efficient than a
8590 // dictionary. 8959 // dictionary.
8591 bool fast_case = (estimate_nof_elements * 2) >= estimate_result_length; 8960 bool fast_case = (estimate_nof_elements * 2) >= estimate_result_length;
8592 8961
8593 Handle<FixedArray> storage; 8962 Handle<FixedArray> storage;
8594 if (fast_case) { 8963 if (fast_case) {
8595 // The backing storage array must have non-existing elements to 8964 // The backing storage array must have non-existing elements to
8596 // preserve holes across concat operations. 8965 // preserve holes across concat operations.
8597 storage = Factory::NewFixedArrayWithHoles(estimate_result_length); 8966 storage = isolate->factory()->NewFixedArrayWithHoles(
8967 estimate_result_length);
8598 } else { 8968 } else {
8599 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate 8969 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate
8600 uint32_t at_least_space_for = estimate_nof_elements + 8970 uint32_t at_least_space_for = estimate_nof_elements +
8601 (estimate_nof_elements >> 2); 8971 (estimate_nof_elements >> 2);
8602 storage = Handle<FixedArray>::cast( 8972 storage = Handle<FixedArray>::cast(
8603 Factory::NewNumberDictionary(at_least_space_for)); 8973 isolate->factory()->NewNumberDictionary(at_least_space_for));
8604 } 8974 }
8605 8975
8606 ArrayConcatVisitor visitor(storage, fast_case); 8976 ArrayConcatVisitor visitor(isolate, storage, fast_case);
8607 8977
8608 for (int i = 0; i < argument_count; i++) { 8978 for (int i = 0; i < argument_count; i++) {
8609 Handle<Object> obj(elements->get(i)); 8979 Handle<Object> obj(elements->get(i));
8610 if (obj->IsJSArray()) { 8980 if (obj->IsJSArray()) {
8611 Handle<JSArray> array = Handle<JSArray>::cast(obj); 8981 Handle<JSArray> array = Handle<JSArray>::cast(obj);
8612 if (!IterateElements(array, &visitor)) { 8982 if (!IterateElements(isolate, array, &visitor)) {
8613 return Failure::Exception(); 8983 return Failure::Exception();
8614 } 8984 }
8615 } else { 8985 } else {
8616 visitor.visit(0, obj); 8986 visitor.visit(0, obj);
8617 visitor.increase_index_offset(1); 8987 visitor.increase_index_offset(1);
8618 } 8988 }
8619 } 8989 }
8620 8990
8621 return *visitor.ToArray(); 8991 return *visitor.ToArray();
8622 } 8992 }
8623 8993
8624 8994
8625 // This will not allocate (flatten the string), but it may run 8995 // This will not allocate (flatten the string), but it may run
8626 // very slowly for very deeply nested ConsStrings. For debugging use only. 8996 // very slowly for very deeply nested ConsStrings. For debugging use only.
8627 static MaybeObject* Runtime_GlobalPrint(Arguments args) { 8997 static MaybeObject* Runtime_GlobalPrint(RUNTIME_CALLING_CONVENTION) {
8998 RUNTIME_GET_ISOLATE;
8628 NoHandleAllocation ha; 8999 NoHandleAllocation ha;
8629 ASSERT(args.length() == 1); 9000 ASSERT(args.length() == 1);
8630 9001
8631 CONVERT_CHECKED(String, string, args[0]); 9002 CONVERT_CHECKED(String, string, args[0]);
8632 StringInputBuffer buffer(string); 9003 StringInputBuffer buffer(string);
8633 while (buffer.has_more()) { 9004 while (buffer.has_more()) {
8634 uint16_t character = buffer.GetNext(); 9005 uint16_t character = buffer.GetNext();
8635 PrintF("%c", character); 9006 PrintF("%c", character);
8636 } 9007 }
8637 return string; 9008 return string;
8638 } 9009 }
8639 9010
8640 // Moves all own elements of an object, that are below a limit, to positions 9011 // Moves all own elements of an object, that are below a limit, to positions
8641 // starting at zero. All undefined values are placed after non-undefined values, 9012 // starting at zero. All undefined values are placed after non-undefined values,
8642 // and are followed by non-existing element. Does not change the length 9013 // and are followed by non-existing element. Does not change the length
8643 // property. 9014 // property.
8644 // Returns the number of non-undefined elements collected. 9015 // Returns the number of non-undefined elements collected.
8645 static MaybeObject* Runtime_RemoveArrayHoles(Arguments args) { 9016 static MaybeObject* Runtime_RemoveArrayHoles(RUNTIME_CALLING_CONVENTION) {
9017 RUNTIME_GET_ISOLATE;
8646 ASSERT(args.length() == 2); 9018 ASSERT(args.length() == 2);
8647 CONVERT_CHECKED(JSObject, object, args[0]); 9019 CONVERT_CHECKED(JSObject, object, args[0]);
8648 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); 9020 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]);
8649 return object->PrepareElementsForSort(limit); 9021 return object->PrepareElementsForSort(limit);
8650 } 9022 }
8651 9023
8652 9024
8653 // Move contents of argument 0 (an array) to argument 1 (an array) 9025 // Move contents of argument 0 (an array) to argument 1 (an array)
8654 static MaybeObject* Runtime_MoveArrayContents(Arguments args) { 9026 static MaybeObject* Runtime_MoveArrayContents(RUNTIME_CALLING_CONVENTION) {
9027 RUNTIME_GET_ISOLATE;
8655 ASSERT(args.length() == 2); 9028 ASSERT(args.length() == 2);
8656 CONVERT_CHECKED(JSArray, from, args[0]); 9029 CONVERT_CHECKED(JSArray, from, args[0]);
8657 CONVERT_CHECKED(JSArray, to, args[1]); 9030 CONVERT_CHECKED(JSArray, to, args[1]);
8658 HeapObject* new_elements = from->elements(); 9031 HeapObject* new_elements = from->elements();
8659 MaybeObject* maybe_new_map; 9032 MaybeObject* maybe_new_map;
8660 if (new_elements->map() == Heap::fixed_array_map() || 9033 if (new_elements->map() == isolate->heap()->fixed_array_map() ||
8661 new_elements->map() == Heap::fixed_cow_array_map()) { 9034 new_elements->map() == isolate->heap()->fixed_cow_array_map()) {
8662 maybe_new_map = to->map()->GetFastElementsMap(); 9035 maybe_new_map = to->map()->GetFastElementsMap();
8663 } else { 9036 } else {
8664 maybe_new_map = to->map()->GetSlowElementsMap(); 9037 maybe_new_map = to->map()->GetSlowElementsMap();
8665 } 9038 }
8666 Object* new_map; 9039 Object* new_map;
8667 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; 9040 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map;
8668 to->set_map(Map::cast(new_map)); 9041 to->set_map(Map::cast(new_map));
8669 to->set_elements(new_elements); 9042 to->set_elements(new_elements);
8670 to->set_length(from->length()); 9043 to->set_length(from->length());
8671 Object* obj; 9044 Object* obj;
8672 { MaybeObject* maybe_obj = from->ResetElements(); 9045 { MaybeObject* maybe_obj = from->ResetElements();
8673 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 9046 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
8674 } 9047 }
8675 from->set_length(Smi::FromInt(0)); 9048 from->set_length(Smi::FromInt(0));
8676 return to; 9049 return to;
8677 } 9050 }
8678 9051
8679 9052
8680 // How many elements does this object/array have? 9053 // How many elements does this object/array have?
8681 static MaybeObject* Runtime_EstimateNumberOfElements(Arguments args) { 9054 static MaybeObject* Runtime_EstimateNumberOfElements(
9055 RUNTIME_CALLING_CONVENTION) {
9056 RUNTIME_GET_ISOLATE;
8682 ASSERT(args.length() == 1); 9057 ASSERT(args.length() == 1);
8683 CONVERT_CHECKED(JSObject, object, args[0]); 9058 CONVERT_CHECKED(JSObject, object, args[0]);
8684 HeapObject* elements = object->elements(); 9059 HeapObject* elements = object->elements();
8685 if (elements->IsDictionary()) { 9060 if (elements->IsDictionary()) {
8686 return Smi::FromInt(NumberDictionary::cast(elements)->NumberOfElements()); 9061 return Smi::FromInt(NumberDictionary::cast(elements)->NumberOfElements());
8687 } else if (object->IsJSArray()) { 9062 } else if (object->IsJSArray()) {
8688 return JSArray::cast(object)->length(); 9063 return JSArray::cast(object)->length();
8689 } else { 9064 } else {
8690 return Smi::FromInt(FixedArray::cast(elements)->length()); 9065 return Smi::FromInt(FixedArray::cast(elements)->length());
8691 } 9066 }
8692 } 9067 }
8693 9068
8694 9069
8695 static MaybeObject* Runtime_SwapElements(Arguments args) { 9070 static MaybeObject* Runtime_SwapElements(RUNTIME_CALLING_CONVENTION) {
8696 HandleScope handle_scope; 9071 RUNTIME_GET_ISOLATE;
9072 HandleScope handle_scope(isolate);
8697 9073
8698 ASSERT_EQ(3, args.length()); 9074 ASSERT_EQ(3, args.length());
8699 9075
8700 CONVERT_ARG_CHECKED(JSObject, object, 0); 9076 CONVERT_ARG_CHECKED(JSObject, object, 0);
8701 Handle<Object> key1 = args.at<Object>(1); 9077 Handle<Object> key1 = args.at<Object>(1);
8702 Handle<Object> key2 = args.at<Object>(2); 9078 Handle<Object> key2 = args.at<Object>(2);
8703 9079
8704 uint32_t index1, index2; 9080 uint32_t index1, index2;
8705 if (!key1->ToArrayIndex(&index1) 9081 if (!key1->ToArrayIndex(&index1)
8706 || !key2->ToArrayIndex(&index2)) { 9082 || !key2->ToArrayIndex(&index2)) {
8707 return Top::ThrowIllegalOperation(); 9083 return isolate->ThrowIllegalOperation();
8708 } 9084 }
8709 9085
8710 Handle<JSObject> jsobject = Handle<JSObject>::cast(object); 9086 Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
8711 Handle<Object> tmp1 = GetElement(jsobject, index1); 9087 Handle<Object> tmp1 = GetElement(jsobject, index1);
8712 RETURN_IF_EMPTY_HANDLE(tmp1); 9088 RETURN_IF_EMPTY_HANDLE(isolate, tmp1);
8713 Handle<Object> tmp2 = GetElement(jsobject, index2); 9089 Handle<Object> tmp2 = GetElement(jsobject, index2);
8714 RETURN_IF_EMPTY_HANDLE(tmp2); 9090 RETURN_IF_EMPTY_HANDLE(isolate, tmp2);
8715 9091
8716 RETURN_IF_EMPTY_HANDLE(SetElement(jsobject, index1, tmp2, kStrictMode)); 9092 RETURN_IF_EMPTY_HANDLE(isolate,
8717 RETURN_IF_EMPTY_HANDLE(SetElement(jsobject, index2, tmp1, kStrictMode)); 9093 SetElement(jsobject, index1, tmp2, kStrictMode));
9094 RETURN_IF_EMPTY_HANDLE(isolate,
9095 SetElement(jsobject, index2, tmp1, kStrictMode));
8718 9096
8719 return Heap::undefined_value(); 9097 return isolate->heap()->undefined_value();
8720 } 9098 }
8721 9099
8722 9100
8723 // Returns an array that tells you where in the [0, length) interval an array 9101 // Returns an array that tells you where in the [0, length) interval an array
8724 // might have elements. Can either return keys (positive integers) or 9102 // might have elements. Can either return keys (positive integers) or
8725 // intervals (pair of a negative integer (-start-1) followed by a 9103 // intervals (pair of a negative integer (-start-1) followed by a
8726 // positive (length)) or undefined values. 9104 // positive (length)) or undefined values.
8727 // Intervals can span over some keys that are not in the object. 9105 // Intervals can span over some keys that are not in the object.
8728 static MaybeObject* Runtime_GetArrayKeys(Arguments args) { 9106 static MaybeObject* Runtime_GetArrayKeys(RUNTIME_CALLING_CONVENTION) {
9107 RUNTIME_GET_ISOLATE;
8729 ASSERT(args.length() == 2); 9108 ASSERT(args.length() == 2);
8730 HandleScope scope; 9109 HandleScope scope(isolate);
8731 CONVERT_ARG_CHECKED(JSObject, array, 0); 9110 CONVERT_ARG_CHECKED(JSObject, array, 0);
8732 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); 9111 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]);
8733 if (array->elements()->IsDictionary()) { 9112 if (array->elements()->IsDictionary()) {
8734 // Create an array and get all the keys into it, then remove all the 9113 // Create an array and get all the keys into it, then remove all the
8735 // keys that are not integers in the range 0 to length-1. 9114 // keys that are not integers in the range 0 to length-1.
8736 Handle<FixedArray> keys = GetKeysInFixedArrayFor(array, INCLUDE_PROTOS); 9115 Handle<FixedArray> keys = GetKeysInFixedArrayFor(array, INCLUDE_PROTOS);
8737 int keys_length = keys->length(); 9116 int keys_length = keys->length();
8738 for (int i = 0; i < keys_length; i++) { 9117 for (int i = 0; i < keys_length; i++) {
8739 Object* key = keys->get(i); 9118 Object* key = keys->get(i);
8740 uint32_t index = 0; 9119 uint32_t index = 0;
8741 if (!key->ToArrayIndex(&index) || index >= length) { 9120 if (!key->ToArrayIndex(&index) || index >= length) {
8742 // Zap invalid keys. 9121 // Zap invalid keys.
8743 keys->set_undefined(i); 9122 keys->set_undefined(i);
8744 } 9123 }
8745 } 9124 }
8746 return *Factory::NewJSArrayWithElements(keys); 9125 return *isolate->factory()->NewJSArrayWithElements(keys);
8747 } else { 9126 } else {
8748 ASSERT(array->HasFastElements()); 9127 ASSERT(array->HasFastElements());
8749 Handle<FixedArray> single_interval = Factory::NewFixedArray(2); 9128 Handle<FixedArray> single_interval = isolate->factory()->NewFixedArray(2);
8750 // -1 means start of array. 9129 // -1 means start of array.
8751 single_interval->set(0, Smi::FromInt(-1)); 9130 single_interval->set(0, Smi::FromInt(-1));
8752 uint32_t actual_length = 9131 uint32_t actual_length =
8753 static_cast<uint32_t>(FixedArray::cast(array->elements())->length()); 9132 static_cast<uint32_t>(FixedArray::cast(array->elements())->length());
8754 uint32_t min_length = actual_length < length ? actual_length : length; 9133 uint32_t min_length = actual_length < length ? actual_length : length;
8755 Handle<Object> length_object = 9134 Handle<Object> length_object =
8756 Factory::NewNumber(static_cast<double>(min_length)); 9135 isolate->factory()->NewNumber(static_cast<double>(min_length));
8757 single_interval->set(1, *length_object); 9136 single_interval->set(1, *length_object);
8758 return *Factory::NewJSArrayWithElements(single_interval); 9137 return *isolate->factory()->NewJSArrayWithElements(single_interval);
8759 } 9138 }
8760 } 9139 }
8761 9140
8762 9141
8763 // DefineAccessor takes an optional final argument which is the 9142 // DefineAccessor takes an optional final argument which is the
8764 // property attributes (eg, DONT_ENUM, DONT_DELETE). IMPORTANT: due 9143 // property attributes (eg, DONT_ENUM, DONT_DELETE). IMPORTANT: due
8765 // to the way accessors are implemented, it is set for both the getter 9144 // to the way accessors are implemented, it is set for both the getter
8766 // and setter on the first call to DefineAccessor and ignored on 9145 // and setter on the first call to DefineAccessor and ignored on
8767 // subsequent calls. 9146 // subsequent calls.
8768 static MaybeObject* Runtime_DefineAccessor(Arguments args) { 9147 static MaybeObject* Runtime_DefineAccessor(RUNTIME_CALLING_CONVENTION) {
9148 RUNTIME_GET_ISOLATE;
8769 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); 9149 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5);
8770 // Compute attributes. 9150 // Compute attributes.
8771 PropertyAttributes attributes = NONE; 9151 PropertyAttributes attributes = NONE;
8772 if (args.length() == 5) { 9152 if (args.length() == 5) {
8773 CONVERT_CHECKED(Smi, attrs, args[4]); 9153 CONVERT_CHECKED(Smi, attrs, args[4]);
8774 int value = attrs->value(); 9154 int value = attrs->value();
8775 // Only attribute bits should be set. 9155 // Only attribute bits should be set.
8776 ASSERT((value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 9156 ASSERT((value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
8777 attributes = static_cast<PropertyAttributes>(value); 9157 attributes = static_cast<PropertyAttributes>(value);
8778 } 9158 }
8779 9159
8780 CONVERT_CHECKED(JSObject, obj, args[0]); 9160 CONVERT_CHECKED(JSObject, obj, args[0]);
8781 CONVERT_CHECKED(String, name, args[1]); 9161 CONVERT_CHECKED(String, name, args[1]);
8782 CONVERT_CHECKED(Smi, flag, args[2]); 9162 CONVERT_CHECKED(Smi, flag, args[2]);
8783 CONVERT_CHECKED(JSFunction, fun, args[3]); 9163 CONVERT_CHECKED(JSFunction, fun, args[3]);
8784 return obj->DefineAccessor(name, flag->value() == 0, fun, attributes); 9164 return obj->DefineAccessor(name, flag->value() == 0, fun, attributes);
8785 } 9165 }
8786 9166
8787 9167
8788 static MaybeObject* Runtime_LookupAccessor(Arguments args) { 9168 static MaybeObject* Runtime_LookupAccessor(RUNTIME_CALLING_CONVENTION) {
9169 RUNTIME_GET_ISOLATE;
8789 ASSERT(args.length() == 3); 9170 ASSERT(args.length() == 3);
8790 CONVERT_CHECKED(JSObject, obj, args[0]); 9171 CONVERT_CHECKED(JSObject, obj, args[0]);
8791 CONVERT_CHECKED(String, name, args[1]); 9172 CONVERT_CHECKED(String, name, args[1]);
8792 CONVERT_CHECKED(Smi, flag, args[2]); 9173 CONVERT_CHECKED(Smi, flag, args[2]);
8793 return obj->LookupAccessor(name, flag->value() == 0); 9174 return obj->LookupAccessor(name, flag->value() == 0);
8794 } 9175 }
8795 9176
8796 9177
8797 #ifdef ENABLE_DEBUGGER_SUPPORT 9178 #ifdef ENABLE_DEBUGGER_SUPPORT
8798 static MaybeObject* Runtime_DebugBreak(Arguments args) { 9179 static MaybeObject* Runtime_DebugBreak(RUNTIME_CALLING_CONVENTION) {
9180 RUNTIME_GET_ISOLATE;
8799 ASSERT(args.length() == 0); 9181 ASSERT(args.length() == 0);
8800 return Execution::DebugBreakHelper(); 9182 return Execution::DebugBreakHelper();
8801 } 9183 }
8802 9184
8803 9185
8804 // Helper functions for wrapping and unwrapping stack frame ids. 9186 // Helper functions for wrapping and unwrapping stack frame ids.
8805 static Smi* WrapFrameId(StackFrame::Id id) { 9187 static Smi* WrapFrameId(StackFrame::Id id) {
8806 ASSERT(IsAligned(OffsetFrom(id), static_cast<intptr_t>(4))); 9188 ASSERT(IsAligned(OffsetFrom(id), static_cast<intptr_t>(4)));
8807 return Smi::FromInt(id >> 2); 9189 return Smi::FromInt(id >> 2);
8808 } 9190 }
8809 9191
8810 9192
8811 static StackFrame::Id UnwrapFrameId(Smi* wrapped) { 9193 static StackFrame::Id UnwrapFrameId(Smi* wrapped) {
8812 return static_cast<StackFrame::Id>(wrapped->value() << 2); 9194 return static_cast<StackFrame::Id>(wrapped->value() << 2);
8813 } 9195 }
8814 9196
8815 9197
8816 // Adds a JavaScript function as a debug event listener. 9198 // Adds a JavaScript function as a debug event listener.
8817 // args[0]: debug event listener function to set or null or undefined for 9199 // args[0]: debug event listener function to set or null or undefined for
8818 // clearing the event listener function 9200 // clearing the event listener function
8819 // args[1]: object supplied during callback 9201 // args[1]: object supplied during callback
8820 static MaybeObject* Runtime_SetDebugEventListener(Arguments args) { 9202 static MaybeObject* Runtime_SetDebugEventListener(RUNTIME_CALLING_CONVENTION) {
9203 RUNTIME_GET_ISOLATE;
8821 ASSERT(args.length() == 2); 9204 ASSERT(args.length() == 2);
8822 RUNTIME_ASSERT(args[0]->IsJSFunction() || 9205 RUNTIME_ASSERT(args[0]->IsJSFunction() ||
8823 args[0]->IsUndefined() || 9206 args[0]->IsUndefined() ||
8824 args[0]->IsNull()); 9207 args[0]->IsNull());
8825 Handle<Object> callback = args.at<Object>(0); 9208 Handle<Object> callback = args.at<Object>(0);
8826 Handle<Object> data = args.at<Object>(1); 9209 Handle<Object> data = args.at<Object>(1);
8827 Debugger::SetEventListener(callback, data); 9210 isolate->debugger()->SetEventListener(callback, data);
8828 9211
8829 return Heap::undefined_value(); 9212 return isolate->heap()->undefined_value();
8830 } 9213 }
8831 9214
8832 9215
8833 static MaybeObject* Runtime_Break(Arguments args) { 9216 static MaybeObject* Runtime_Break(RUNTIME_CALLING_CONVENTION) {
9217 RUNTIME_GET_ISOLATE;
8834 ASSERT(args.length() == 0); 9218 ASSERT(args.length() == 0);
8835 StackGuard::DebugBreak(); 9219 isolate->stack_guard()->DebugBreak();
8836 return Heap::undefined_value(); 9220 return isolate->heap()->undefined_value();
8837 } 9221 }
8838 9222
8839 9223
8840 static MaybeObject* DebugLookupResultValue(Object* receiver, String* name, 9224 static MaybeObject* DebugLookupResultValue(Heap* heap,
9225 Object* receiver,
9226 String* name,
8841 LookupResult* result, 9227 LookupResult* result,
8842 bool* caught_exception) { 9228 bool* caught_exception) {
8843 Object* value; 9229 Object* value;
8844 switch (result->type()) { 9230 switch (result->type()) {
8845 case NORMAL: 9231 case NORMAL:
8846 value = result->holder()->GetNormalizedProperty(result); 9232 value = result->holder()->GetNormalizedProperty(result);
8847 if (value->IsTheHole()) { 9233 if (value->IsTheHole()) {
8848 return Heap::undefined_value(); 9234 return heap->undefined_value();
8849 } 9235 }
8850 return value; 9236 return value;
8851 case FIELD: 9237 case FIELD:
8852 value = 9238 value =
8853 JSObject::cast( 9239 JSObject::cast(
8854 result->holder())->FastPropertyAt(result->GetFieldIndex()); 9240 result->holder())->FastPropertyAt(result->GetFieldIndex());
8855 if (value->IsTheHole()) { 9241 if (value->IsTheHole()) {
8856 return Heap::undefined_value(); 9242 return heap->undefined_value();
8857 } 9243 }
8858 return value; 9244 return value;
8859 case CONSTANT_FUNCTION: 9245 case CONSTANT_FUNCTION:
8860 return result->GetConstantFunction(); 9246 return result->GetConstantFunction();
8861 case CALLBACKS: { 9247 case CALLBACKS: {
8862 Object* structure = result->GetCallbackObject(); 9248 Object* structure = result->GetCallbackObject();
8863 if (structure->IsProxy() || structure->IsAccessorInfo()) { 9249 if (structure->IsProxy() || structure->IsAccessorInfo()) {
8864 MaybeObject* maybe_value = receiver->GetPropertyWithCallback( 9250 MaybeObject* maybe_value = receiver->GetPropertyWithCallback(
8865 receiver, structure, name, result->holder()); 9251 receiver, structure, name, result->holder());
8866 if (!maybe_value->ToObject(&value)) { 9252 if (!maybe_value->ToObject(&value)) {
8867 if (maybe_value->IsRetryAfterGC()) return maybe_value; 9253 if (maybe_value->IsRetryAfterGC()) return maybe_value;
8868 ASSERT(maybe_value->IsException()); 9254 ASSERT(maybe_value->IsException());
8869 maybe_value = Top::pending_exception(); 9255 maybe_value = heap->isolate()->pending_exception();
8870 Top::clear_pending_exception(); 9256 heap->isolate()->clear_pending_exception();
8871 if (caught_exception != NULL) { 9257 if (caught_exception != NULL) {
8872 *caught_exception = true; 9258 *caught_exception = true;
8873 } 9259 }
8874 return maybe_value; 9260 return maybe_value;
8875 } 9261 }
8876 return value; 9262 return value;
8877 } else { 9263 } else {
8878 return Heap::undefined_value(); 9264 return heap->undefined_value();
8879 } 9265 }
8880 } 9266 }
8881 case INTERCEPTOR: 9267 case INTERCEPTOR:
8882 case MAP_TRANSITION: 9268 case MAP_TRANSITION:
8883 case CONSTANT_TRANSITION: 9269 case CONSTANT_TRANSITION:
8884 case NULL_DESCRIPTOR: 9270 case NULL_DESCRIPTOR:
8885 return Heap::undefined_value(); 9271 return heap->undefined_value();
8886 default: 9272 default:
8887 UNREACHABLE(); 9273 UNREACHABLE();
8888 } 9274 }
8889 UNREACHABLE(); 9275 UNREACHABLE();
8890 return Heap::undefined_value(); 9276 return heap->undefined_value();
8891 } 9277 }
8892 9278
8893 9279
8894 // Get debugger related details for an object property. 9280 // Get debugger related details for an object property.
8895 // args[0]: object holding property 9281 // args[0]: object holding property
8896 // args[1]: name of the property 9282 // args[1]: name of the property
8897 // 9283 //
8898 // The array returned contains the following information: 9284 // The array returned contains the following information:
8899 // 0: Property value 9285 // 0: Property value
8900 // 1: Property details 9286 // 1: Property details
8901 // 2: Property value is exception 9287 // 2: Property value is exception
8902 // 3: Getter function if defined 9288 // 3: Getter function if defined
8903 // 4: Setter function if defined 9289 // 4: Setter function if defined
8904 // Items 2-4 are only filled if the property has either a getter or a setter 9290 // Items 2-4 are only filled if the property has either a getter or a setter
8905 // defined through __defineGetter__ and/or __defineSetter__. 9291 // defined through __defineGetter__ and/or __defineSetter__.
8906 static MaybeObject* Runtime_DebugGetPropertyDetails(Arguments args) { 9292 static MaybeObject* Runtime_DebugGetPropertyDetails(
8907 HandleScope scope; 9293 RUNTIME_CALLING_CONVENTION) {
9294 RUNTIME_GET_ISOLATE;
9295 HandleScope scope(isolate);
8908 9296
8909 ASSERT(args.length() == 2); 9297 ASSERT(args.length() == 2);
8910 9298
8911 CONVERT_ARG_CHECKED(JSObject, obj, 0); 9299 CONVERT_ARG_CHECKED(JSObject, obj, 0);
8912 CONVERT_ARG_CHECKED(String, name, 1); 9300 CONVERT_ARG_CHECKED(String, name, 1);
8913 9301
8914 // Make sure to set the current context to the context before the debugger was 9302 // Make sure to set the current context to the context before the debugger was
8915 // entered (if the debugger is entered). The reason for switching context here 9303 // entered (if the debugger is entered). The reason for switching context here
8916 // is that for some property lookups (accessors and interceptors) callbacks 9304 // is that for some property lookups (accessors and interceptors) callbacks
8917 // into the embedding application can occour, and the embedding application 9305 // into the embedding application can occour, and the embedding application
8918 // could have the assumption that its own global context is the current 9306 // could have the assumption that its own global context is the current
8919 // context and not some internal debugger context. 9307 // context and not some internal debugger context.
8920 SaveContext save; 9308 SaveContext save(isolate);
8921 if (Debug::InDebugger()) { 9309 if (isolate->debug()->InDebugger()) {
8922 Top::set_context(*Debug::debugger_entry()->GetContext()); 9310 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext());
8923 } 9311 }
8924 9312
8925 // Skip the global proxy as it has no properties and always delegates to the 9313 // Skip the global proxy as it has no properties and always delegates to the
8926 // real global object. 9314 // real global object.
8927 if (obj->IsJSGlobalProxy()) { 9315 if (obj->IsJSGlobalProxy()) {
8928 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); 9316 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
8929 } 9317 }
8930 9318
8931 9319
8932 // Check if the name is trivially convertible to an index and get the element 9320 // Check if the name is trivially convertible to an index and get the element
8933 // if so. 9321 // if so.
8934 uint32_t index; 9322 uint32_t index;
8935 if (name->AsArrayIndex(&index)) { 9323 if (name->AsArrayIndex(&index)) {
8936 Handle<FixedArray> details = Factory::NewFixedArray(2); 9324 Handle<FixedArray> details = isolate->factory()->NewFixedArray(2);
8937 Object* element_or_char; 9325 Object* element_or_char;
8938 { MaybeObject* maybe_element_or_char = 9326 { MaybeObject* maybe_element_or_char =
8939 Runtime::GetElementOrCharAt(obj, index); 9327 Runtime::GetElementOrCharAt(isolate, obj, index);
8940 if (!maybe_element_or_char->ToObject(&element_or_char)) { 9328 if (!maybe_element_or_char->ToObject(&element_or_char)) {
8941 return maybe_element_or_char; 9329 return maybe_element_or_char;
8942 } 9330 }
8943 } 9331 }
8944 details->set(0, element_or_char); 9332 details->set(0, element_or_char);
8945 details->set(1, PropertyDetails(NONE, NORMAL).AsSmi()); 9333 details->set(1, PropertyDetails(NONE, NORMAL).AsSmi());
8946 return *Factory::NewJSArrayWithElements(details); 9334 return *isolate->factory()->NewJSArrayWithElements(details);
8947 } 9335 }
8948 9336
8949 // Find the number of objects making up this. 9337 // Find the number of objects making up this.
8950 int length = LocalPrototypeChainLength(*obj); 9338 int length = LocalPrototypeChainLength(*obj);
8951 9339
8952 // Try local lookup on each of the objects. 9340 // Try local lookup on each of the objects.
8953 Handle<JSObject> jsproto = obj; 9341 Handle<JSObject> jsproto = obj;
8954 for (int i = 0; i < length; i++) { 9342 for (int i = 0; i < length; i++) {
8955 LookupResult result; 9343 LookupResult result;
8956 jsproto->LocalLookup(*name, &result); 9344 jsproto->LocalLookup(*name, &result);
8957 if (result.IsProperty()) { 9345 if (result.IsProperty()) {
8958 // LookupResult is not GC safe as it holds raw object pointers. 9346 // LookupResult is not GC safe as it holds raw object pointers.
8959 // GC can happen later in this code so put the required fields into 9347 // GC can happen later in this code so put the required fields into
8960 // local variables using handles when required for later use. 9348 // local variables using handles when required for later use.
8961 PropertyType result_type = result.type(); 9349 PropertyType result_type = result.type();
8962 Handle<Object> result_callback_obj; 9350 Handle<Object> result_callback_obj;
8963 if (result_type == CALLBACKS) { 9351 if (result_type == CALLBACKS) {
8964 result_callback_obj = Handle<Object>(result.GetCallbackObject()); 9352 result_callback_obj = Handle<Object>(result.GetCallbackObject(),
9353 isolate);
8965 } 9354 }
8966 Smi* property_details = result.GetPropertyDetails().AsSmi(); 9355 Smi* property_details = result.GetPropertyDetails().AsSmi();
8967 // DebugLookupResultValue can cause GC so details from LookupResult needs 9356 // DebugLookupResultValue can cause GC so details from LookupResult needs
8968 // to be copied to handles before this. 9357 // to be copied to handles before this.
8969 bool caught_exception = false; 9358 bool caught_exception = false;
8970 Object* raw_value; 9359 Object* raw_value;
8971 { MaybeObject* maybe_raw_value = 9360 { MaybeObject* maybe_raw_value =
8972 DebugLookupResultValue(*obj, *name, &result, &caught_exception); 9361 DebugLookupResultValue(isolate->heap(), *obj, *name,
9362 &result, &caught_exception);
8973 if (!maybe_raw_value->ToObject(&raw_value)) return maybe_raw_value; 9363 if (!maybe_raw_value->ToObject(&raw_value)) return maybe_raw_value;
8974 } 9364 }
8975 Handle<Object> value(raw_value); 9365 Handle<Object> value(raw_value, isolate);
8976 9366
8977 // If the callback object is a fixed array then it contains JavaScript 9367 // If the callback object is a fixed array then it contains JavaScript
8978 // getter and/or setter. 9368 // getter and/or setter.
8979 bool hasJavaScriptAccessors = result_type == CALLBACKS && 9369 bool hasJavaScriptAccessors = result_type == CALLBACKS &&
8980 result_callback_obj->IsFixedArray(); 9370 result_callback_obj->IsFixedArray();
8981 Handle<FixedArray> details = 9371 Handle<FixedArray> details =
8982 Factory::NewFixedArray(hasJavaScriptAccessors ? 5 : 2); 9372 isolate->factory()->NewFixedArray(hasJavaScriptAccessors ? 5 : 2);
8983 details->set(0, *value); 9373 details->set(0, *value);
8984 details->set(1, property_details); 9374 details->set(1, property_details);
8985 if (hasJavaScriptAccessors) { 9375 if (hasJavaScriptAccessors) {
8986 details->set(2, 9376 details->set(2,
8987 caught_exception ? Heap::true_value() 9377 caught_exception ? isolate->heap()->true_value()
8988 : Heap::false_value()); 9378 : isolate->heap()->false_value());
8989 details->set(3, FixedArray::cast(*result_callback_obj)->get(0)); 9379 details->set(3, FixedArray::cast(*result_callback_obj)->get(0));
8990 details->set(4, FixedArray::cast(*result_callback_obj)->get(1)); 9380 details->set(4, FixedArray::cast(*result_callback_obj)->get(1));
8991 } 9381 }
8992 9382
8993 return *Factory::NewJSArrayWithElements(details); 9383 return *isolate->factory()->NewJSArrayWithElements(details);
8994 } 9384 }
8995 if (i < length - 1) { 9385 if (i < length - 1) {
8996 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); 9386 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
8997 } 9387 }
8998 } 9388 }
8999 9389
9000 return Heap::undefined_value(); 9390 return isolate->heap()->undefined_value();
9001 } 9391 }
9002 9392
9003 9393
9004 static MaybeObject* Runtime_DebugGetProperty(Arguments args) { 9394 static MaybeObject* Runtime_DebugGetProperty(RUNTIME_CALLING_CONVENTION) {
9005 HandleScope scope; 9395 RUNTIME_GET_ISOLATE;
9396 HandleScope scope(isolate);
9006 9397
9007 ASSERT(args.length() == 2); 9398 ASSERT(args.length() == 2);
9008 9399
9009 CONVERT_ARG_CHECKED(JSObject, obj, 0); 9400 CONVERT_ARG_CHECKED(JSObject, obj, 0);
9010 CONVERT_ARG_CHECKED(String, name, 1); 9401 CONVERT_ARG_CHECKED(String, name, 1);
9011 9402
9012 LookupResult result; 9403 LookupResult result;
9013 obj->Lookup(*name, &result); 9404 obj->Lookup(*name, &result);
9014 if (result.IsProperty()) { 9405 if (result.IsProperty()) {
9015 return DebugLookupResultValue(*obj, *name, &result, NULL); 9406 return DebugLookupResultValue(isolate->heap(), *obj, *name, &result, NULL);
9016 } 9407 }
9017 return Heap::undefined_value(); 9408 return isolate->heap()->undefined_value();
9018 } 9409 }
9019 9410
9020 9411
9021 // Return the property type calculated from the property details. 9412 // Return the property type calculated from the property details.
9022 // args[0]: smi with property details. 9413 // args[0]: smi with property details.
9023 static MaybeObject* Runtime_DebugPropertyTypeFromDetails(Arguments args) { 9414 static MaybeObject* Runtime_DebugPropertyTypeFromDetails(
9415 RUNTIME_CALLING_CONVENTION) {
9416 RUNTIME_GET_ISOLATE;
9024 ASSERT(args.length() == 1); 9417 ASSERT(args.length() == 1);
9025 CONVERT_CHECKED(Smi, details, args[0]); 9418 CONVERT_CHECKED(Smi, details, args[0]);
9026 PropertyType type = PropertyDetails(details).type(); 9419 PropertyType type = PropertyDetails(details).type();
9027 return Smi::FromInt(static_cast<int>(type)); 9420 return Smi::FromInt(static_cast<int>(type));
9028 } 9421 }
9029 9422
9030 9423
9031 // Return the property attribute calculated from the property details. 9424 // Return the property attribute calculated from the property details.
9032 // args[0]: smi with property details. 9425 // args[0]: smi with property details.
9033 static MaybeObject* Runtime_DebugPropertyAttributesFromDetails(Arguments args) { 9426 static MaybeObject* Runtime_DebugPropertyAttributesFromDetails(
9427 RUNTIME_CALLING_CONVENTION) {
9428 RUNTIME_GET_ISOLATE;
9034 ASSERT(args.length() == 1); 9429 ASSERT(args.length() == 1);
9035 CONVERT_CHECKED(Smi, details, args[0]); 9430 CONVERT_CHECKED(Smi, details, args[0]);
9036 PropertyAttributes attributes = PropertyDetails(details).attributes(); 9431 PropertyAttributes attributes = PropertyDetails(details).attributes();
9037 return Smi::FromInt(static_cast<int>(attributes)); 9432 return Smi::FromInt(static_cast<int>(attributes));
9038 } 9433 }
9039 9434
9040 9435
9041 // Return the property insertion index calculated from the property details. 9436 // Return the property insertion index calculated from the property details.
9042 // args[0]: smi with property details. 9437 // args[0]: smi with property details.
9043 static MaybeObject* Runtime_DebugPropertyIndexFromDetails(Arguments args) { 9438 static MaybeObject* Runtime_DebugPropertyIndexFromDetails(
9439 RUNTIME_CALLING_CONVENTION) {
9440 RUNTIME_GET_ISOLATE;
9044 ASSERT(args.length() == 1); 9441 ASSERT(args.length() == 1);
9045 CONVERT_CHECKED(Smi, details, args[0]); 9442 CONVERT_CHECKED(Smi, details, args[0]);
9046 int index = PropertyDetails(details).index(); 9443 int index = PropertyDetails(details).index();
9047 return Smi::FromInt(index); 9444 return Smi::FromInt(index);
9048 } 9445 }
9049 9446
9050 9447
9051 // Return property value from named interceptor. 9448 // Return property value from named interceptor.
9052 // args[0]: object 9449 // args[0]: object
9053 // args[1]: property name 9450 // args[1]: property name
9054 static MaybeObject* Runtime_DebugNamedInterceptorPropertyValue(Arguments args) { 9451 static MaybeObject* Runtime_DebugNamedInterceptorPropertyValue(
9055 HandleScope scope; 9452 RUNTIME_CALLING_CONVENTION) {
9453 RUNTIME_GET_ISOLATE;
9454 HandleScope scope(isolate);
9056 ASSERT(args.length() == 2); 9455 ASSERT(args.length() == 2);
9057 CONVERT_ARG_CHECKED(JSObject, obj, 0); 9456 CONVERT_ARG_CHECKED(JSObject, obj, 0);
9058 RUNTIME_ASSERT(obj->HasNamedInterceptor()); 9457 RUNTIME_ASSERT(obj->HasNamedInterceptor());
9059 CONVERT_ARG_CHECKED(String, name, 1); 9458 CONVERT_ARG_CHECKED(String, name, 1);
9060 9459
9061 PropertyAttributes attributes; 9460 PropertyAttributes attributes;
9062 return obj->GetPropertyWithInterceptor(*obj, *name, &attributes); 9461 return obj->GetPropertyWithInterceptor(*obj, *name, &attributes);
9063 } 9462 }
9064 9463
9065 9464
9066 // Return element value from indexed interceptor. 9465 // Return element value from indexed interceptor.
9067 // args[0]: object 9466 // args[0]: object
9068 // args[1]: index 9467 // args[1]: index
9069 static MaybeObject* Runtime_DebugIndexedInterceptorElementValue( 9468 static MaybeObject* Runtime_DebugIndexedInterceptorElementValue(
9070 Arguments args) { 9469 RUNTIME_CALLING_CONVENTION) {
9071 HandleScope scope; 9470 RUNTIME_GET_ISOLATE;
9471 HandleScope scope(isolate);
9072 ASSERT(args.length() == 2); 9472 ASSERT(args.length() == 2);
9073 CONVERT_ARG_CHECKED(JSObject, obj, 0); 9473 CONVERT_ARG_CHECKED(JSObject, obj, 0);
9074 RUNTIME_ASSERT(obj->HasIndexedInterceptor()); 9474 RUNTIME_ASSERT(obj->HasIndexedInterceptor());
9075 CONVERT_NUMBER_CHECKED(uint32_t, index, Uint32, args[1]); 9475 CONVERT_NUMBER_CHECKED(uint32_t, index, Uint32, args[1]);
9076 9476
9077 return obj->GetElementWithInterceptor(*obj, index); 9477 return obj->GetElementWithInterceptor(*obj, index);
9078 } 9478 }
9079 9479
9080 9480
9081 static MaybeObject* Runtime_CheckExecutionState(Arguments args) { 9481 static MaybeObject* Runtime_CheckExecutionState(RUNTIME_CALLING_CONVENTION) {
9482 RUNTIME_GET_ISOLATE;
9082 ASSERT(args.length() >= 1); 9483 ASSERT(args.length() >= 1);
9083 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]); 9484 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]);
9084 // Check that the break id is valid. 9485 // Check that the break id is valid.
9085 if (Debug::break_id() == 0 || break_id != Debug::break_id()) { 9486 if (isolate->debug()->break_id() == 0 ||
9086 return Top::Throw(Heap::illegal_execution_state_symbol()); 9487 break_id != isolate->debug()->break_id()) {
9488 return isolate->Throw(
9489 isolate->heap()->illegal_execution_state_symbol());
9087 } 9490 }
9088 9491
9089 return Heap::true_value(); 9492 return isolate->heap()->true_value();
9090 } 9493 }
9091 9494
9092 9495
9093 static MaybeObject* Runtime_GetFrameCount(Arguments args) { 9496 static MaybeObject* Runtime_GetFrameCount(RUNTIME_CALLING_CONVENTION) {
9094 HandleScope scope; 9497 RUNTIME_GET_ISOLATE;
9498 HandleScope scope(isolate);
9095 ASSERT(args.length() == 1); 9499 ASSERT(args.length() == 1);
9096 9500
9097 // Check arguments. 9501 // Check arguments.
9098 Object* result; 9502 Object* result;
9099 { MaybeObject* maybe_result = Runtime_CheckExecutionState(args); 9503 { MaybeObject* maybe_result = Runtime_CheckExecutionState(args, isolate);
9100 if (!maybe_result->ToObject(&result)) return maybe_result; 9504 if (!maybe_result->ToObject(&result)) return maybe_result;
9101 } 9505 }
9102 9506
9103 // Count all frames which are relevant to debugging stack trace. 9507 // Count all frames which are relevant to debugging stack trace.
9104 int n = 0; 9508 int n = 0;
9105 StackFrame::Id id = Debug::break_frame_id(); 9509 StackFrame::Id id = isolate->debug()->break_frame_id();
9106 if (id == StackFrame::NO_ID) { 9510 if (id == StackFrame::NO_ID) {
9107 // If there is no JavaScript stack frame count is 0. 9511 // If there is no JavaScript stack frame count is 0.
9108 return Smi::FromInt(0); 9512 return Smi::FromInt(0);
9109 } 9513 }
9110 for (JavaScriptFrameIterator it(id); !it.done(); it.Advance()) n++; 9514 for (JavaScriptFrameIterator it(id); !it.done(); it.Advance()) n++;
9111 return Smi::FromInt(n); 9515 return Smi::FromInt(n);
9112 } 9516 }
9113 9517
9114 9518
9115 static const int kFrameDetailsFrameIdIndex = 0; 9519 static const int kFrameDetailsFrameIdIndex = 0;
(...skipping 17 matching lines...) Expand all
9133 // 2: Function 9537 // 2: Function
9134 // 3: Argument count 9538 // 3: Argument count
9135 // 4: Local count 9539 // 4: Local count
9136 // 5: Source position 9540 // 5: Source position
9137 // 6: Constructor call 9541 // 6: Constructor call
9138 // 7: Is at return 9542 // 7: Is at return
9139 // 8: Debugger frame 9543 // 8: Debugger frame
9140 // Arguments name, value 9544 // Arguments name, value
9141 // Locals name, value 9545 // Locals name, value
9142 // Return value if any 9546 // Return value if any
9143 static MaybeObject* Runtime_GetFrameDetails(Arguments args) { 9547 static MaybeObject* Runtime_GetFrameDetails(RUNTIME_CALLING_CONVENTION) {
9144 HandleScope scope; 9548 RUNTIME_GET_ISOLATE;
9549 HandleScope scope(isolate);
9145 ASSERT(args.length() == 2); 9550 ASSERT(args.length() == 2);
9146 9551
9147 // Check arguments. 9552 // Check arguments.
9148 Object* check; 9553 Object* check;
9149 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args); 9554 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args, isolate);
9150 if (!maybe_check->ToObject(&check)) return maybe_check; 9555 if (!maybe_check->ToObject(&check)) return maybe_check;
9151 } 9556 }
9152 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); 9557 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
9558 Heap* heap = isolate->heap();
9153 9559
9154 // Find the relevant frame with the requested index. 9560 // Find the relevant frame with the requested index.
9155 StackFrame::Id id = Debug::break_frame_id(); 9561 StackFrame::Id id = isolate->debug()->break_frame_id();
9156 if (id == StackFrame::NO_ID) { 9562 if (id == StackFrame::NO_ID) {
9157 // If there are no JavaScript stack frames return undefined. 9563 // If there are no JavaScript stack frames return undefined.
9158 return Heap::undefined_value(); 9564 return heap->undefined_value();
9159 } 9565 }
9160 int count = 0; 9566 int count = 0;
9161 JavaScriptFrameIterator it(id); 9567 JavaScriptFrameIterator it(id);
9162 for (; !it.done(); it.Advance()) { 9568 for (; !it.done(); it.Advance()) {
9163 if (count == index) break; 9569 if (count == index) break;
9164 count++; 9570 count++;
9165 } 9571 }
9166 if (it.done()) return Heap::undefined_value(); 9572 if (it.done()) return heap->undefined_value();
9167 9573
9168 bool is_optimized_frame = 9574 bool is_optimized_frame =
9169 it.frame()->code()->kind() == Code::OPTIMIZED_FUNCTION; 9575 it.frame()->LookupCode(isolate)->kind() == Code::OPTIMIZED_FUNCTION;
9170 9576
9171 // Traverse the saved contexts chain to find the active context for the 9577 // Traverse the saved contexts chain to find the active context for the
9172 // selected frame. 9578 // selected frame.
9173 SaveContext* save = Top::save_context(); 9579 SaveContext* save = isolate->save_context();
9174 while (save != NULL && !save->below(it.frame())) { 9580 while (save != NULL && !save->below(it.frame())) {
9175 save = save->prev(); 9581 save = save->prev();
9176 } 9582 }
9177 ASSERT(save != NULL); 9583 ASSERT(save != NULL);
9178 9584
9179 // Get the frame id. 9585 // Get the frame id.
9180 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); 9586 Handle<Object> frame_id(WrapFrameId(it.frame()->id()), isolate);
9181 9587
9182 // Find source position. 9588 // Find source position.
9183 int position = it.frame()->code()->SourcePosition(it.frame()->pc()); 9589 int position =
9590 it.frame()->LookupCode(isolate)->SourcePosition(it.frame()->pc());
9184 9591
9185 // Check for constructor frame. 9592 // Check for constructor frame.
9186 bool constructor = it.frame()->IsConstructor(); 9593 bool constructor = it.frame()->IsConstructor();
9187 9594
9188 // Get scope info and read from it for local variable information. 9595 // Get scope info and read from it for local variable information.
9189 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); 9596 Handle<JSFunction> function(JSFunction::cast(it.frame()->function()));
9190 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); 9597 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info());
9191 ScopeInfo<> info(*scope_info); 9598 ScopeInfo<> info(*scope_info);
9192 9599
9193 // Get the context. 9600 // Get the context.
9194 Handle<Context> context(Context::cast(it.frame()->context())); 9601 Handle<Context> context(Context::cast(it.frame()->context()));
9195 9602
9196 // Get the locals names and values into a temporary array. 9603 // Get the locals names and values into a temporary array.
9197 // 9604 //
9198 // TODO(1240907): Hide compiler-introduced stack variables 9605 // TODO(1240907): Hide compiler-introduced stack variables
9199 // (e.g. .result)? For users of the debugger, they will probably be 9606 // (e.g. .result)? For users of the debugger, they will probably be
9200 // confusing. 9607 // confusing.
9201 Handle<FixedArray> locals = Factory::NewFixedArray(info.NumberOfLocals() * 2); 9608 Handle<FixedArray> locals =
9609 isolate->factory()->NewFixedArray(info.NumberOfLocals() * 2);
9202 9610
9203 // Fill in the names of the locals. 9611 // Fill in the names of the locals.
9204 for (int i = 0; i < info.NumberOfLocals(); i++) { 9612 for (int i = 0; i < info.NumberOfLocals(); i++) {
9205 locals->set(i * 2, *info.LocalName(i)); 9613 locals->set(i * 2, *info.LocalName(i));
9206 } 9614 }
9207 9615
9208 // Fill in the values of the locals. 9616 // Fill in the values of the locals.
9209 for (int i = 0; i < info.NumberOfLocals(); i++) { 9617 for (int i = 0; i < info.NumberOfLocals(); i++) {
9210 if (is_optimized_frame) { 9618 if (is_optimized_frame) {
9211 // If we are inspecting an optimized frame use undefined as the 9619 // If we are inspecting an optimized frame use undefined as the
9212 // value for all locals. 9620 // value for all locals.
9213 // 9621 //
9214 // TODO(1140): We should be able to get the correct values 9622 // TODO(1140): We should be able to get the correct values
9215 // for locals in optimized frames. 9623 // for locals in optimized frames.
9216 locals->set(i * 2 + 1, Heap::undefined_value()); 9624 locals->set(i * 2 + 1, isolate->heap()->undefined_value());
9217 } else if (i < info.number_of_stack_slots()) { 9625 } else if (i < info.number_of_stack_slots()) {
9218 // Get the value from the stack. 9626 // Get the value from the stack.
9219 locals->set(i * 2 + 1, it.frame()->GetExpression(i)); 9627 locals->set(i * 2 + 1, it.frame()->GetExpression(i));
9220 } else { 9628 } else {
9221 // Traverse the context chain to the function context as all local 9629 // Traverse the context chain to the function context as all local
9222 // variables stored in the context will be on the function context. 9630 // variables stored in the context will be on the function context.
9223 Handle<String> name = info.LocalName(i); 9631 Handle<String> name = info.LocalName(i);
9224 while (!context->is_function_context()) { 9632 while (!context->is_function_context()) {
9225 context = Handle<Context>(context->previous()); 9633 context = Handle<Context>(context->previous());
9226 } 9634 }
9227 ASSERT(context->is_function_context()); 9635 ASSERT(context->is_function_context());
9228 locals->set(i * 2 + 1, 9636 locals->set(i * 2 + 1,
9229 context->get(scope_info->ContextSlotIndex(*name, NULL))); 9637 context->get(scope_info->ContextSlotIndex(*name, NULL)));
9230 } 9638 }
9231 } 9639 }
9232 9640
9233 // Check whether this frame is positioned at return. If not top 9641 // Check whether this frame is positioned at return. If not top
9234 // frame or if the frame is optimized it cannot be at a return. 9642 // frame or if the frame is optimized it cannot be at a return.
9235 bool at_return = false; 9643 bool at_return = false;
9236 if (!is_optimized_frame && index == 0) { 9644 if (!is_optimized_frame && index == 0) {
9237 at_return = Debug::IsBreakAtReturn(it.frame()); 9645 at_return = isolate->debug()->IsBreakAtReturn(it.frame());
9238 } 9646 }
9239 9647
9240 // If positioned just before return find the value to be returned and add it 9648 // If positioned just before return find the value to be returned and add it
9241 // to the frame information. 9649 // to the frame information.
9242 Handle<Object> return_value = Factory::undefined_value(); 9650 Handle<Object> return_value = isolate->factory()->undefined_value();
9243 if (at_return) { 9651 if (at_return) {
9244 StackFrameIterator it2; 9652 StackFrameIterator it2;
9245 Address internal_frame_sp = NULL; 9653 Address internal_frame_sp = NULL;
9246 while (!it2.done()) { 9654 while (!it2.done()) {
9247 if (it2.frame()->is_internal()) { 9655 if (it2.frame()->is_internal()) {
9248 internal_frame_sp = it2.frame()->sp(); 9656 internal_frame_sp = it2.frame()->sp();
9249 } else { 9657 } else {
9250 if (it2.frame()->is_java_script()) { 9658 if (it2.frame()->is_java_script()) {
9251 if (it2.frame()->id() == it.frame()->id()) { 9659 if (it2.frame()->id() == it.frame()->id()) {
9252 // The internal frame just before the JavaScript frame contains the 9660 // The internal frame just before the JavaScript frame contains the
9253 // value to return on top. A debug break at return will create an 9661 // value to return on top. A debug break at return will create an
9254 // internal frame to store the return value (eax/rax/r0) before 9662 // internal frame to store the return value (eax/rax/r0) before
9255 // entering the debug break exit frame. 9663 // entering the debug break exit frame.
9256 if (internal_frame_sp != NULL) { 9664 if (internal_frame_sp != NULL) {
9257 return_value = 9665 return_value =
9258 Handle<Object>(Memory::Object_at(internal_frame_sp)); 9666 Handle<Object>(Memory::Object_at(internal_frame_sp),
9667 isolate);
9259 break; 9668 break;
9260 } 9669 }
9261 } 9670 }
9262 } 9671 }
9263 9672
9264 // Indicate that the previous frame was not an internal frame. 9673 // Indicate that the previous frame was not an internal frame.
9265 internal_frame_sp = NULL; 9674 internal_frame_sp = NULL;
9266 } 9675 }
9267 it2.Advance(); 9676 it2.Advance();
9268 } 9677 }
9269 } 9678 }
9270 9679
9271 // Now advance to the arguments adapter frame (if any). It contains all 9680 // Now advance to the arguments adapter frame (if any). It contains all
9272 // the provided parameters whereas the function frame always have the number 9681 // the provided parameters whereas the function frame always have the number
9273 // of arguments matching the functions parameters. The rest of the 9682 // of arguments matching the functions parameters. The rest of the
9274 // information (except for what is collected above) is the same. 9683 // information (except for what is collected above) is the same.
9275 it.AdvanceToArgumentsFrame(); 9684 it.AdvanceToArgumentsFrame();
9276 9685
9277 // Find the number of arguments to fill. At least fill the number of 9686 // Find the number of arguments to fill. At least fill the number of
9278 // parameters for the function and fill more if more parameters are provided. 9687 // parameters for the function and fill more if more parameters are provided.
9279 int argument_count = info.number_of_parameters(); 9688 int argument_count = info.number_of_parameters();
9280 if (argument_count < it.frame()->ComputeParametersCount()) { 9689 if (argument_count < it.frame()->ComputeParametersCount()) {
9281 argument_count = it.frame()->ComputeParametersCount(); 9690 argument_count = it.frame()->ComputeParametersCount();
9282 } 9691 }
9283 9692
9284 // Calculate the size of the result. 9693 // Calculate the size of the result.
9285 int details_size = kFrameDetailsFirstDynamicIndex + 9694 int details_size = kFrameDetailsFirstDynamicIndex +
9286 2 * (argument_count + info.NumberOfLocals()) + 9695 2 * (argument_count + info.NumberOfLocals()) +
9287 (at_return ? 1 : 0); 9696 (at_return ? 1 : 0);
9288 Handle<FixedArray> details = Factory::NewFixedArray(details_size); 9697 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size);
9289 9698
9290 // Add the frame id. 9699 // Add the frame id.
9291 details->set(kFrameDetailsFrameIdIndex, *frame_id); 9700 details->set(kFrameDetailsFrameIdIndex, *frame_id);
9292 9701
9293 // Add the function (same as in function frame). 9702 // Add the function (same as in function frame).
9294 details->set(kFrameDetailsFunctionIndex, it.frame()->function()); 9703 details->set(kFrameDetailsFunctionIndex, it.frame()->function());
9295 9704
9296 // Add the arguments count. 9705 // Add the arguments count.
9297 details->set(kFrameDetailsArgumentCountIndex, Smi::FromInt(argument_count)); 9706 details->set(kFrameDetailsArgumentCountIndex, Smi::FromInt(argument_count));
9298 9707
9299 // Add the locals count 9708 // Add the locals count
9300 details->set(kFrameDetailsLocalCountIndex, 9709 details->set(kFrameDetailsLocalCountIndex,
9301 Smi::FromInt(info.NumberOfLocals())); 9710 Smi::FromInt(info.NumberOfLocals()));
9302 9711
9303 // Add the source position. 9712 // Add the source position.
9304 if (position != RelocInfo::kNoPosition) { 9713 if (position != RelocInfo::kNoPosition) {
9305 details->set(kFrameDetailsSourcePositionIndex, Smi::FromInt(position)); 9714 details->set(kFrameDetailsSourcePositionIndex, Smi::FromInt(position));
9306 } else { 9715 } else {
9307 details->set(kFrameDetailsSourcePositionIndex, Heap::undefined_value()); 9716 details->set(kFrameDetailsSourcePositionIndex, heap->undefined_value());
9308 } 9717 }
9309 9718
9310 // Add the constructor information. 9719 // Add the constructor information.
9311 details->set(kFrameDetailsConstructCallIndex, Heap::ToBoolean(constructor)); 9720 details->set(kFrameDetailsConstructCallIndex, heap->ToBoolean(constructor));
9312 9721
9313 // Add the at return information. 9722 // Add the at return information.
9314 details->set(kFrameDetailsAtReturnIndex, Heap::ToBoolean(at_return)); 9723 details->set(kFrameDetailsAtReturnIndex, heap->ToBoolean(at_return));
9315 9724
9316 // Add information on whether this frame is invoked in the debugger context. 9725 // Add information on whether this frame is invoked in the debugger context.
9317 details->set(kFrameDetailsDebuggerFrameIndex, 9726 details->set(kFrameDetailsDebuggerFrameIndex,
9318 Heap::ToBoolean(*save->context() == *Debug::debug_context())); 9727 heap->ToBoolean(*save->context() ==
9728 *isolate->debug()->debug_context()));
9319 9729
9320 // Fill the dynamic part. 9730 // Fill the dynamic part.
9321 int details_index = kFrameDetailsFirstDynamicIndex; 9731 int details_index = kFrameDetailsFirstDynamicIndex;
9322 9732
9323 // Add arguments name and value. 9733 // Add arguments name and value.
9324 for (int i = 0; i < argument_count; i++) { 9734 for (int i = 0; i < argument_count; i++) {
9325 // Name of the argument. 9735 // Name of the argument.
9326 if (i < info.number_of_parameters()) { 9736 if (i < info.number_of_parameters()) {
9327 details->set(details_index++, *info.parameter_name(i)); 9737 details->set(details_index++, *info.parameter_name(i));
9328 } else { 9738 } else {
9329 details->set(details_index++, Heap::undefined_value()); 9739 details->set(details_index++, heap->undefined_value());
9330 } 9740 }
9331 9741
9332 // Parameter value. If we are inspecting an optimized frame, use 9742 // Parameter value. If we are inspecting an optimized frame, use
9333 // undefined as the value. 9743 // undefined as the value.
9334 // 9744 //
9335 // TODO(3141533): We should be able to get the actual parameter 9745 // TODO(3141533): We should be able to get the actual parameter
9336 // value for optimized frames. 9746 // value for optimized frames.
9337 if (!is_optimized_frame && 9747 if (!is_optimized_frame &&
9338 (i < it.frame()->ComputeParametersCount())) { 9748 (i < it.frame()->ComputeParametersCount())) {
9339 details->set(details_index++, it.frame()->GetParameter(i)); 9749 details->set(details_index++, it.frame()->GetParameter(i));
9340 } else { 9750 } else {
9341 details->set(details_index++, Heap::undefined_value()); 9751 details->set(details_index++, heap->undefined_value());
9342 } 9752 }
9343 } 9753 }
9344 9754
9345 // Add locals name and value from the temporary copy from the function frame. 9755 // Add locals name and value from the temporary copy from the function frame.
9346 for (int i = 0; i < info.NumberOfLocals() * 2; i++) { 9756 for (int i = 0; i < info.NumberOfLocals() * 2; i++) {
9347 details->set(details_index++, locals->get(i)); 9757 details->set(details_index++, locals->get(i));
9348 } 9758 }
9349 9759
9350 // Add the value being returned. 9760 // Add the value being returned.
9351 if (at_return) { 9761 if (at_return) {
9352 details->set(details_index++, *return_value); 9762 details->set(details_index++, *return_value);
9353 } 9763 }
9354 9764
9355 // Add the receiver (same as in function frame). 9765 // Add the receiver (same as in function frame).
9356 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE 9766 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE
9357 // THE FRAME ITERATOR TO WRAP THE RECEIVER. 9767 // THE FRAME ITERATOR TO WRAP THE RECEIVER.
9358 Handle<Object> receiver(it.frame()->receiver()); 9768 Handle<Object> receiver(it.frame()->receiver(), isolate);
9359 if (!receiver->IsJSObject()) { 9769 if (!receiver->IsJSObject()) {
9360 // If the receiver is NOT a JSObject we have hit an optimization 9770 // If the receiver is NOT a JSObject we have hit an optimization
9361 // where a value object is not converted into a wrapped JS objects. 9771 // where a value object is not converted into a wrapped JS objects.
9362 // To hide this optimization from the debugger, we wrap the receiver 9772 // To hide this optimization from the debugger, we wrap the receiver
9363 // by creating correct wrapper object based on the calling frame's 9773 // by creating correct wrapper object based on the calling frame's
9364 // global context. 9774 // global context.
9365 it.Advance(); 9775 it.Advance();
9366 Handle<Context> calling_frames_global_context( 9776 Handle<Context> calling_frames_global_context(
9367 Context::cast(Context::cast(it.frame()->context())->global_context())); 9777 Context::cast(Context::cast(it.frame()->context())->global_context()));
9368 receiver = Factory::ToObject(receiver, calling_frames_global_context); 9778 receiver =
9779 isolate->factory()->ToObject(receiver, calling_frames_global_context);
9369 } 9780 }
9370 details->set(kFrameDetailsReceiverIndex, *receiver); 9781 details->set(kFrameDetailsReceiverIndex, *receiver);
9371 9782
9372 ASSERT_EQ(details_size, details_index); 9783 ASSERT_EQ(details_size, details_index);
9373 return *Factory::NewJSArrayWithElements(details); 9784 return *isolate->factory()->NewJSArrayWithElements(details);
9374 } 9785 }
9375 9786
9376 9787
9377 // Copy all the context locals into an object used to materialize a scope. 9788 // Copy all the context locals into an object used to materialize a scope.
9378 static bool CopyContextLocalsToScopeObject( 9789 static bool CopyContextLocalsToScopeObject(
9790 Isolate* isolate,
9379 Handle<SerializedScopeInfo> serialized_scope_info, 9791 Handle<SerializedScopeInfo> serialized_scope_info,
9380 ScopeInfo<>& scope_info, 9792 ScopeInfo<>& scope_info,
9381 Handle<Context> context, 9793 Handle<Context> context,
9382 Handle<JSObject> scope_object) { 9794 Handle<JSObject> scope_object) {
9383 // Fill all context locals to the context extension. 9795 // Fill all context locals to the context extension.
9384 for (int i = Context::MIN_CONTEXT_SLOTS; 9796 for (int i = Context::MIN_CONTEXT_SLOTS;
9385 i < scope_info.number_of_context_slots(); 9797 i < scope_info.number_of_context_slots();
9386 i++) { 9798 i++) {
9387 int context_index = serialized_scope_info->ContextSlotIndex( 9799 int context_index = serialized_scope_info->ContextSlotIndex(
9388 *scope_info.context_slot_name(i), NULL); 9800 *scope_info.context_slot_name(i), NULL);
9389 9801
9390 // Don't include the arguments shadow (.arguments) context variable. 9802 // Don't include the arguments shadow (.arguments) context variable.
9391 if (*scope_info.context_slot_name(i) != Heap::arguments_shadow_symbol()) { 9803 if (*scope_info.context_slot_name(i) !=
9804 isolate->heap()->arguments_shadow_symbol()) {
9392 RETURN_IF_EMPTY_HANDLE_VALUE( 9805 RETURN_IF_EMPTY_HANDLE_VALUE(
9806 isolate,
9393 SetProperty(scope_object, 9807 SetProperty(scope_object,
9394 scope_info.context_slot_name(i), 9808 scope_info.context_slot_name(i),
9395 Handle<Object>(context->get(context_index)), 9809 Handle<Object>(context->get(context_index), isolate),
9396 NONE, 9810 NONE,
9397 kNonStrictMode), 9811 kNonStrictMode),
9398 false); 9812 false);
9399 } 9813 }
9400 } 9814 }
9401 9815
9402 return true; 9816 return true;
9403 } 9817 }
9404 9818
9405 9819
9406 // Create a plain JSObject which materializes the local scope for the specified 9820 // Create a plain JSObject which materializes the local scope for the specified
9407 // frame. 9821 // frame.
9408 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) { 9822 static Handle<JSObject> MaterializeLocalScope(Isolate* isolate,
9823 JavaScriptFrame* frame) {
9409 Handle<JSFunction> function(JSFunction::cast(frame->function())); 9824 Handle<JSFunction> function(JSFunction::cast(frame->function()));
9410 Handle<SharedFunctionInfo> shared(function->shared()); 9825 Handle<SharedFunctionInfo> shared(function->shared());
9411 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); 9826 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info());
9412 ScopeInfo<> scope_info(*serialized_scope_info); 9827 ScopeInfo<> scope_info(*serialized_scope_info);
9413 9828
9414 // Allocate and initialize a JSObject with all the arguments, stack locals 9829 // Allocate and initialize a JSObject with all the arguments, stack locals
9415 // heap locals and extension properties of the debugged function. 9830 // heap locals and extension properties of the debugged function.
9416 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function()); 9831 Handle<JSObject> local_scope =
9832 isolate->factory()->NewJSObject(isolate->object_function());
9417 9833
9418 // First fill all parameters. 9834 // First fill all parameters.
9419 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 9835 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
9420 RETURN_IF_EMPTY_HANDLE_VALUE( 9836 RETURN_IF_EMPTY_HANDLE_VALUE(
9837 isolate,
9421 SetProperty(local_scope, 9838 SetProperty(local_scope,
9422 scope_info.parameter_name(i), 9839 scope_info.parameter_name(i),
9423 Handle<Object>(frame->GetParameter(i)), 9840 Handle<Object>(frame->GetParameter(i), isolate),
9424 NONE, 9841 NONE,
9425 kNonStrictMode), 9842 kNonStrictMode),
9426 Handle<JSObject>()); 9843 Handle<JSObject>());
9427 } 9844 }
9428 9845
9429 // Second fill all stack locals. 9846 // Second fill all stack locals.
9430 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) { 9847 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) {
9431 RETURN_IF_EMPTY_HANDLE_VALUE( 9848 RETURN_IF_EMPTY_HANDLE_VALUE(
9849 isolate,
9432 SetProperty(local_scope, 9850 SetProperty(local_scope,
9433 scope_info.stack_slot_name(i), 9851 scope_info.stack_slot_name(i),
9434 Handle<Object>(frame->GetExpression(i)), 9852 Handle<Object>(frame->GetExpression(i), isolate),
9435 NONE, 9853 NONE,
9436 kNonStrictMode), 9854 kNonStrictMode),
9437 Handle<JSObject>()); 9855 Handle<JSObject>());
9438 } 9856 }
9439 9857
9440 // Third fill all context locals. 9858 // Third fill all context locals.
9441 Handle<Context> frame_context(Context::cast(frame->context())); 9859 Handle<Context> frame_context(Context::cast(frame->context()));
9442 Handle<Context> function_context(frame_context->fcontext()); 9860 Handle<Context> function_context(frame_context->fcontext());
9443 if (!CopyContextLocalsToScopeObject(serialized_scope_info, scope_info, 9861 if (!CopyContextLocalsToScopeObject(isolate,
9862 serialized_scope_info, scope_info,
9444 function_context, local_scope)) { 9863 function_context, local_scope)) {
9445 return Handle<JSObject>(); 9864 return Handle<JSObject>();
9446 } 9865 }
9447 9866
9448 // Finally copy any properties from the function context extension. This will 9867 // Finally copy any properties from the function context extension. This will
9449 // be variables introduced by eval. 9868 // be variables introduced by eval.
9450 if (function_context->closure() == *function) { 9869 if (function_context->closure() == *function) {
9451 if (function_context->has_extension() && 9870 if (function_context->has_extension() &&
9452 !function_context->IsGlobalContext()) { 9871 !function_context->IsGlobalContext()) {
9453 Handle<JSObject> ext(JSObject::cast(function_context->extension())); 9872 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
9454 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); 9873 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS);
9455 for (int i = 0; i < keys->length(); i++) { 9874 for (int i = 0; i < keys->length(); i++) {
9456 // Names of variables introduced by eval are strings. 9875 // Names of variables introduced by eval are strings.
9457 ASSERT(keys->get(i)->IsString()); 9876 ASSERT(keys->get(i)->IsString());
9458 Handle<String> key(String::cast(keys->get(i))); 9877 Handle<String> key(String::cast(keys->get(i)));
9459 RETURN_IF_EMPTY_HANDLE_VALUE( 9878 RETURN_IF_EMPTY_HANDLE_VALUE(
9879 isolate,
9460 SetProperty(local_scope, 9880 SetProperty(local_scope,
9461 key, 9881 key,
9462 GetProperty(ext, key), 9882 GetProperty(ext, key),
9463 NONE, 9883 NONE,
9464 kNonStrictMode), 9884 kNonStrictMode),
9465 Handle<JSObject>()); 9885 Handle<JSObject>());
9466 } 9886 }
9467 } 9887 }
9468 } 9888 }
9469 return local_scope; 9889 return local_scope;
9470 } 9890 }
9471 9891
9472 9892
9473 // Create a plain JSObject which materializes the closure content for the 9893 // Create a plain JSObject which materializes the closure content for the
9474 // context. 9894 // context.
9475 static Handle<JSObject> MaterializeClosure(Handle<Context> context) { 9895 static Handle<JSObject> MaterializeClosure(Isolate* isolate,
9896 Handle<Context> context) {
9476 ASSERT(context->is_function_context()); 9897 ASSERT(context->is_function_context());
9477 9898
9478 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 9899 Handle<SharedFunctionInfo> shared(context->closure()->shared());
9479 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); 9900 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info());
9480 ScopeInfo<> scope_info(*serialized_scope_info); 9901 ScopeInfo<> scope_info(*serialized_scope_info);
9481 9902
9482 // Allocate and initialize a JSObject with all the content of theis function 9903 // Allocate and initialize a JSObject with all the content of theis function
9483 // closure. 9904 // closure.
9484 Handle<JSObject> closure_scope = Factory::NewJSObject(Top::object_function()); 9905 Handle<JSObject> closure_scope =
9906 isolate->factory()->NewJSObject(isolate->object_function());
9485 9907
9486 // Check whether the arguments shadow object exists. 9908 // Check whether the arguments shadow object exists.
9487 int arguments_shadow_index = 9909 int arguments_shadow_index =
9488 shared->scope_info()->ContextSlotIndex(Heap::arguments_shadow_symbol(), 9910 shared->scope_info()->ContextSlotIndex(
9489 NULL); 9911 isolate->heap()->arguments_shadow_symbol(), NULL);
9490 if (arguments_shadow_index >= 0) { 9912 if (arguments_shadow_index >= 0) {
9491 // In this case all the arguments are available in the arguments shadow 9913 // In this case all the arguments are available in the arguments shadow
9492 // object. 9914 // object.
9493 Handle<JSObject> arguments_shadow( 9915 Handle<JSObject> arguments_shadow(
9494 JSObject::cast(context->get(arguments_shadow_index))); 9916 JSObject::cast(context->get(arguments_shadow_index)));
9495 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 9917 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
9496 // We don't expect exception-throwing getters on the arguments shadow. 9918 // We don't expect exception-throwing getters on the arguments shadow.
9497 Object* element = arguments_shadow->GetElement(i)->ToObjectUnchecked(); 9919 Object* element = arguments_shadow->GetElement(i)->ToObjectUnchecked();
9498 RETURN_IF_EMPTY_HANDLE_VALUE( 9920 RETURN_IF_EMPTY_HANDLE_VALUE(
9921 isolate,
9499 SetProperty(closure_scope, 9922 SetProperty(closure_scope,
9500 scope_info.parameter_name(i), 9923 scope_info.parameter_name(i),
9501 Handle<Object>(element), 9924 Handle<Object>(element, isolate),
9502 NONE, 9925 NONE,
9503 kNonStrictMode), 9926 kNonStrictMode),
9504 Handle<JSObject>()); 9927 Handle<JSObject>());
9505 } 9928 }
9506 } 9929 }
9507 9930
9508 // Fill all context locals to the context extension. 9931 // Fill all context locals to the context extension.
9509 if (!CopyContextLocalsToScopeObject(serialized_scope_info, scope_info, 9932 if (!CopyContextLocalsToScopeObject(isolate,
9933 serialized_scope_info, scope_info,
9510 context, closure_scope)) { 9934 context, closure_scope)) {
9511 return Handle<JSObject>(); 9935 return Handle<JSObject>();
9512 } 9936 }
9513 9937
9514 // Finally copy any properties from the function context extension. This will 9938 // Finally copy any properties from the function context extension. This will
9515 // be variables introduced by eval. 9939 // be variables introduced by eval.
9516 if (context->has_extension()) { 9940 if (context->has_extension()) {
9517 Handle<JSObject> ext(JSObject::cast(context->extension())); 9941 Handle<JSObject> ext(JSObject::cast(context->extension()));
9518 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); 9942 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS);
9519 for (int i = 0; i < keys->length(); i++) { 9943 for (int i = 0; i < keys->length(); i++) {
9520 // Names of variables introduced by eval are strings. 9944 // Names of variables introduced by eval are strings.
9521 ASSERT(keys->get(i)->IsString()); 9945 ASSERT(keys->get(i)->IsString());
9522 Handle<String> key(String::cast(keys->get(i))); 9946 Handle<String> key(String::cast(keys->get(i)));
9523 RETURN_IF_EMPTY_HANDLE_VALUE( 9947 RETURN_IF_EMPTY_HANDLE_VALUE(
9948 isolate,
9524 SetProperty(closure_scope, 9949 SetProperty(closure_scope,
9525 key, 9950 key,
9526 GetProperty(ext, key), 9951 GetProperty(ext, key),
9527 NONE, 9952 NONE,
9528 kNonStrictMode), 9953 kNonStrictMode),
9529 Handle<JSObject>()); 9954 Handle<JSObject>());
9530 } 9955 }
9531 } 9956 }
9532 9957
9533 return closure_scope; 9958 return closure_scope;
(...skipping 10 matching lines...) Expand all
9544 ScopeTypeLocal, 9969 ScopeTypeLocal,
9545 ScopeTypeWith, 9970 ScopeTypeWith,
9546 ScopeTypeClosure, 9971 ScopeTypeClosure,
9547 // Every catch block contains an implicit with block (its parameter is 9972 // Every catch block contains an implicit with block (its parameter is
9548 // a JSContextExtensionObject) that extends current scope with a variable 9973 // a JSContextExtensionObject) that extends current scope with a variable
9549 // holding exception object. Such with blocks are treated as scopes of their 9974 // holding exception object. Such with blocks are treated as scopes of their
9550 // own type. 9975 // own type.
9551 ScopeTypeCatch 9976 ScopeTypeCatch
9552 }; 9977 };
9553 9978
9554 explicit ScopeIterator(JavaScriptFrame* frame) 9979 ScopeIterator(Isolate* isolate, JavaScriptFrame* frame)
9555 : frame_(frame), 9980 : isolate_(isolate),
9981 frame_(frame),
9556 function_(JSFunction::cast(frame->function())), 9982 function_(JSFunction::cast(frame->function())),
9557 context_(Context::cast(frame->context())), 9983 context_(Context::cast(frame->context())),
9558 local_done_(false), 9984 local_done_(false),
9559 at_local_(false) { 9985 at_local_(false) {
9560 9986
9561 // Check whether the first scope is actually a local scope. 9987 // Check whether the first scope is actually a local scope.
9562 if (context_->IsGlobalContext()) { 9988 if (context_->IsGlobalContext()) {
9563 // If there is a stack slot for .result then this local scope has been 9989 // If there is a stack slot for .result then this local scope has been
9564 // created for evaluating top level code and it is not a real local scope. 9990 // created for evaluating top level code and it is not a real local scope.
9565 // Checking for the existence of .result seems fragile, but the scope info 9991 // Checking for the existence of .result seems fragile, but the scope info
9566 // saved with the code object does not otherwise have that information. 9992 // saved with the code object does not otherwise have that information.
9567 int index = function_->shared()->scope_info()-> 9993 int index = function_->shared()->scope_info()->
9568 StackSlotIndex(Heap::result_symbol()); 9994 StackSlotIndex(isolate_->heap()->result_symbol());
9569 at_local_ = index < 0; 9995 at_local_ = index < 0;
9570 } else if (context_->is_function_context()) { 9996 } else if (context_->is_function_context()) {
9571 at_local_ = true; 9997 at_local_ = true;
9572 } 9998 }
9573 } 9999 }
9574 10000
9575 // More scopes? 10001 // More scopes?
9576 bool Done() { return context_.is_null(); } 10002 bool Done() { return context_.is_null(); }
9577 10003
9578 // Move to the next scope. 10004 // Move to the next scope.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
9636 } 10062 }
9637 10063
9638 // Return the JavaScript object with the content of the current scope. 10064 // Return the JavaScript object with the content of the current scope.
9639 Handle<JSObject> ScopeObject() { 10065 Handle<JSObject> ScopeObject() {
9640 switch (Type()) { 10066 switch (Type()) {
9641 case ScopeIterator::ScopeTypeGlobal: 10067 case ScopeIterator::ScopeTypeGlobal:
9642 return Handle<JSObject>(CurrentContext()->global()); 10068 return Handle<JSObject>(CurrentContext()->global());
9643 break; 10069 break;
9644 case ScopeIterator::ScopeTypeLocal: 10070 case ScopeIterator::ScopeTypeLocal:
9645 // Materialize the content of the local scope into a JSObject. 10071 // Materialize the content of the local scope into a JSObject.
9646 return MaterializeLocalScope(frame_); 10072 return MaterializeLocalScope(isolate_, frame_);
9647 break; 10073 break;
9648 case ScopeIterator::ScopeTypeWith: 10074 case ScopeIterator::ScopeTypeWith:
9649 case ScopeIterator::ScopeTypeCatch: 10075 case ScopeIterator::ScopeTypeCatch:
9650 // Return the with object. 10076 // Return the with object.
9651 return Handle<JSObject>(CurrentContext()->extension()); 10077 return Handle<JSObject>(CurrentContext()->extension());
9652 break; 10078 break;
9653 case ScopeIterator::ScopeTypeClosure: 10079 case ScopeIterator::ScopeTypeClosure:
9654 // Materialize the content of the closure scope into a JSObject. 10080 // Materialize the content of the closure scope into a JSObject.
9655 return MaterializeClosure(CurrentContext()); 10081 return MaterializeClosure(isolate_, CurrentContext());
9656 break; 10082 break;
9657 } 10083 }
9658 UNREACHABLE(); 10084 UNREACHABLE();
9659 return Handle<JSObject>(); 10085 return Handle<JSObject>();
9660 } 10086 }
9661 10087
9662 // Return the context for this scope. For the local context there might not 10088 // Return the context for this scope. For the local context there might not
9663 // be an actual context. 10089 // be an actual context.
9664 Handle<Context> CurrentContext() { 10090 Handle<Context> CurrentContext() {
9665 if (at_local_ && context_->closure() != *function_) { 10091 if (at_local_ && context_->closure() != *function_) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
9724 } 10150 }
9725 10151
9726 default: 10152 default:
9727 UNREACHABLE(); 10153 UNREACHABLE();
9728 } 10154 }
9729 PrintF("\n"); 10155 PrintF("\n");
9730 } 10156 }
9731 #endif 10157 #endif
9732 10158
9733 private: 10159 private:
10160 Isolate* isolate_;
9734 JavaScriptFrame* frame_; 10161 JavaScriptFrame* frame_;
9735 Handle<JSFunction> function_; 10162 Handle<JSFunction> function_;
9736 Handle<Context> context_; 10163 Handle<Context> context_;
9737 bool local_done_; 10164 bool local_done_;
9738 bool at_local_; 10165 bool at_local_;
9739 10166
9740 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); 10167 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator);
9741 }; 10168 };
9742 10169
9743 10170
9744 static MaybeObject* Runtime_GetScopeCount(Arguments args) { 10171 static MaybeObject* Runtime_GetScopeCount(RUNTIME_CALLING_CONVENTION) {
9745 HandleScope scope; 10172 RUNTIME_GET_ISOLATE;
10173 HandleScope scope(isolate);
9746 ASSERT(args.length() == 2); 10174 ASSERT(args.length() == 2);
9747 10175
9748 // Check arguments. 10176 // Check arguments.
9749 Object* check; 10177 Object* check;
9750 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args); 10178 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args, isolate);
9751 if (!maybe_check->ToObject(&check)) return maybe_check; 10179 if (!maybe_check->ToObject(&check)) return maybe_check;
9752 } 10180 }
9753 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 10181 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
9754 10182
9755 // Get the frame where the debugging is performed. 10183 // Get the frame where the debugging is performed.
9756 StackFrame::Id id = UnwrapFrameId(wrapped_id); 10184 StackFrame::Id id = UnwrapFrameId(wrapped_id);
9757 JavaScriptFrameIterator it(id); 10185 JavaScriptFrameIterator it(id);
9758 JavaScriptFrame* frame = it.frame(); 10186 JavaScriptFrame* frame = it.frame();
9759 10187
9760 // Count the visible scopes. 10188 // Count the visible scopes.
9761 int n = 0; 10189 int n = 0;
9762 for (ScopeIterator it(frame); !it.Done(); it.Next()) { 10190 for (ScopeIterator it(isolate, frame); !it.Done(); it.Next()) {
9763 n++; 10191 n++;
9764 } 10192 }
9765 10193
9766 return Smi::FromInt(n); 10194 return Smi::FromInt(n);
9767 } 10195 }
9768 10196
9769 10197
9770 static const int kScopeDetailsTypeIndex = 0; 10198 static const int kScopeDetailsTypeIndex = 0;
9771 static const int kScopeDetailsObjectIndex = 1; 10199 static const int kScopeDetailsObjectIndex = 1;
9772 static const int kScopeDetailsSize = 2; 10200 static const int kScopeDetailsSize = 2;
9773 10201
9774 // Return an array with scope details 10202 // Return an array with scope details
9775 // args[0]: number: break id 10203 // args[0]: number: break id
9776 // args[1]: number: frame index 10204 // args[1]: number: frame index
9777 // args[2]: number: scope index 10205 // args[2]: number: scope index
9778 // 10206 //
9779 // The array returned contains the following information: 10207 // The array returned contains the following information:
9780 // 0: Scope type 10208 // 0: Scope type
9781 // 1: Scope object 10209 // 1: Scope object
9782 static MaybeObject* Runtime_GetScopeDetails(Arguments args) { 10210 static MaybeObject* Runtime_GetScopeDetails(RUNTIME_CALLING_CONVENTION) {
9783 HandleScope scope; 10211 RUNTIME_GET_ISOLATE;
10212 HandleScope scope(isolate);
9784 ASSERT(args.length() == 3); 10213 ASSERT(args.length() == 3);
9785 10214
9786 // Check arguments. 10215 // Check arguments.
9787 Object* check; 10216 Object* check;
9788 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args); 10217 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args, isolate);
9789 if (!maybe_check->ToObject(&check)) return maybe_check; 10218 if (!maybe_check->ToObject(&check)) return maybe_check;
9790 } 10219 }
9791 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 10220 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
9792 CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]); 10221 CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]);
9793 10222
9794 // Get the frame where the debugging is performed. 10223 // Get the frame where the debugging is performed.
9795 StackFrame::Id id = UnwrapFrameId(wrapped_id); 10224 StackFrame::Id id = UnwrapFrameId(wrapped_id);
9796 JavaScriptFrameIterator frame_it(id); 10225 JavaScriptFrameIterator frame_it(id);
9797 JavaScriptFrame* frame = frame_it.frame(); 10226 JavaScriptFrame* frame = frame_it.frame();
9798 10227
9799 // Find the requested scope. 10228 // Find the requested scope.
9800 int n = 0; 10229 int n = 0;
9801 ScopeIterator it(frame); 10230 ScopeIterator it(isolate, frame);
9802 for (; !it.Done() && n < index; it.Next()) { 10231 for (; !it.Done() && n < index; it.Next()) {
9803 n++; 10232 n++;
9804 } 10233 }
9805 if (it.Done()) { 10234 if (it.Done()) {
9806 return Heap::undefined_value(); 10235 return isolate->heap()->undefined_value();
9807 } 10236 }
9808 10237
9809 // Calculate the size of the result. 10238 // Calculate the size of the result.
9810 int details_size = kScopeDetailsSize; 10239 int details_size = kScopeDetailsSize;
9811 Handle<FixedArray> details = Factory::NewFixedArray(details_size); 10240 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size);
9812 10241
9813 // Fill in scope details. 10242 // Fill in scope details.
9814 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type())); 10243 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type()));
9815 Handle<JSObject> scope_object = it.ScopeObject(); 10244 Handle<JSObject> scope_object = it.ScopeObject();
9816 RETURN_IF_EMPTY_HANDLE(scope_object); 10245 RETURN_IF_EMPTY_HANDLE(isolate, scope_object);
9817 details->set(kScopeDetailsObjectIndex, *scope_object); 10246 details->set(kScopeDetailsObjectIndex, *scope_object);
9818 10247
9819 return *Factory::NewJSArrayWithElements(details); 10248 return *isolate->factory()->NewJSArrayWithElements(details);
9820 } 10249 }
9821 10250
9822 10251
9823 static MaybeObject* Runtime_DebugPrintScopes(Arguments args) { 10252 static MaybeObject* Runtime_DebugPrintScopes(RUNTIME_CALLING_CONVENTION) {
9824 HandleScope scope; 10253 RUNTIME_GET_ISOLATE;
10254 HandleScope scope(isolate);
9825 ASSERT(args.length() == 0); 10255 ASSERT(args.length() == 0);
9826 10256
9827 #ifdef DEBUG 10257 #ifdef DEBUG
9828 // Print the scopes for the top frame. 10258 // Print the scopes for the top frame.
9829 StackFrameLocator locator; 10259 StackFrameLocator locator;
9830 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 10260 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
9831 for (ScopeIterator it(frame); !it.Done(); it.Next()) { 10261 for (ScopeIterator it(isolate, frame); !it.Done(); it.Next()) {
9832 it.DebugPrint(); 10262 it.DebugPrint();
9833 } 10263 }
9834 #endif 10264 #endif
9835 return Heap::undefined_value(); 10265 return isolate->heap()->undefined_value();
9836 } 10266 }
9837 10267
9838 10268
9839 static MaybeObject* Runtime_GetThreadCount(Arguments args) { 10269 static MaybeObject* Runtime_GetThreadCount(RUNTIME_CALLING_CONVENTION) {
9840 HandleScope scope; 10270 RUNTIME_GET_ISOLATE;
10271 HandleScope scope(isolate);
9841 ASSERT(args.length() == 1); 10272 ASSERT(args.length() == 1);
9842 10273
9843 // Check arguments. 10274 // Check arguments.
9844 Object* result; 10275 Object* result;
9845 { MaybeObject* maybe_result = Runtime_CheckExecutionState(args); 10276 { MaybeObject* maybe_result = Runtime_CheckExecutionState(args, isolate);
9846 if (!maybe_result->ToObject(&result)) return maybe_result; 10277 if (!maybe_result->ToObject(&result)) return maybe_result;
9847 } 10278 }
9848 10279
9849 // Count all archived V8 threads. 10280 // Count all archived V8 threads.
9850 int n = 0; 10281 int n = 0;
9851 for (ThreadState* thread = ThreadState::FirstInUse(); 10282 for (ThreadState* thread =
10283 isolate->thread_manager()->FirstThreadStateInUse();
9852 thread != NULL; 10284 thread != NULL;
9853 thread = thread->Next()) { 10285 thread = thread->Next()) {
9854 n++; 10286 n++;
9855 } 10287 }
9856 10288
9857 // Total number of threads is current thread and archived threads. 10289 // Total number of threads is current thread and archived threads.
9858 return Smi::FromInt(n + 1); 10290 return Smi::FromInt(n + 1);
9859 } 10291 }
9860 10292
9861 10293
9862 static const int kThreadDetailsCurrentThreadIndex = 0; 10294 static const int kThreadDetailsCurrentThreadIndex = 0;
9863 static const int kThreadDetailsThreadIdIndex = 1; 10295 static const int kThreadDetailsThreadIdIndex = 1;
9864 static const int kThreadDetailsSize = 2; 10296 static const int kThreadDetailsSize = 2;
9865 10297
9866 // Return an array with thread details 10298 // Return an array with thread details
9867 // args[0]: number: break id 10299 // args[0]: number: break id
9868 // args[1]: number: thread index 10300 // args[1]: number: thread index
9869 // 10301 //
9870 // The array returned contains the following information: 10302 // The array returned contains the following information:
9871 // 0: Is current thread? 10303 // 0: Is current thread?
9872 // 1: Thread id 10304 // 1: Thread id
9873 static MaybeObject* Runtime_GetThreadDetails(Arguments args) { 10305 static MaybeObject* Runtime_GetThreadDetails(RUNTIME_CALLING_CONVENTION) {
9874 HandleScope scope; 10306 RUNTIME_GET_ISOLATE;
10307 HandleScope scope(isolate);
9875 ASSERT(args.length() == 2); 10308 ASSERT(args.length() == 2);
9876 10309
9877 // Check arguments. 10310 // Check arguments.
9878 Object* check; 10311 Object* check;
9879 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args); 10312 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args, isolate);
9880 if (!maybe_check->ToObject(&check)) return maybe_check; 10313 if (!maybe_check->ToObject(&check)) return maybe_check;
9881 } 10314 }
9882 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); 10315 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
9883 10316
9884 // Allocate array for result. 10317 // Allocate array for result.
9885 Handle<FixedArray> details = Factory::NewFixedArray(kThreadDetailsSize); 10318 Handle<FixedArray> details =
10319 isolate->factory()->NewFixedArray(kThreadDetailsSize);
9886 10320
9887 // Thread index 0 is current thread. 10321 // Thread index 0 is current thread.
9888 if (index == 0) { 10322 if (index == 0) {
9889 // Fill the details. 10323 // Fill the details.
9890 details->set(kThreadDetailsCurrentThreadIndex, Heap::true_value()); 10324 details->set(kThreadDetailsCurrentThreadIndex,
10325 isolate->heap()->true_value());
9891 details->set(kThreadDetailsThreadIdIndex, 10326 details->set(kThreadDetailsThreadIdIndex,
9892 Smi::FromInt(ThreadManager::CurrentId())); 10327 Smi::FromInt(
10328 isolate->thread_manager()->CurrentId()));
9893 } else { 10329 } else {
9894 // Find the thread with the requested index. 10330 // Find the thread with the requested index.
9895 int n = 1; 10331 int n = 1;
9896 ThreadState* thread = ThreadState::FirstInUse(); 10332 ThreadState* thread =
10333 isolate->thread_manager()->FirstThreadStateInUse();
9897 while (index != n && thread != NULL) { 10334 while (index != n && thread != NULL) {
9898 thread = thread->Next(); 10335 thread = thread->Next();
9899 n++; 10336 n++;
9900 } 10337 }
9901 if (thread == NULL) { 10338 if (thread == NULL) {
9902 return Heap::undefined_value(); 10339 return isolate->heap()->undefined_value();
9903 } 10340 }
9904 10341
9905 // Fill the details. 10342 // Fill the details.
9906 details->set(kThreadDetailsCurrentThreadIndex, Heap::false_value()); 10343 details->set(kThreadDetailsCurrentThreadIndex,
10344 isolate->heap()->false_value());
9907 details->set(kThreadDetailsThreadIdIndex, Smi::FromInt(thread->id())); 10345 details->set(kThreadDetailsThreadIdIndex, Smi::FromInt(thread->id()));
9908 } 10346 }
9909 10347
9910 // Convert to JS array and return. 10348 // Convert to JS array and return.
9911 return *Factory::NewJSArrayWithElements(details); 10349 return *isolate->factory()->NewJSArrayWithElements(details);
9912 } 10350 }
9913 10351
9914 10352
9915 // Sets the disable break state 10353 // Sets the disable break state
9916 // args[0]: disable break state 10354 // args[0]: disable break state
9917 static MaybeObject* Runtime_SetDisableBreak(Arguments args) { 10355 static MaybeObject* Runtime_SetDisableBreak(RUNTIME_CALLING_CONVENTION) {
9918 HandleScope scope; 10356 RUNTIME_GET_ISOLATE;
10357 HandleScope scope(isolate);
9919 ASSERT(args.length() == 1); 10358 ASSERT(args.length() == 1);
9920 CONVERT_BOOLEAN_CHECKED(disable_break, args[0]); 10359 CONVERT_BOOLEAN_CHECKED(disable_break, args[0]);
9921 Debug::set_disable_break(disable_break); 10360 isolate->debug()->set_disable_break(disable_break);
9922 return Heap::undefined_value(); 10361 return isolate->heap()->undefined_value();
9923 } 10362 }
9924 10363
9925 10364
9926 static MaybeObject* Runtime_GetBreakLocations(Arguments args) { 10365 static MaybeObject* Runtime_GetBreakLocations(RUNTIME_CALLING_CONVENTION) {
9927 HandleScope scope; 10366 RUNTIME_GET_ISOLATE;
10367 HandleScope scope(isolate);
9928 ASSERT(args.length() == 1); 10368 ASSERT(args.length() == 1);
9929 10369
9930 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 10370 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
9931 Handle<SharedFunctionInfo> shared(fun->shared()); 10371 Handle<SharedFunctionInfo> shared(fun->shared());
9932 // Find the number of break points 10372 // Find the number of break points
9933 Handle<Object> break_locations = Debug::GetSourceBreakLocations(shared); 10373 Handle<Object> break_locations = Debug::GetSourceBreakLocations(shared);
9934 if (break_locations->IsUndefined()) return Heap::undefined_value(); 10374 if (break_locations->IsUndefined()) return isolate->heap()->undefined_value();
9935 // Return array as JS array 10375 // Return array as JS array
9936 return *Factory::NewJSArrayWithElements( 10376 return *isolate->factory()->NewJSArrayWithElements(
9937 Handle<FixedArray>::cast(break_locations)); 10377 Handle<FixedArray>::cast(break_locations));
9938 } 10378 }
9939 10379
9940 10380
9941 // Set a break point in a function 10381 // Set a break point in a function
9942 // args[0]: function 10382 // args[0]: function
9943 // args[1]: number: break source position (within the function source) 10383 // args[1]: number: break source position (within the function source)
9944 // args[2]: number: break point object 10384 // args[2]: number: break point object
9945 static MaybeObject* Runtime_SetFunctionBreakPoint(Arguments args) { 10385 static MaybeObject* Runtime_SetFunctionBreakPoint(RUNTIME_CALLING_CONVENTION) {
9946 HandleScope scope; 10386 RUNTIME_GET_ISOLATE;
10387 HandleScope scope(isolate);
9947 ASSERT(args.length() == 3); 10388 ASSERT(args.length() == 3);
9948 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 10389 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
9949 Handle<SharedFunctionInfo> shared(fun->shared()); 10390 Handle<SharedFunctionInfo> shared(fun->shared());
9950 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 10391 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
9951 RUNTIME_ASSERT(source_position >= 0); 10392 RUNTIME_ASSERT(source_position >= 0);
9952 Handle<Object> break_point_object_arg = args.at<Object>(2); 10393 Handle<Object> break_point_object_arg = args.at<Object>(2);
9953 10394
9954 // Set break point. 10395 // Set break point.
9955 Debug::SetBreakPoint(shared, break_point_object_arg, &source_position); 10396 isolate->debug()->SetBreakPoint(shared, break_point_object_arg,
10397 &source_position);
9956 10398
9957 return Smi::FromInt(source_position); 10399 return Smi::FromInt(source_position);
9958 } 10400 }
9959 10401
9960 10402
9961 Object* Runtime::FindSharedFunctionInfoInScript(Handle<Script> script, 10403 Object* Runtime::FindSharedFunctionInfoInScript(Isolate* isolate,
10404 Handle<Script> script,
9962 int position) { 10405 int position) {
9963 // Iterate the heap looking for SharedFunctionInfo generated from the 10406 // Iterate the heap looking for SharedFunctionInfo generated from the
9964 // script. The inner most SharedFunctionInfo containing the source position 10407 // script. The inner most SharedFunctionInfo containing the source position
9965 // for the requested break point is found. 10408 // for the requested break point is found.
9966 // NOTE: This might require several heap iterations. If the SharedFunctionInfo 10409 // NOTE: This might require several heap iterations. If the SharedFunctionInfo
9967 // which is found is not compiled it is compiled and the heap is iterated 10410 // which is found is not compiled it is compiled and the heap is iterated
9968 // again as the compilation might create inner functions from the newly 10411 // again as the compilation might create inner functions from the newly
9969 // compiled function and the actual requested break point might be in one of 10412 // compiled function and the actual requested break point might be in one of
9970 // these functions. 10413 // these functions.
9971 bool done = false; 10414 bool done = false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
10014 target = shared; 10457 target = shared;
10015 } 10458 }
10016 } 10459 }
10017 } 10460 }
10018 } 10461 }
10019 } 10462 }
10020 } // End for loop. 10463 } // End for loop.
10021 } // End No allocation scope. 10464 } // End No allocation scope.
10022 10465
10023 if (target.is_null()) { 10466 if (target.is_null()) {
10024 return Heap::undefined_value(); 10467 return isolate->heap()->undefined_value();
10025 } 10468 }
10026 10469
10027 // If the candidate found is compiled we are done. NOTE: when lazy 10470 // If the candidate found is compiled we are done. NOTE: when lazy
10028 // compilation of inner functions is introduced some additional checking 10471 // compilation of inner functions is introduced some additional checking
10029 // needs to be done here to compile inner functions. 10472 // needs to be done here to compile inner functions.
10030 done = target->is_compiled(); 10473 done = target->is_compiled();
10031 if (!done) { 10474 if (!done) {
10032 // If the candidate is not compiled compile it to reveal any inner 10475 // If the candidate is not compiled compile it to reveal any inner
10033 // functions which might contain the requested source position. 10476 // functions which might contain the requested source position.
10034 CompileLazyShared(target, KEEP_EXCEPTION); 10477 CompileLazyShared(target, KEEP_EXCEPTION);
10035 } 10478 }
10036 } // End while loop. 10479 } // End while loop.
10037 10480
10038 return *target; 10481 return *target;
10039 } 10482 }
10040 10483
10041 10484
10042 // Changes the state of a break point in a script and returns source position 10485 // Changes the state of a break point in a script and returns source position
10043 // where break point was set. NOTE: Regarding performance see the NOTE for 10486 // where break point was set. NOTE: Regarding performance see the NOTE for
10044 // GetScriptFromScriptData. 10487 // GetScriptFromScriptData.
10045 // args[0]: script to set break point in 10488 // args[0]: script to set break point in
10046 // args[1]: number: break source position (within the script source) 10489 // args[1]: number: break source position (within the script source)
10047 // args[2]: number: break point object 10490 // args[2]: number: break point object
10048 static MaybeObject* Runtime_SetScriptBreakPoint(Arguments args) { 10491 static MaybeObject* Runtime_SetScriptBreakPoint(RUNTIME_CALLING_CONVENTION) {
10049 HandleScope scope; 10492 RUNTIME_GET_ISOLATE;
10493 HandleScope scope(isolate);
10050 ASSERT(args.length() == 3); 10494 ASSERT(args.length() == 3);
10051 CONVERT_ARG_CHECKED(JSValue, wrapper, 0); 10495 CONVERT_ARG_CHECKED(JSValue, wrapper, 0);
10052 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 10496 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
10053 RUNTIME_ASSERT(source_position >= 0); 10497 RUNTIME_ASSERT(source_position >= 0);
10054 Handle<Object> break_point_object_arg = args.at<Object>(2); 10498 Handle<Object> break_point_object_arg = args.at<Object>(2);
10055 10499
10056 // Get the script from the script wrapper. 10500 // Get the script from the script wrapper.
10057 RUNTIME_ASSERT(wrapper->value()->IsScript()); 10501 RUNTIME_ASSERT(wrapper->value()->IsScript());
10058 Handle<Script> script(Script::cast(wrapper->value())); 10502 Handle<Script> script(Script::cast(wrapper->value()));
10059 10503
10060 Object* result = Runtime::FindSharedFunctionInfoInScript( 10504 Object* result = Runtime::FindSharedFunctionInfoInScript(
10061 script, source_position); 10505 isolate, script, source_position);
10062 if (!result->IsUndefined()) { 10506 if (!result->IsUndefined()) {
10063 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); 10507 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result));
10064 // Find position within function. The script position might be before the 10508 // Find position within function. The script position might be before the
10065 // source position of the first function. 10509 // source position of the first function.
10066 int position; 10510 int position;
10067 if (shared->start_position() > source_position) { 10511 if (shared->start_position() > source_position) {
10068 position = 0; 10512 position = 0;
10069 } else { 10513 } else {
10070 position = source_position - shared->start_position(); 10514 position = source_position - shared->start_position();
10071 } 10515 }
10072 Debug::SetBreakPoint(shared, break_point_object_arg, &position); 10516 isolate->debug()->SetBreakPoint(shared, break_point_object_arg, &position);
10073 position += shared->start_position(); 10517 position += shared->start_position();
10074 return Smi::FromInt(position); 10518 return Smi::FromInt(position);
10075 } 10519 }
10076 return Heap::undefined_value(); 10520 return isolate->heap()->undefined_value();
10077 } 10521 }
10078 10522
10079 10523
10080 // Clear a break point 10524 // Clear a break point
10081 // args[0]: number: break point object 10525 // args[0]: number: break point object
10082 static MaybeObject* Runtime_ClearBreakPoint(Arguments args) { 10526 static MaybeObject* Runtime_ClearBreakPoint(RUNTIME_CALLING_CONVENTION) {
10083 HandleScope scope; 10527 RUNTIME_GET_ISOLATE;
10528 HandleScope scope(isolate);
10084 ASSERT(args.length() == 1); 10529 ASSERT(args.length() == 1);
10085 Handle<Object> break_point_object_arg = args.at<Object>(0); 10530 Handle<Object> break_point_object_arg = args.at<Object>(0);
10086 10531
10087 // Clear break point. 10532 // Clear break point.
10088 Debug::ClearBreakPoint(break_point_object_arg); 10533 isolate->debug()->ClearBreakPoint(break_point_object_arg);
10089 10534
10090 return Heap::undefined_value(); 10535 return isolate->heap()->undefined_value();
10091 } 10536 }
10092 10537
10093 10538
10094 // Change the state of break on exceptions. 10539 // Change the state of break on exceptions.
10095 // args[0]: Enum value indicating whether to affect caught/uncaught exceptions. 10540 // args[0]: Enum value indicating whether to affect caught/uncaught exceptions.
10096 // args[1]: Boolean indicating on/off. 10541 // args[1]: Boolean indicating on/off.
10097 static MaybeObject* Runtime_ChangeBreakOnException(Arguments args) { 10542 static MaybeObject* Runtime_ChangeBreakOnException(RUNTIME_CALLING_CONVENTION) {
10098 HandleScope scope; 10543 RUNTIME_GET_ISOLATE;
10544 HandleScope scope(isolate);
10099 ASSERT(args.length() == 2); 10545 ASSERT(args.length() == 2);
10100 RUNTIME_ASSERT(args[0]->IsNumber()); 10546 RUNTIME_ASSERT(args[0]->IsNumber());
10101 CONVERT_BOOLEAN_CHECKED(enable, args[1]); 10547 CONVERT_BOOLEAN_CHECKED(enable, args[1]);
10102 10548
10103 // If the number doesn't match an enum value, the ChangeBreakOnException 10549 // If the number doesn't match an enum value, the ChangeBreakOnException
10104 // function will default to affecting caught exceptions. 10550 // function will default to affecting caught exceptions.
10105 ExceptionBreakType type = 10551 ExceptionBreakType type =
10106 static_cast<ExceptionBreakType>(NumberToUint32(args[0])); 10552 static_cast<ExceptionBreakType>(NumberToUint32(args[0]));
10107 // Update break point state. 10553 // Update break point state.
10108 Debug::ChangeBreakOnException(type, enable); 10554 isolate->debug()->ChangeBreakOnException(type, enable);
10109 return Heap::undefined_value(); 10555 return isolate->heap()->undefined_value();
10110 } 10556 }
10111 10557
10112 10558
10113 // Returns the state of break on exceptions 10559 // Returns the state of break on exceptions
10114 // args[0]: boolean indicating uncaught exceptions 10560 // args[0]: boolean indicating uncaught exceptions
10115 static MaybeObject* Runtime_IsBreakOnException(Arguments args) { 10561 static MaybeObject* Runtime_IsBreakOnException(RUNTIME_CALLING_CONVENTION) {
10116 HandleScope scope; 10562 RUNTIME_GET_ISOLATE;
10563 HandleScope scope(isolate);
10117 ASSERT(args.length() == 1); 10564 ASSERT(args.length() == 1);
10118 RUNTIME_ASSERT(args[0]->IsNumber()); 10565 RUNTIME_ASSERT(args[0]->IsNumber());
10119 10566
10120 ExceptionBreakType type = 10567 ExceptionBreakType type =
10121 static_cast<ExceptionBreakType>(NumberToUint32(args[0])); 10568 static_cast<ExceptionBreakType>(NumberToUint32(args[0]));
10122 bool result = Debug::IsBreakOnException(type); 10569 bool result = isolate->debug()->IsBreakOnException(type);
10123 return Smi::FromInt(result); 10570 return Smi::FromInt(result);
10124 } 10571 }
10125 10572
10126 10573
10127 // Prepare for stepping 10574 // Prepare for stepping
10128 // args[0]: break id for checking execution state 10575 // args[0]: break id for checking execution state
10129 // args[1]: step action from the enumeration StepAction 10576 // args[1]: step action from the enumeration StepAction
10130 // args[2]: number of times to perform the step, for step out it is the number 10577 // args[2]: number of times to perform the step, for step out it is the number
10131 // of frames to step down. 10578 // of frames to step down.
10132 static MaybeObject* Runtime_PrepareStep(Arguments args) { 10579 static MaybeObject* Runtime_PrepareStep(RUNTIME_CALLING_CONVENTION) {
10133 HandleScope scope; 10580 RUNTIME_GET_ISOLATE;
10581 HandleScope scope(isolate);
10134 ASSERT(args.length() == 3); 10582 ASSERT(args.length() == 3);
10135 // Check arguments. 10583 // Check arguments.
10136 Object* check; 10584 Object* check;
10137 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args); 10585 { MaybeObject* maybe_check = Runtime_CheckExecutionState(args, isolate);
10138 if (!maybe_check->ToObject(&check)) return maybe_check; 10586 if (!maybe_check->ToObject(&check)) return maybe_check;
10139 } 10587 }
10140 if (!args[1]->IsNumber() || !args[2]->IsNumber()) { 10588 if (!args[1]->IsNumber() || !args[2]->IsNumber()) {
10141 return Top::Throw(Heap::illegal_argument_symbol()); 10589 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
10142 } 10590 }
10143 10591
10144 // Get the step action and check validity. 10592 // Get the step action and check validity.
10145 StepAction step_action = static_cast<StepAction>(NumberToInt32(args[1])); 10593 StepAction step_action = static_cast<StepAction>(NumberToInt32(args[1]));
10146 if (step_action != StepIn && 10594 if (step_action != StepIn &&
10147 step_action != StepNext && 10595 step_action != StepNext &&
10148 step_action != StepOut && 10596 step_action != StepOut &&
10149 step_action != StepInMin && 10597 step_action != StepInMin &&
10150 step_action != StepMin) { 10598 step_action != StepMin) {
10151 return Top::Throw(Heap::illegal_argument_symbol()); 10599 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
10152 } 10600 }
10153 10601
10154 // Get the number of steps. 10602 // Get the number of steps.
10155 int step_count = NumberToInt32(args[2]); 10603 int step_count = NumberToInt32(args[2]);
10156 if (step_count < 1) { 10604 if (step_count < 1) {
10157 return Top::Throw(Heap::illegal_argument_symbol()); 10605 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
10158 } 10606 }
10159 10607
10160 // Clear all current stepping setup. 10608 // Clear all current stepping setup.
10161 Debug::ClearStepping(); 10609 isolate->debug()->ClearStepping();
10162 10610
10163 // Prepare step. 10611 // Prepare step.
10164 Debug::PrepareStep(static_cast<StepAction>(step_action), step_count); 10612 isolate->debug()->PrepareStep(static_cast<StepAction>(step_action),
10165 return Heap::undefined_value(); 10613 step_count);
10614 return isolate->heap()->undefined_value();
10166 } 10615 }
10167 10616
10168 10617
10169 // Clear all stepping set by PrepareStep. 10618 // Clear all stepping set by PrepareStep.
10170 static MaybeObject* Runtime_ClearStepping(Arguments args) { 10619 static MaybeObject* Runtime_ClearStepping(RUNTIME_CALLING_CONVENTION) {
10171 HandleScope scope; 10620 RUNTIME_GET_ISOLATE;
10621 HandleScope scope(isolate);
10172 ASSERT(args.length() == 0); 10622 ASSERT(args.length() == 0);
10173 Debug::ClearStepping(); 10623 isolate->debug()->ClearStepping();
10174 return Heap::undefined_value(); 10624 return isolate->heap()->undefined_value();
10175 } 10625 }
10176 10626
10177 10627
10178 // Creates a copy of the with context chain. The copy of the context chain is 10628 // Creates a copy of the with context chain. The copy of the context chain is
10179 // is linked to the function context supplied. 10629 // is linked to the function context supplied.
10180 static Handle<Context> CopyWithContextChain(Handle<Context> context_chain, 10630 static Handle<Context> CopyWithContextChain(Handle<Context> context_chain,
10181 Handle<Context> function_context) { 10631 Handle<Context> function_context) {
10182 // At the bottom of the chain. Return the function context to link to. 10632 // At the bottom of the chain. Return the function context to link to.
10183 if (context_chain->is_function_context()) { 10633 if (context_chain->is_function_context()) {
10184 return function_context; 10634 return function_context;
10185 } 10635 }
10186 10636
10187 // Recursively copy the with contexts. 10637 // Recursively copy the with contexts.
10188 Handle<Context> previous(context_chain->previous()); 10638 Handle<Context> previous(context_chain->previous());
10189 Handle<JSObject> extension(JSObject::cast(context_chain->extension())); 10639 Handle<JSObject> extension(JSObject::cast(context_chain->extension()));
10190 Handle<Context> context = CopyWithContextChain(function_context, previous); 10640 Handle<Context> context = CopyWithContextChain(function_context, previous);
10191 return Factory::NewWithContext(context, 10641 return context->GetIsolate()->factory()->NewWithContext(
10192 extension, 10642 context, extension, context_chain->IsCatchContext());
10193 context_chain->IsCatchContext());
10194 } 10643 }
10195 10644
10196 10645
10197 // Helper function to find or create the arguments object for 10646 // Helper function to find or create the arguments object for
10198 // Runtime_DebugEvaluate. 10647 // Runtime_DebugEvaluate.
10199 static Handle<Object> GetArgumentsObject(JavaScriptFrame* frame, 10648 static Handle<Object> GetArgumentsObject(Isolate* isolate,
10649 JavaScriptFrame* frame,
10200 Handle<JSFunction> function, 10650 Handle<JSFunction> function,
10201 Handle<SerializedScopeInfo> scope_info, 10651 Handle<SerializedScopeInfo> scope_info,
10202 const ScopeInfo<>* sinfo, 10652 const ScopeInfo<>* sinfo,
10203 Handle<Context> function_context) { 10653 Handle<Context> function_context) {
10204 // Try to find the value of 'arguments' to pass as parameter. If it is not 10654 // Try to find the value of 'arguments' to pass as parameter. If it is not
10205 // found (that is the debugged function does not reference 'arguments' and 10655 // found (that is the debugged function does not reference 'arguments' and
10206 // does not support eval) then create an 'arguments' object. 10656 // does not support eval) then create an 'arguments' object.
10207 int index; 10657 int index;
10208 if (sinfo->number_of_stack_slots() > 0) { 10658 if (sinfo->number_of_stack_slots() > 0) {
10209 index = scope_info->StackSlotIndex(Heap::arguments_symbol()); 10659 index = scope_info->StackSlotIndex(isolate->heap()->arguments_symbol());
10210 if (index != -1) { 10660 if (index != -1) {
10211 return Handle<Object>(frame->GetExpression(index)); 10661 return Handle<Object>(frame->GetExpression(index), isolate);
10212 } 10662 }
10213 } 10663 }
10214 10664
10215 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { 10665 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) {
10216 index = scope_info->ContextSlotIndex(Heap::arguments_symbol(), NULL); 10666 index = scope_info->ContextSlotIndex(isolate->heap()->arguments_symbol(),
10667 NULL);
10217 if (index != -1) { 10668 if (index != -1) {
10218 return Handle<Object>(function_context->get(index)); 10669 return Handle<Object>(function_context->get(index), isolate);
10219 } 10670 }
10220 } 10671 }
10221 10672
10222 const int length = frame->ComputeParametersCount(); 10673 const int length = frame->ComputeParametersCount();
10223 Handle<JSObject> arguments = Factory::NewArgumentsObject(function, length); 10674 Handle<JSObject> arguments =
10224 Handle<FixedArray> array = Factory::NewFixedArray(length); 10675 isolate->factory()->NewArgumentsObject(function, length);
10676 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length);
10225 10677
10226 AssertNoAllocation no_gc; 10678 AssertNoAllocation no_gc;
10227 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); 10679 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc);
10228 for (int i = 0; i < length; i++) { 10680 for (int i = 0; i < length; i++) {
10229 array->set(i, frame->GetParameter(i), mode); 10681 array->set(i, frame->GetParameter(i), mode);
10230 } 10682 }
10231 arguments->set_elements(*array); 10683 arguments->set_elements(*array);
10232 return arguments; 10684 return arguments;
10233 } 10685 }
10234 10686
10235 10687
10688 static const char kSourceStr[] =
10689 "(function(arguments,__source__){return eval(__source__);})";
10690
10691
10236 // Evaluate a piece of JavaScript in the context of a stack frame for 10692 // Evaluate a piece of JavaScript in the context of a stack frame for
10237 // debugging. This is accomplished by creating a new context which in its 10693 // debugging. This is accomplished by creating a new context which in its
10238 // extension part has all the parameters and locals of the function on the 10694 // extension part has all the parameters and locals of the function on the
10239 // stack frame. A function which calls eval with the code to evaluate is then 10695 // stack frame. A function which calls eval with the code to evaluate is then
10240 // compiled in this context and called in this context. As this context 10696 // compiled in this context and called in this context. As this context
10241 // replaces the context of the function on the stack frame a new (empty) 10697 // replaces the context of the function on the stack frame a new (empty)
10242 // function is created as well to be used as the closure for the context. 10698 // function is created as well to be used as the closure for the context.
10243 // This function and the context acts as replacements for the function on the 10699 // This function and the context acts as replacements for the function on the
10244 // stack frame presenting the same view of the values of parameters and 10700 // stack frame presenting the same view of the values of parameters and
10245 // local variables as if the piece of JavaScript was evaluated at the point 10701 // local variables as if the piece of JavaScript was evaluated at the point
10246 // where the function on the stack frame is currently stopped. 10702 // where the function on the stack frame is currently stopped.
10247 static MaybeObject* Runtime_DebugEvaluate(Arguments args) { 10703 static MaybeObject* Runtime_DebugEvaluate(RUNTIME_CALLING_CONVENTION) {
10248 HandleScope scope; 10704 RUNTIME_GET_ISOLATE;
10705 HandleScope scope(isolate);
10249 10706
10250 // Check the execution state and decode arguments frame and source to be 10707 // Check the execution state and decode arguments frame and source to be
10251 // evaluated. 10708 // evaluated.
10252 ASSERT(args.length() == 5); 10709 ASSERT(args.length() == 5);
10253 Object* check_result; 10710 Object* check_result;
10254 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); 10711 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args,
10712 isolate);
10255 if (!maybe_check_result->ToObject(&check_result)) { 10713 if (!maybe_check_result->ToObject(&check_result)) {
10256 return maybe_check_result; 10714 return maybe_check_result;
10257 } 10715 }
10258 } 10716 }
10259 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 10717 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
10260 CONVERT_ARG_CHECKED(String, source, 2); 10718 CONVERT_ARG_CHECKED(String, source, 2);
10261 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); 10719 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]);
10262 Handle<Object> additional_context(args[4]); 10720 Handle<Object> additional_context(args[4]);
10263 10721
10264 // Handle the processing of break. 10722 // Handle the processing of break.
10265 DisableBreak disable_break_save(disable_break); 10723 DisableBreak disable_break_save(disable_break);
10266 10724
10267 // Get the frame where the debugging is performed. 10725 // Get the frame where the debugging is performed.
10268 StackFrame::Id id = UnwrapFrameId(wrapped_id); 10726 StackFrame::Id id = UnwrapFrameId(wrapped_id);
10269 JavaScriptFrameIterator it(id); 10727 JavaScriptFrameIterator it(id);
10270 JavaScriptFrame* frame = it.frame(); 10728 JavaScriptFrame* frame = it.frame();
10271 Handle<JSFunction> function(JSFunction::cast(frame->function())); 10729 Handle<JSFunction> function(JSFunction::cast(frame->function()));
10272 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); 10730 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info());
10273 ScopeInfo<> sinfo(*scope_info); 10731 ScopeInfo<> sinfo(*scope_info);
10274 10732
10275 // Traverse the saved contexts chain to find the active context for the 10733 // Traverse the saved contexts chain to find the active context for the
10276 // selected frame. 10734 // selected frame.
10277 SaveContext* save = Top::save_context(); 10735 SaveContext* save = isolate->save_context();
10278 while (save != NULL && !save->below(frame)) { 10736 while (save != NULL && !save->below(frame)) {
10279 save = save->prev(); 10737 save = save->prev();
10280 } 10738 }
10281 ASSERT(save != NULL); 10739 ASSERT(save != NULL);
10282 SaveContext savex; 10740 SaveContext savex(isolate);
10283 Top::set_context(*(save->context())); 10741 isolate->set_context(*(save->context()));
10284 10742
10285 // Create the (empty) function replacing the function on the stack frame for 10743 // Create the (empty) function replacing the function on the stack frame for
10286 // the purpose of evaluating in the context created below. It is important 10744 // the purpose of evaluating in the context created below. It is important
10287 // that this function does not describe any parameters and local variables 10745 // that this function does not describe any parameters and local variables
10288 // in the context. If it does then this will cause problems with the lookup 10746 // in the context. If it does then this will cause problems with the lookup
10289 // in Context::Lookup, where context slots for parameters and local variables 10747 // in Context::Lookup, where context slots for parameters and local variables
10290 // are looked at before the extension object. 10748 // are looked at before the extension object.
10291 Handle<JSFunction> go_between = 10749 Handle<JSFunction> go_between =
10292 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value()); 10750 isolate->factory()->NewFunction(isolate->factory()->empty_string(),
10751 isolate->factory()->undefined_value());
10293 go_between->set_context(function->context()); 10752 go_between->set_context(function->context());
10294 #ifdef DEBUG 10753 #ifdef DEBUG
10295 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info()); 10754 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info());
10296 ASSERT(go_between_sinfo.number_of_parameters() == 0); 10755 ASSERT(go_between_sinfo.number_of_parameters() == 0);
10297 ASSERT(go_between_sinfo.number_of_context_slots() == 0); 10756 ASSERT(go_between_sinfo.number_of_context_slots() == 0);
10298 #endif 10757 #endif
10299 10758
10300 // Materialize the content of the local scope into a JSObject. 10759 // Materialize the content of the local scope into a JSObject.
10301 Handle<JSObject> local_scope = MaterializeLocalScope(frame); 10760 Handle<JSObject> local_scope = MaterializeLocalScope(isolate, frame);
10302 RETURN_IF_EMPTY_HANDLE(local_scope); 10761 RETURN_IF_EMPTY_HANDLE(isolate, local_scope);
10303 10762
10304 // Allocate a new context for the debug evaluation and set the extension 10763 // Allocate a new context for the debug evaluation and set the extension
10305 // object build. 10764 // object build.
10306 Handle<Context> context = 10765 Handle<Context> context =
10307 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); 10766 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS,
10767 go_between);
10308 context->set_extension(*local_scope); 10768 context->set_extension(*local_scope);
10309 // Copy any with contexts present and chain them in front of this context. 10769 // Copy any with contexts present and chain them in front of this context.
10310 Handle<Context> frame_context(Context::cast(frame->context())); 10770 Handle<Context> frame_context(Context::cast(frame->context()));
10311 Handle<Context> function_context(frame_context->fcontext()); 10771 Handle<Context> function_context(frame_context->fcontext());
10312 context = CopyWithContextChain(frame_context, context); 10772 context = CopyWithContextChain(frame_context, context);
10313 10773
10314 if (additional_context->IsJSObject()) { 10774 if (additional_context->IsJSObject()) {
10315 context = Factory::NewWithContext(context, 10775 context = isolate->factory()->NewWithContext(context,
10316 Handle<JSObject>::cast(additional_context), false); 10776 Handle<JSObject>::cast(additional_context), false);
10317 } 10777 }
10318 10778
10319 // Wrap the evaluation statement in a new function compiled in the newly 10779 // Wrap the evaluation statement in a new function compiled in the newly
10320 // created context. The function has one parameter which has to be called 10780 // created context. The function has one parameter which has to be called
10321 // 'arguments'. This it to have access to what would have been 'arguments' in 10781 // 'arguments'. This it to have access to what would have been 'arguments' in
10322 // the function being debugged. 10782 // the function being debugged.
10323 // function(arguments,__source__) {return eval(__source__);} 10783 // function(arguments,__source__) {return eval(__source__);}
10324 static const char* source_str = 10784
10325 "(function(arguments,__source__){return eval(__source__);})";
10326 static const int source_str_length = StrLength(source_str);
10327 Handle<String> function_source = 10785 Handle<String> function_source =
10328 Factory::NewStringFromAscii(Vector<const char>(source_str, 10786 isolate->factory()->NewStringFromAscii(
10329 source_str_length)); 10787 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1));
10330 10788
10331 // Currently, the eval code will be executed in non-strict mode, 10789 // Currently, the eval code will be executed in non-strict mode,
10332 // even in the strict code context. 10790 // even in the strict code context.
10333 Handle<SharedFunctionInfo> shared = 10791 Handle<SharedFunctionInfo> shared =
10334 Compiler::CompileEval(function_source, 10792 Compiler::CompileEval(function_source,
10335 context, 10793 context,
10336 context->IsGlobalContext(), 10794 context->IsGlobalContext(),
10337 kNonStrictMode); 10795 kNonStrictMode);
10338 if (shared.is_null()) return Failure::Exception(); 10796 if (shared.is_null()) return Failure::Exception();
10339 Handle<JSFunction> compiled_function = 10797 Handle<JSFunction> compiled_function =
10340 Factory::NewFunctionFromSharedFunctionInfo(shared, context); 10798 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context);
10341 10799
10342 // Invoke the result of the compilation to get the evaluation function. 10800 // Invoke the result of the compilation to get the evaluation function.
10343 bool has_pending_exception; 10801 bool has_pending_exception;
10344 Handle<Object> receiver(frame->receiver()); 10802 Handle<Object> receiver(frame->receiver(), isolate);
10345 Handle<Object> evaluation_function = 10803 Handle<Object> evaluation_function =
10346 Execution::Call(compiled_function, receiver, 0, NULL, 10804 Execution::Call(compiled_function, receiver, 0, NULL,
10347 &has_pending_exception); 10805 &has_pending_exception);
10348 if (has_pending_exception) return Failure::Exception(); 10806 if (has_pending_exception) return Failure::Exception();
10349 10807
10350 Handle<Object> arguments = GetArgumentsObject(frame, function, scope_info, 10808 Handle<Object> arguments = GetArgumentsObject(isolate, frame,
10809 function, scope_info,
10351 &sinfo, function_context); 10810 &sinfo, function_context);
10352 10811
10353 // Invoke the evaluation function and return the result. 10812 // Invoke the evaluation function and return the result.
10354 const int argc = 2; 10813 const int argc = 2;
10355 Object** argv[argc] = { arguments.location(), 10814 Object** argv[argc] = { arguments.location(),
10356 Handle<Object>::cast(source).location() }; 10815 Handle<Object>::cast(source).location() };
10357 Handle<Object> result = 10816 Handle<Object> result =
10358 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver, 10817 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver,
10359 argc, argv, &has_pending_exception); 10818 argc, argv, &has_pending_exception);
10360 if (has_pending_exception) return Failure::Exception(); 10819 if (has_pending_exception) return Failure::Exception();
10361 10820
10362 // Skip the global proxy as it has no properties and always delegates to the 10821 // Skip the global proxy as it has no properties and always delegates to the
10363 // real global object. 10822 // real global object.
10364 if (result->IsJSGlobalProxy()) { 10823 if (result->IsJSGlobalProxy()) {
10365 result = Handle<JSObject>(JSObject::cast(result->GetPrototype())); 10824 result = Handle<JSObject>(JSObject::cast(result->GetPrototype()));
10366 } 10825 }
10367 10826
10368 return *result; 10827 return *result;
10369 } 10828 }
10370 10829
10371 10830
10372 static MaybeObject* Runtime_DebugEvaluateGlobal(Arguments args) { 10831 static MaybeObject* Runtime_DebugEvaluateGlobal(RUNTIME_CALLING_CONVENTION) {
10373 HandleScope scope; 10832 RUNTIME_GET_ISOLATE;
10833 HandleScope scope(isolate);
10374 10834
10375 // Check the execution state and decode arguments frame and source to be 10835 // Check the execution state and decode arguments frame and source to be
10376 // evaluated. 10836 // evaluated.
10377 ASSERT(args.length() == 4); 10837 ASSERT(args.length() == 4);
10378 Object* check_result; 10838 Object* check_result;
10379 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); 10839 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args,
10840 isolate);
10380 if (!maybe_check_result->ToObject(&check_result)) { 10841 if (!maybe_check_result->ToObject(&check_result)) {
10381 return maybe_check_result; 10842 return maybe_check_result;
10382 } 10843 }
10383 } 10844 }
10384 CONVERT_ARG_CHECKED(String, source, 1); 10845 CONVERT_ARG_CHECKED(String, source, 1);
10385 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); 10846 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]);
10386 Handle<Object> additional_context(args[3]); 10847 Handle<Object> additional_context(args[3]);
10387 10848
10388 // Handle the processing of break. 10849 // Handle the processing of break.
10389 DisableBreak disable_break_save(disable_break); 10850 DisableBreak disable_break_save(disable_break);
10390 10851
10391 // Enter the top context from before the debugger was invoked. 10852 // Enter the top context from before the debugger was invoked.
10392 SaveContext save; 10853 SaveContext save(isolate);
10393 SaveContext* top = &save; 10854 SaveContext* top = &save;
10394 while (top != NULL && *top->context() == *Debug::debug_context()) { 10855 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) {
10395 top = top->prev(); 10856 top = top->prev();
10396 } 10857 }
10397 if (top != NULL) { 10858 if (top != NULL) {
10398 Top::set_context(*top->context()); 10859 isolate->set_context(*top->context());
10399 } 10860 }
10400 10861
10401 // Get the global context now set to the top context from before the 10862 // Get the global context now set to the top context from before the
10402 // debugger was invoked. 10863 // debugger was invoked.
10403 Handle<Context> context = Top::global_context(); 10864 Handle<Context> context = isolate->global_context();
10404 10865
10405 bool is_global = true; 10866 bool is_global = true;
10406 10867
10407 if (additional_context->IsJSObject()) { 10868 if (additional_context->IsJSObject()) {
10408 // Create a function context first, than put 'with' context on top of it. 10869 // Create a function context first, than put 'with' context on top of it.
10409 Handle<JSFunction> go_between = Factory::NewFunction( 10870 Handle<JSFunction> go_between = isolate->factory()->NewFunction(
10410 Factory::empty_string(), Factory::undefined_value()); 10871 isolate->factory()->empty_string(),
10872 isolate->factory()->undefined_value());
10411 go_between->set_context(*context); 10873 go_between->set_context(*context);
10412 context = 10874 context =
10413 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); 10875 isolate->factory()->NewFunctionContext(
10876 Context::MIN_CONTEXT_SLOTS, go_between);
10414 context->set_extension(JSObject::cast(*additional_context)); 10877 context->set_extension(JSObject::cast(*additional_context));
10415 is_global = false; 10878 is_global = false;
10416 } 10879 }
10417 10880
10418 // Compile the source to be evaluated. 10881 // Compile the source to be evaluated.
10419 // Currently, the eval code will be executed in non-strict mode, 10882 // Currently, the eval code will be executed in non-strict mode,
10420 // even in the strict code context. 10883 // even in the strict code context.
10421 Handle<SharedFunctionInfo> shared = 10884 Handle<SharedFunctionInfo> shared =
10422 Compiler::CompileEval(source, context, is_global, kNonStrictMode); 10885 Compiler::CompileEval(source, context, is_global, kNonStrictMode);
10423 if (shared.is_null()) return Failure::Exception(); 10886 if (shared.is_null()) return Failure::Exception();
10424 Handle<JSFunction> compiled_function = 10887 Handle<JSFunction> compiled_function =
10425 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, 10888 Handle<JSFunction>(
10426 context)); 10889 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
10890 context));
10427 10891
10428 // Invoke the result of the compilation to get the evaluation function. 10892 // Invoke the result of the compilation to get the evaluation function.
10429 bool has_pending_exception; 10893 bool has_pending_exception;
10430 Handle<Object> receiver = Top::global(); 10894 Handle<Object> receiver = isolate->global();
10431 Handle<Object> result = 10895 Handle<Object> result =
10432 Execution::Call(compiled_function, receiver, 0, NULL, 10896 Execution::Call(compiled_function, receiver, 0, NULL,
10433 &has_pending_exception); 10897 &has_pending_exception);
10434 if (has_pending_exception) return Failure::Exception(); 10898 if (has_pending_exception) return Failure::Exception();
10435 return *result; 10899 return *result;
10436 } 10900 }
10437 10901
10438 10902
10439 static MaybeObject* Runtime_DebugGetLoadedScripts(Arguments args) { 10903 static MaybeObject* Runtime_DebugGetLoadedScripts(RUNTIME_CALLING_CONVENTION) {
10440 HandleScope scope; 10904 RUNTIME_GET_ISOLATE;
10905 HandleScope scope(isolate);
10441 ASSERT(args.length() == 0); 10906 ASSERT(args.length() == 0);
10442 10907
10443 // Fill the script objects. 10908 // Fill the script objects.
10444 Handle<FixedArray> instances = Debug::GetLoadedScripts(); 10909 Handle<FixedArray> instances = isolate->debug()->GetLoadedScripts();
10445 10910
10446 // Convert the script objects to proper JS objects. 10911 // Convert the script objects to proper JS objects.
10447 for (int i = 0; i < instances->length(); i++) { 10912 for (int i = 0; i < instances->length(); i++) {
10448 Handle<Script> script = Handle<Script>(Script::cast(instances->get(i))); 10913 Handle<Script> script = Handle<Script>(Script::cast(instances->get(i)));
10449 // Get the script wrapper in a local handle before calling GetScriptWrapper, 10914 // Get the script wrapper in a local handle before calling GetScriptWrapper,
10450 // because using 10915 // because using
10451 // instances->set(i, *GetScriptWrapper(script)) 10916 // instances->set(i, *GetScriptWrapper(script))
10452 // is unsafe as GetScriptWrapper might call GC and the C++ compiler might 10917 // is unsafe as GetScriptWrapper might call GC and the C++ compiler might
10453 // already have deferenced the instances handle. 10918 // already have deferenced the instances handle.
10454 Handle<JSValue> wrapper = GetScriptWrapper(script); 10919 Handle<JSValue> wrapper = GetScriptWrapper(script);
10455 instances->set(i, *wrapper); 10920 instances->set(i, *wrapper);
10456 } 10921 }
10457 10922
10458 // Return result as a JS array. 10923 // Return result as a JS array.
10459 Handle<JSObject> result = Factory::NewJSObject(Top::array_function()); 10924 Handle<JSObject> result =
10925 isolate->factory()->NewJSObject(isolate->array_function());
10460 Handle<JSArray>::cast(result)->SetContent(*instances); 10926 Handle<JSArray>::cast(result)->SetContent(*instances);
10461 return *result; 10927 return *result;
10462 } 10928 }
10463 10929
10464 10930
10465 // Helper function used by Runtime_DebugReferencedBy below. 10931 // Helper function used by Runtime_DebugReferencedBy below.
10466 static int DebugReferencedBy(HeapIterator* iterator, 10932 static int DebugReferencedBy(HeapIterator* iterator,
10467 JSObject* target, 10933 JSObject* target,
10468 Object* instance_filter, int max_references, 10934 Object* instance_filter, int max_references,
10469 FixedArray* instances, int instances_size, 10935 FixedArray* instances, int instances_size,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
10529 10995
10530 // Return the number of referencing objects found. 10996 // Return the number of referencing objects found.
10531 return count; 10997 return count;
10532 } 10998 }
10533 10999
10534 11000
10535 // Scan the heap for objects with direct references to an object 11001 // Scan the heap for objects with direct references to an object
10536 // args[0]: the object to find references to 11002 // args[0]: the object to find references to
10537 // args[1]: constructor function for instances to exclude (Mirror) 11003 // args[1]: constructor function for instances to exclude (Mirror)
10538 // args[2]: the the maximum number of objects to return 11004 // args[2]: the the maximum number of objects to return
10539 static MaybeObject* Runtime_DebugReferencedBy(Arguments args) { 11005 static MaybeObject* Runtime_DebugReferencedBy(RUNTIME_CALLING_CONVENTION) {
11006 RUNTIME_GET_ISOLATE;
10540 ASSERT(args.length() == 3); 11007 ASSERT(args.length() == 3);
10541 11008
10542 // First perform a full GC in order to avoid references from dead objects. 11009 // First perform a full GC in order to avoid references from dead objects.
10543 Heap::CollectAllGarbage(Heap::kMakeHeapIterableMask); 11010 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask);
10544 // The heap iterator reserves the right to do a GC to make the heap iterable. 11011 // The heap iterator reserves the right to do a GC to make the heap iterable.
10545 // Due to the GC above we know it won't need to do that, but it seems cleaner 11012 // Due to the GC above we know it won't need to do that, but it seems cleaner
10546 // to get the heap iterator constructed before we start having unprotected 11013 // to get the heap iterator constructed before we start having unprotected
10547 // Object* locals that are not protected by handles. 11014 // Object* locals that are not protected by handles.
10548 HeapIterator heap_iterator; 11015 HeapIterator heap_iterator;
10549 HeapIterator heap_iterator2; 11016 HeapIterator heap_iterator2;
10550 11017
10551 // Check parameters. 11018 // Check parameters.
10552 CONVERT_CHECKED(JSObject, target, args[0]); 11019 CONVERT_CHECKED(JSObject, target, args[0]);
10553 Object* instance_filter = args[1]; 11020 Object* instance_filter = args[1];
10554 RUNTIME_ASSERT(instance_filter->IsUndefined() || 11021 RUNTIME_ASSERT(instance_filter->IsUndefined() ||
10555 instance_filter->IsJSObject()); 11022 instance_filter->IsJSObject());
10556 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); 11023 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]);
10557 RUNTIME_ASSERT(max_references >= 0); 11024 RUNTIME_ASSERT(max_references >= 0);
10558 11025
10559 11026
10560 // Get the constructor function for context extension and arguments array. 11027 // Get the constructor function for context extension and arguments array.
10561 JSObject* arguments_boilerplate = 11028 JSObject* arguments_boilerplate =
10562 Top::context()->global_context()->arguments_boilerplate(); 11029 isolate->context()->global_context()->arguments_boilerplate();
10563 JSFunction* arguments_function = 11030 JSFunction* arguments_function =
10564 JSFunction::cast(arguments_boilerplate->map()->constructor()); 11031 JSFunction::cast(arguments_boilerplate->map()->constructor());
10565 11032
10566 // Get the number of referencing objects. 11033 // Get the number of referencing objects.
10567 int count; 11034 int count;
10568 count = DebugReferencedBy(&heap_iterator, 11035 count = DebugReferencedBy(&heap_iterator,
10569 target, instance_filter, max_references, 11036 target, instance_filter, max_references,
10570 NULL, 0, arguments_function); 11037 NULL, 0, arguments_function);
10571 11038
10572 // Allocate an array to hold the result. 11039 // Allocate an array to hold the result.
10573 Object* object; 11040 Object* object;
10574 { MaybeObject* maybe_object = Heap::AllocateFixedArray(count); 11041 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count);
10575 if (!maybe_object->ToObject(&object)) return maybe_object; 11042 if (!maybe_object->ToObject(&object)) return maybe_object;
10576 } 11043 }
10577 FixedArray* instances = FixedArray::cast(object); 11044 FixedArray* instances = FixedArray::cast(object);
10578 11045
10579 // Fill the referencing objects. 11046 // Fill the referencing objects.
10580 count = DebugReferencedBy(&heap_iterator2, 11047 count = DebugReferencedBy(&heap_iterator2,
10581 target, instance_filter, max_references, 11048 target, instance_filter, max_references,
10582 instances, count, arguments_function); 11049 instances, count, arguments_function);
10583 11050
10584 // Return result as JS array. 11051 // Return result as JS array.
10585 Object* result; 11052 Object* result;
10586 { MaybeObject* maybe_result = Heap::AllocateJSObject( 11053 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
10587 Top::context()->global_context()->array_function()); 11054 isolate->context()->global_context()->array_function());
10588 if (!maybe_result->ToObject(&result)) return maybe_result; 11055 if (!maybe_result->ToObject(&result)) return maybe_result;
10589 } 11056 }
10590 JSArray::cast(result)->SetContent(instances); 11057 JSArray::cast(result)->SetContent(instances);
10591 return result; 11058 return result;
10592 } 11059 }
10593 11060
10594 11061
10595 // Helper function used by Runtime_DebugConstructedBy below. 11062 // Helper function used by Runtime_DebugConstructedBy below.
10596 static int DebugConstructedBy(HeapIterator* iterator, 11063 static int DebugConstructedBy(HeapIterator* iterator,
10597 JSFunction* constructor, 11064 JSFunction* constructor,
(...skipping 22 matching lines...) Expand all
10620 } 11087 }
10621 11088
10622 // Return the number of referencing objects found. 11089 // Return the number of referencing objects found.
10623 return count; 11090 return count;
10624 } 11091 }
10625 11092
10626 11093
10627 // Scan the heap for objects constructed by a specific function. 11094 // Scan the heap for objects constructed by a specific function.
10628 // args[0]: the constructor to find instances of 11095 // args[0]: the constructor to find instances of
10629 // args[1]: the the maximum number of objects to return 11096 // args[1]: the the maximum number of objects to return
10630 static MaybeObject* Runtime_DebugConstructedBy(Arguments args) { 11097 static MaybeObject* Runtime_DebugConstructedBy(RUNTIME_CALLING_CONVENTION) {
11098 RUNTIME_GET_ISOLATE;
10631 ASSERT(args.length() == 2); 11099 ASSERT(args.length() == 2);
10632 11100
10633 // First perform a full GC in order to avoid dead objects. 11101 // First perform a full GC in order to avoid dead objects.
10634 Heap::CollectAllGarbage(Heap::kMakeHeapIterableMask); 11102 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask);
10635 11103
10636 HeapIterator heap_iterator; 11104 HeapIterator heap_iterator;
10637 HeapIterator heap_iterator2; 11105 HeapIterator heap_iterator2;
10638 11106
10639 // Check parameters. 11107 // Check parameters.
10640 CONVERT_CHECKED(JSFunction, constructor, args[0]); 11108 CONVERT_CHECKED(JSFunction, constructor, args[0]);
10641 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); 11109 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]);
10642 RUNTIME_ASSERT(max_references >= 0); 11110 RUNTIME_ASSERT(max_references >= 0);
10643 11111
10644 // Get the number of referencing objects. 11112 // Get the number of referencing objects.
10645 int count; 11113 int count;
10646 count = DebugConstructedBy(&heap_iterator, 11114 count = DebugConstructedBy(&heap_iterator,
10647 constructor, 11115 constructor,
10648 max_references, 11116 max_references,
10649 NULL, 11117 NULL,
10650 0); 11118 0);
10651 11119
10652 // Allocate an array to hold the result. 11120 // Allocate an array to hold the result.
10653 Object* object; 11121 Object* object;
10654 { MaybeObject* maybe_object = Heap::AllocateFixedArray(count); 11122 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count);
10655 if (!maybe_object->ToObject(&object)) return maybe_object; 11123 if (!maybe_object->ToObject(&object)) return maybe_object;
10656 } 11124 }
10657 FixedArray* instances = FixedArray::cast(object); 11125 FixedArray* instances = FixedArray::cast(object);
10658 11126
10659 // Fill the referencing objects. 11127 // Fill the referencing objects.
10660 count = DebugConstructedBy(&heap_iterator2, 11128 count = DebugConstructedBy(&heap_iterator2,
10661 constructor, 11129 constructor,
10662 max_references, 11130 max_references,
10663 instances, 11131 instances,
10664 count); 11132 count);
10665 11133
10666 // Return result as JS array. 11134 // Return result as JS array.
10667 Object* result; 11135 Object* result;
10668 { MaybeObject* maybe_result = Heap::AllocateJSObject( 11136 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
10669 Top::context()->global_context()->array_function()); 11137 isolate->context()->global_context()->array_function());
10670 if (!maybe_result->ToObject(&result)) return maybe_result; 11138 if (!maybe_result->ToObject(&result)) return maybe_result;
10671 } 11139 }
10672 JSArray::cast(result)->SetContent(instances); 11140 JSArray::cast(result)->SetContent(instances);
10673 return result; 11141 return result;
10674 } 11142 }
10675 11143
10676 11144
10677 // Find the effective prototype object as returned by __proto__. 11145 // Find the effective prototype object as returned by __proto__.
10678 // args[0]: the object to find the prototype for. 11146 // args[0]: the object to find the prototype for.
10679 static MaybeObject* Runtime_DebugGetPrototype(Arguments args) { 11147 static MaybeObject* Runtime_DebugGetPrototype(RUNTIME_CALLING_CONVENTION) {
11148 RUNTIME_GET_ISOLATE;
10680 ASSERT(args.length() == 1); 11149 ASSERT(args.length() == 1);
10681 11150
10682 CONVERT_CHECKED(JSObject, obj, args[0]); 11151 CONVERT_CHECKED(JSObject, obj, args[0]);
10683 11152
10684 // Use the __proto__ accessor. 11153 // Use the __proto__ accessor.
10685 return Accessors::ObjectPrototype.getter(obj, NULL); 11154 return Accessors::ObjectPrototype.getter(obj, NULL);
10686 } 11155 }
10687 11156
10688 11157
10689 static MaybeObject* Runtime_SystemBreak(Arguments args) { 11158 static MaybeObject* Runtime_SystemBreak(RUNTIME_CALLING_CONVENTION) {
11159 RUNTIME_GET_ISOLATE;
10690 ASSERT(args.length() == 0); 11160 ASSERT(args.length() == 0);
10691 CPU::DebugBreak(); 11161 CPU::DebugBreak();
10692 return Heap::undefined_value(); 11162 return isolate->heap()->undefined_value();
10693 } 11163 }
10694 11164
10695 11165
10696 static MaybeObject* Runtime_DebugDisassembleFunction(Arguments args) { 11166 static MaybeObject* Runtime_DebugDisassembleFunction(
11167 RUNTIME_CALLING_CONVENTION) {
11168 RUNTIME_GET_ISOLATE;
10697 #ifdef DEBUG 11169 #ifdef DEBUG
10698 HandleScope scope; 11170 HandleScope scope(isolate);
10699 ASSERT(args.length() == 1); 11171 ASSERT(args.length() == 1);
10700 // Get the function and make sure it is compiled. 11172 // Get the function and make sure it is compiled.
10701 CONVERT_ARG_CHECKED(JSFunction, func, 0); 11173 CONVERT_ARG_CHECKED(JSFunction, func, 0);
10702 Handle<SharedFunctionInfo> shared(func->shared()); 11174 Handle<SharedFunctionInfo> shared(func->shared());
10703 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { 11175 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) {
10704 return Failure::Exception(); 11176 return Failure::Exception();
10705 } 11177 }
10706 func->code()->PrintLn(); 11178 func->code()->PrintLn();
10707 #endif // DEBUG 11179 #endif // DEBUG
10708 return Heap::undefined_value(); 11180 return isolate->heap()->undefined_value();
10709 } 11181 }
10710 11182
10711 11183
10712 static MaybeObject* Runtime_DebugDisassembleConstructor(Arguments args) { 11184 static MaybeObject* Runtime_DebugDisassembleConstructor(
11185 RUNTIME_CALLING_CONVENTION) {
11186 RUNTIME_GET_ISOLATE;
10713 #ifdef DEBUG 11187 #ifdef DEBUG
10714 HandleScope scope; 11188 HandleScope scope(isolate);
10715 ASSERT(args.length() == 1); 11189 ASSERT(args.length() == 1);
10716 // Get the function and make sure it is compiled. 11190 // Get the function and make sure it is compiled.
10717 CONVERT_ARG_CHECKED(JSFunction, func, 0); 11191 CONVERT_ARG_CHECKED(JSFunction, func, 0);
10718 Handle<SharedFunctionInfo> shared(func->shared()); 11192 Handle<SharedFunctionInfo> shared(func->shared());
10719 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { 11193 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) {
10720 return Failure::Exception(); 11194 return Failure::Exception();
10721 } 11195 }
10722 shared->construct_stub()->PrintLn(); 11196 shared->construct_stub()->PrintLn();
10723 #endif // DEBUG 11197 #endif // DEBUG
10724 return Heap::undefined_value(); 11198 return isolate->heap()->undefined_value();
10725 } 11199 }
10726 11200
10727 11201
10728 static MaybeObject* Runtime_FunctionGetInferredName(Arguments args) { 11202 static MaybeObject* Runtime_FunctionGetInferredName(
11203 RUNTIME_CALLING_CONVENTION) {
11204 RUNTIME_GET_ISOLATE;
10729 NoHandleAllocation ha; 11205 NoHandleAllocation ha;
10730 ASSERT(args.length() == 1); 11206 ASSERT(args.length() == 1);
10731 11207
10732 CONVERT_CHECKED(JSFunction, f, args[0]); 11208 CONVERT_CHECKED(JSFunction, f, args[0]);
10733 return f->shared()->inferred_name(); 11209 return f->shared()->inferred_name();
10734 } 11210 }
10735 11211
10736 11212
10737 static int FindSharedFunctionInfosForScript(HeapIterator* iterator, 11213 static int FindSharedFunctionInfosForScript(HeapIterator* iterator,
10738 Script* script, 11214 Script* script,
10739 FixedArray* buffer) { 11215 FixedArray* buffer) {
11216 AssertNoAllocation no_allocations;
10740 int counter = 0; 11217 int counter = 0;
10741 int buffer_size = buffer->length(); 11218 int buffer_size = buffer->length();
10742 for (HeapObject* obj = iterator->Next(); 11219 for (HeapObject* obj = iterator->Next();
10743 obj != NULL; 11220 obj != NULL;
10744 obj = iterator->Next()) { 11221 obj = iterator->Next()) {
10745 ASSERT(obj != NULL); 11222 ASSERT(obj != NULL);
10746 if (!obj->IsSharedFunctionInfo()) { 11223 if (!obj->IsSharedFunctionInfo()) {
10747 continue; 11224 continue;
10748 } 11225 }
10749 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); 11226 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
10750 if (shared->script() != script) { 11227 if (shared->script() != script) {
10751 continue; 11228 continue;
10752 } 11229 }
10753 if (counter < buffer_size) { 11230 if (counter < buffer_size) {
10754 buffer->set(counter, shared); 11231 buffer->set(counter, shared);
10755 } 11232 }
10756 counter++; 11233 counter++;
10757 } 11234 }
10758 return counter; 11235 return counter;
10759 } 11236 }
10760 11237
10761 // For a script finds all SharedFunctionInfo's in the heap that points 11238 // For a script finds all SharedFunctionInfo's in the heap that points
10762 // to this script. Returns JSArray of SharedFunctionInfo wrapped 11239 // to this script. Returns JSArray of SharedFunctionInfo wrapped
10763 // in OpaqueReferences. 11240 // in OpaqueReferences.
10764 static MaybeObject* Runtime_LiveEditFindSharedFunctionInfosForScript( 11241 static MaybeObject* Runtime_LiveEditFindSharedFunctionInfosForScript(
10765 Arguments args) { 11242 RUNTIME_CALLING_CONVENTION) {
11243 RUNTIME_GET_ISOLATE;
10766 ASSERT(args.length() == 1); 11244 ASSERT(args.length() == 1);
10767 HandleScope scope; 11245 HandleScope scope(isolate);
10768 CONVERT_CHECKED(JSValue, script_value, args[0]); 11246 CONVERT_CHECKED(JSValue, script_value, args[0]);
10769 11247
10770 11248
10771 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); 11249 Handle<Script> script = Handle<Script>(Script::cast(script_value->value()));
10772 11250
10773 const int kBufferSize = 32; 11251 const int kBufferSize = 32;
10774 11252
10775 Handle<FixedArray> array; 11253 Handle<FixedArray> array;
10776 array = Factory::NewFixedArray(kBufferSize); 11254 array = isolate->factory()->NewFixedArray(kBufferSize);
10777 int number; 11255 int number;
10778 { 11256 {
10779 HeapIterator heap_iterator; 11257 HeapIterator heap_iterator;
10780 AssertNoAllocation no_allocations; 11258 AssertNoAllocation no_allocations;
10781 Script* scr = *script; 11259 Script* scr = *script;
10782 FixedArray* arr = *array; 11260 FixedArray* arr = *array;
10783 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 11261 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
10784 } 11262 }
10785 if (number > kBufferSize) { 11263 if (number > kBufferSize) {
10786 array = Factory::NewFixedArray(number); 11264 array = isolate->factory()->NewFixedArray(number);
10787 HeapIterator heap_iterator; 11265 HeapIterator heap_iterator;
10788 AssertNoAllocation no_allocations; 11266 AssertNoAllocation no_allocations;
10789 Script* scr = *script; 11267 Script* scr = *script;
10790 FixedArray* arr = *array; 11268 FixedArray* arr = *array;
10791 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 11269 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
10792 } 11270 }
10793 11271
10794 Handle<JSArray> result = Factory::NewJSArrayWithElements(array); 11272 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array);
10795 result->set_length(Smi::FromInt(number)); 11273 result->set_length(Smi::FromInt(number));
10796 11274
10797 LiveEdit::WrapSharedFunctionInfos(result); 11275 LiveEdit::WrapSharedFunctionInfos(result);
10798 11276
10799 return *result; 11277 return *result;
10800 } 11278 }
10801 11279
10802 // For a script calculates compilation information about all its functions. 11280 // For a script calculates compilation information about all its functions.
10803 // The script source is explicitly specified by the second argument. 11281 // The script source is explicitly specified by the second argument.
10804 // The source of the actual script is not used, however it is important that 11282 // The source of the actual script is not used, however it is important that
10805 // all generated code keeps references to this particular instance of script. 11283 // all generated code keeps references to this particular instance of script.
10806 // Returns a JSArray of compilation infos. The array is ordered so that 11284 // Returns a JSArray of compilation infos. The array is ordered so that
10807 // each function with all its descendant is always stored in a continues range 11285 // each function with all its descendant is always stored in a continues range
10808 // with the function itself going first. The root function is a script function. 11286 // with the function itself going first. The root function is a script function.
10809 static MaybeObject* Runtime_LiveEditGatherCompileInfo(Arguments args) { 11287 static MaybeObject* Runtime_LiveEditGatherCompileInfo(
11288 RUNTIME_CALLING_CONVENTION) {
11289 RUNTIME_GET_ISOLATE;
10810 ASSERT(args.length() == 2); 11290 ASSERT(args.length() == 2);
10811 HandleScope scope; 11291 HandleScope scope(isolate);
10812 CONVERT_CHECKED(JSValue, script, args[0]); 11292 CONVERT_CHECKED(JSValue, script, args[0]);
10813 CONVERT_ARG_CHECKED(String, source, 1); 11293 CONVERT_ARG_CHECKED(String, source, 1);
10814 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 11294 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
10815 11295
10816 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source); 11296 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source);
10817 11297
10818 if (Top::has_pending_exception()) { 11298 if (isolate->has_pending_exception()) {
10819 return Failure::Exception(); 11299 return Failure::Exception();
10820 } 11300 }
10821 11301
10822 return result; 11302 return result;
10823 } 11303 }
10824 11304
10825 // Changes the source of the script to a new_source. 11305 // Changes the source of the script to a new_source.
10826 // If old_script_name is provided (i.e. is a String), also creates a copy of 11306 // If old_script_name is provided (i.e. is a String), also creates a copy of
10827 // the script with its original source and sends notification to debugger. 11307 // the script with its original source and sends notification to debugger.
10828 static MaybeObject* Runtime_LiveEditReplaceScript(Arguments args) { 11308 static MaybeObject* Runtime_LiveEditReplaceScript(RUNTIME_CALLING_CONVENTION) {
11309 RUNTIME_GET_ISOLATE;
10829 ASSERT(args.length() == 3); 11310 ASSERT(args.length() == 3);
10830 HandleScope scope; 11311 HandleScope scope(isolate);
10831 CONVERT_CHECKED(JSValue, original_script_value, args[0]); 11312 CONVERT_CHECKED(JSValue, original_script_value, args[0]);
10832 CONVERT_ARG_CHECKED(String, new_source, 1); 11313 CONVERT_ARG_CHECKED(String, new_source, 1);
10833 Handle<Object> old_script_name(args[2]); 11314 Handle<Object> old_script_name(args[2], isolate);
10834 11315
10835 CONVERT_CHECKED(Script, original_script_pointer, 11316 CONVERT_CHECKED(Script, original_script_pointer,
10836 original_script_value->value()); 11317 original_script_value->value());
10837 Handle<Script> original_script(original_script_pointer); 11318 Handle<Script> original_script(original_script_pointer);
10838 11319
10839 Object* old_script = LiveEdit::ChangeScriptSource(original_script, 11320 Object* old_script = LiveEdit::ChangeScriptSource(original_script,
10840 new_source, 11321 new_source,
10841 old_script_name); 11322 old_script_name);
10842 11323
10843 if (old_script->IsScript()) { 11324 if (old_script->IsScript()) {
10844 Handle<Script> script_handle(Script::cast(old_script)); 11325 Handle<Script> script_handle(Script::cast(old_script));
10845 return *(GetScriptWrapper(script_handle)); 11326 return *(GetScriptWrapper(script_handle));
10846 } else { 11327 } else {
10847 return Heap::null_value(); 11328 return isolate->heap()->null_value();
10848 } 11329 }
10849 } 11330 }
10850 11331
10851 11332
10852 static MaybeObject* Runtime_LiveEditFunctionSourceUpdated(Arguments args) { 11333 static MaybeObject* Runtime_LiveEditFunctionSourceUpdated(
11334 RUNTIME_CALLING_CONVENTION) {
11335 RUNTIME_GET_ISOLATE;
10853 ASSERT(args.length() == 1); 11336 ASSERT(args.length() == 1);
10854 HandleScope scope; 11337 HandleScope scope(isolate);
10855 CONVERT_ARG_CHECKED(JSArray, shared_info, 0); 11338 CONVERT_ARG_CHECKED(JSArray, shared_info, 0);
10856 return LiveEdit::FunctionSourceUpdated(shared_info); 11339 return LiveEdit::FunctionSourceUpdated(shared_info);
10857 } 11340 }
10858 11341
10859 11342
10860 // Replaces code of SharedFunctionInfo with a new one. 11343 // Replaces code of SharedFunctionInfo with a new one.
10861 static MaybeObject* Runtime_LiveEditReplaceFunctionCode(Arguments args) { 11344 static MaybeObject* Runtime_LiveEditReplaceFunctionCode(
11345 RUNTIME_CALLING_CONVENTION) {
11346 RUNTIME_GET_ISOLATE;
10862 ASSERT(args.length() == 2); 11347 ASSERT(args.length() == 2);
10863 HandleScope scope; 11348 HandleScope scope(isolate);
10864 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0); 11349 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0);
10865 CONVERT_ARG_CHECKED(JSArray, shared_info, 1); 11350 CONVERT_ARG_CHECKED(JSArray, shared_info, 1);
10866 11351
10867 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info); 11352 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info);
10868 } 11353 }
10869 11354
10870 // Connects SharedFunctionInfo to another script. 11355 // Connects SharedFunctionInfo to another script.
10871 static MaybeObject* Runtime_LiveEditFunctionSetScript(Arguments args) { 11356 static MaybeObject* Runtime_LiveEditFunctionSetScript(
11357 RUNTIME_CALLING_CONVENTION) {
11358 RUNTIME_GET_ISOLATE;
10872 ASSERT(args.length() == 2); 11359 ASSERT(args.length() == 2);
10873 HandleScope scope; 11360 HandleScope scope(isolate);
10874 Handle<Object> function_object(args[0]); 11361 Handle<Object> function_object(args[0], isolate);
10875 Handle<Object> script_object(args[1]); 11362 Handle<Object> script_object(args[1], isolate);
10876 11363
10877 if (function_object->IsJSValue()) { 11364 if (function_object->IsJSValue()) {
10878 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object); 11365 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object);
10879 if (script_object->IsJSValue()) { 11366 if (script_object->IsJSValue()) {
10880 CONVERT_CHECKED(Script, script, JSValue::cast(*script_object)->value()); 11367 CONVERT_CHECKED(Script, script, JSValue::cast(*script_object)->value());
10881 script_object = Handle<Object>(script); 11368 script_object = Handle<Object>(script, isolate);
10882 } 11369 }
10883 11370
10884 LiveEdit::SetFunctionScript(function_wrapper, script_object); 11371 LiveEdit::SetFunctionScript(function_wrapper, script_object);
10885 } else { 11372 } else {
10886 // Just ignore this. We may not have a SharedFunctionInfo for some functions 11373 // Just ignore this. We may not have a SharedFunctionInfo for some functions
10887 // and we check it in this function. 11374 // and we check it in this function.
10888 } 11375 }
10889 11376
10890 return Heap::undefined_value(); 11377 return isolate->heap()->undefined_value();
10891 } 11378 }
10892 11379
10893 11380
10894 // In a code of a parent function replaces original function as embedded object 11381 // In a code of a parent function replaces original function as embedded object
10895 // with a substitution one. 11382 // with a substitution one.
10896 static MaybeObject* Runtime_LiveEditReplaceRefToNestedFunction(Arguments args) { 11383 static MaybeObject* Runtime_LiveEditReplaceRefToNestedFunction(
11384 RUNTIME_CALLING_CONVENTION) {
11385 RUNTIME_GET_ISOLATE;
10897 ASSERT(args.length() == 3); 11386 ASSERT(args.length() == 3);
10898 HandleScope scope; 11387 HandleScope scope(isolate);
10899 11388
10900 CONVERT_ARG_CHECKED(JSValue, parent_wrapper, 0); 11389 CONVERT_ARG_CHECKED(JSValue, parent_wrapper, 0);
10901 CONVERT_ARG_CHECKED(JSValue, orig_wrapper, 1); 11390 CONVERT_ARG_CHECKED(JSValue, orig_wrapper, 1);
10902 CONVERT_ARG_CHECKED(JSValue, subst_wrapper, 2); 11391 CONVERT_ARG_CHECKED(JSValue, subst_wrapper, 2);
10903 11392
10904 LiveEdit::ReplaceRefToNestedFunction(parent_wrapper, orig_wrapper, 11393 LiveEdit::ReplaceRefToNestedFunction(parent_wrapper, orig_wrapper,
10905 subst_wrapper); 11394 subst_wrapper);
10906 11395
10907 return Heap::undefined_value(); 11396 return isolate->heap()->undefined_value();
10908 } 11397 }
10909 11398
10910 11399
10911 // Updates positions of a shared function info (first parameter) according 11400 // Updates positions of a shared function info (first parameter) according
10912 // to script source change. Text change is described in second parameter as 11401 // to script source change. Text change is described in second parameter as
10913 // array of groups of 3 numbers: 11402 // array of groups of 3 numbers:
10914 // (change_begin, change_end, change_end_new_position). 11403 // (change_begin, change_end, change_end_new_position).
10915 // Each group describes a change in text; groups are sorted by change_begin. 11404 // Each group describes a change in text; groups are sorted by change_begin.
10916 static MaybeObject* Runtime_LiveEditPatchFunctionPositions(Arguments args) { 11405 static MaybeObject* Runtime_LiveEditPatchFunctionPositions(
11406 RUNTIME_CALLING_CONVENTION) {
11407 RUNTIME_GET_ISOLATE;
10917 ASSERT(args.length() == 2); 11408 ASSERT(args.length() == 2);
10918 HandleScope scope; 11409 HandleScope scope(isolate);
10919 CONVERT_ARG_CHECKED(JSArray, shared_array, 0); 11410 CONVERT_ARG_CHECKED(JSArray, shared_array, 0);
10920 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1); 11411 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1);
10921 11412
10922 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array); 11413 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array);
10923 } 11414 }
10924 11415
10925 11416
10926 // For array of SharedFunctionInfo's (each wrapped in JSValue) 11417 // For array of SharedFunctionInfo's (each wrapped in JSValue)
10927 // checks that none of them have activations on stacks (of any thread). 11418 // checks that none of them have activations on stacks (of any thread).
10928 // Returns array of the same length with corresponding results of 11419 // Returns array of the same length with corresponding results of
10929 // LiveEdit::FunctionPatchabilityStatus type. 11420 // LiveEdit::FunctionPatchabilityStatus type.
10930 static MaybeObject* Runtime_LiveEditCheckAndDropActivations(Arguments args) { 11421 static MaybeObject* Runtime_LiveEditCheckAndDropActivations(
11422 RUNTIME_CALLING_CONVENTION) {
11423 RUNTIME_GET_ISOLATE;
10931 ASSERT(args.length() == 2); 11424 ASSERT(args.length() == 2);
10932 HandleScope scope; 11425 HandleScope scope(isolate);
10933 CONVERT_ARG_CHECKED(JSArray, shared_array, 0); 11426 CONVERT_ARG_CHECKED(JSArray, shared_array, 0);
10934 CONVERT_BOOLEAN_CHECKED(do_drop, args[1]); 11427 CONVERT_BOOLEAN_CHECKED(do_drop, args[1]);
10935 11428
10936 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop); 11429 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop);
10937 } 11430 }
10938 11431
10939 // Compares 2 strings line-by-line, then token-wise and returns diff in form 11432 // Compares 2 strings line-by-line, then token-wise and returns diff in form
10940 // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list 11433 // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list
10941 // of diff chunks. 11434 // of diff chunks.
10942 static MaybeObject* Runtime_LiveEditCompareStrings(Arguments args) { 11435 static MaybeObject* Runtime_LiveEditCompareStrings(RUNTIME_CALLING_CONVENTION) {
11436 RUNTIME_GET_ISOLATE;
10943 ASSERT(args.length() == 2); 11437 ASSERT(args.length() == 2);
10944 HandleScope scope; 11438 HandleScope scope(isolate);
10945 CONVERT_ARG_CHECKED(String, s1, 0); 11439 CONVERT_ARG_CHECKED(String, s1, 0);
10946 CONVERT_ARG_CHECKED(String, s2, 1); 11440 CONVERT_ARG_CHECKED(String, s2, 1);
10947 11441
10948 return *LiveEdit::CompareStrings(s1, s2); 11442 return *LiveEdit::CompareStrings(s1, s2);
10949 } 11443 }
10950 11444
10951 11445
10952
10953 // A testing entry. Returns statement position which is the closest to 11446 // A testing entry. Returns statement position which is the closest to
10954 // source_position. 11447 // source_position.
10955 static MaybeObject* Runtime_GetFunctionCodePositionFromSource(Arguments args) { 11448 static MaybeObject* Runtime_GetFunctionCodePositionFromSource(
11449 RUNTIME_CALLING_CONVENTION) {
11450 RUNTIME_GET_ISOLATE;
10956 ASSERT(args.length() == 2); 11451 ASSERT(args.length() == 2);
10957 HandleScope scope; 11452 HandleScope scope(isolate);
10958 CONVERT_ARG_CHECKED(JSFunction, function, 0); 11453 CONVERT_ARG_CHECKED(JSFunction, function, 0);
10959 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 11454 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
10960 11455
10961 Handle<Code> code(function->code()); 11456 Handle<Code> code(function->code(), isolate);
10962 11457
10963 if (code->kind() != Code::FUNCTION && 11458 if (code->kind() != Code::FUNCTION &&
10964 code->kind() != Code::OPTIMIZED_FUNCTION) { 11459 code->kind() != Code::OPTIMIZED_FUNCTION) {
10965 return Heap::undefined_value(); 11460 return isolate->heap()->undefined_value();
10966 } 11461 }
10967 11462
10968 RelocIterator it(*code, RelocInfo::ModeMask(RelocInfo::STATEMENT_POSITION)); 11463 RelocIterator it(*code, RelocInfo::ModeMask(RelocInfo::STATEMENT_POSITION));
10969 int closest_pc = 0; 11464 int closest_pc = 0;
10970 int distance = kMaxInt; 11465 int distance = kMaxInt;
10971 while (!it.done()) { 11466 while (!it.done()) {
10972 int statement_position = static_cast<int>(it.rinfo()->data()); 11467 int statement_position = static_cast<int>(it.rinfo()->data());
10973 // Check if this break point is closer that what was previously found. 11468 // Check if this break point is closer that what was previously found.
10974 if (source_position <= statement_position && 11469 if (source_position <= statement_position &&
10975 statement_position - source_position < distance) { 11470 statement_position - source_position < distance) {
10976 closest_pc = 11471 closest_pc =
10977 static_cast<int>(it.rinfo()->pc() - code->instruction_start()); 11472 static_cast<int>(it.rinfo()->pc() - code->instruction_start());
10978 distance = statement_position - source_position; 11473 distance = statement_position - source_position;
10979 // Check whether we can't get any closer. 11474 // Check whether we can't get any closer.
10980 if (distance == 0) break; 11475 if (distance == 0) break;
10981 } 11476 }
10982 it.next(); 11477 it.next();
10983 } 11478 }
10984 11479
10985 return Smi::FromInt(closest_pc); 11480 return Smi::FromInt(closest_pc);
10986 } 11481 }
10987 11482
10988 11483
10989 // Calls specified function with or without entering the debugger. 11484 // Calls specified function with or without entering the debugger.
10990 // This is used in unit tests to run code as if debugger is entered or simply 11485 // This is used in unit tests to run code as if debugger is entered or simply
10991 // to have a stack with C++ frame in the middle. 11486 // to have a stack with C++ frame in the middle.
10992 static MaybeObject* Runtime_ExecuteInDebugContext(Arguments args) { 11487 static MaybeObject* Runtime_ExecuteInDebugContext(RUNTIME_CALLING_CONVENTION) {
11488 RUNTIME_GET_ISOLATE;
10993 ASSERT(args.length() == 2); 11489 ASSERT(args.length() == 2);
10994 HandleScope scope; 11490 HandleScope scope(isolate);
10995 CONVERT_ARG_CHECKED(JSFunction, function, 0); 11491 CONVERT_ARG_CHECKED(JSFunction, function, 0);
10996 CONVERT_BOOLEAN_CHECKED(without_debugger, args[1]); 11492 CONVERT_BOOLEAN_CHECKED(without_debugger, args[1]);
10997 11493
10998 Handle<Object> result; 11494 Handle<Object> result;
10999 bool pending_exception; 11495 bool pending_exception;
11000 { 11496 {
11001 if (without_debugger) { 11497 if (without_debugger) {
11002 result = Execution::Call(function, Top::global(), 0, NULL, 11498 result = Execution::Call(function, isolate->global(), 0, NULL,
11003 &pending_exception); 11499 &pending_exception);
11004 } else { 11500 } else {
11005 EnterDebugger enter_debugger; 11501 EnterDebugger enter_debugger;
11006 result = Execution::Call(function, Top::global(), 0, NULL, 11502 result = Execution::Call(function, isolate->global(), 0, NULL,
11007 &pending_exception); 11503 &pending_exception);
11008 } 11504 }
11009 } 11505 }
11010 if (!pending_exception) { 11506 if (!pending_exception) {
11011 return *result; 11507 return *result;
11012 } else { 11508 } else {
11013 return Failure::Exception(); 11509 return Failure::Exception();
11014 } 11510 }
11015 } 11511 }
11016 11512
11017 11513
11018 // Sets a v8 flag. 11514 // Sets a v8 flag.
11019 static MaybeObject* Runtime_SetFlags(Arguments args) { 11515 static MaybeObject* Runtime_SetFlags(RUNTIME_CALLING_CONVENTION) {
11516 RUNTIME_GET_ISOLATE;
11020 CONVERT_CHECKED(String, arg, args[0]); 11517 CONVERT_CHECKED(String, arg, args[0]);
11021 SmartPointer<char> flags = 11518 SmartPointer<char> flags =
11022 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 11519 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
11023 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); 11520 FlagList::SetFlagsFromString(*flags, StrLength(*flags));
11024 return Heap::undefined_value(); 11521 return isolate->heap()->undefined_value();
11025 } 11522 }
11026 11523
11027 11524
11028 // Performs a GC. 11525 // Performs a GC.
11029 // Presently, it only does a full GC. 11526 // Presently, it only does a full GC.
11030 static MaybeObject* Runtime_CollectGarbage(Arguments args) { 11527 static MaybeObject* Runtime_CollectGarbage(RUNTIME_CALLING_CONVENTION) {
11031 Heap::CollectAllGarbage(Heap::kForceCompactionMask); 11528 RUNTIME_GET_ISOLATE;
11032 return Heap::undefined_value(); 11529 isolate->heap()->CollectAllGarbage(true);
11530 return isolate->heap()->undefined_value();
11033 } 11531 }
11034 11532
11035 11533
11036 // Gets the current heap usage. 11534 // Gets the current heap usage.
11037 static MaybeObject* Runtime_GetHeapUsage(Arguments args) { 11535 static MaybeObject* Runtime_GetHeapUsage(RUNTIME_CALLING_CONVENTION) {
11038 int usage = static_cast<int>(Heap::SizeOfObjects()); 11536 RUNTIME_GET_ISOLATE;
11537 int usage = static_cast<int>(isolate->heap()->SizeOfObjects());
11039 if (!Smi::IsValid(usage)) { 11538 if (!Smi::IsValid(usage)) {
11040 return *Factory::NewNumberFromInt(usage); 11539 return *isolate->factory()->NewNumberFromInt(usage);
11041 } 11540 }
11042 return Smi::FromInt(usage); 11541 return Smi::FromInt(usage);
11043 } 11542 }
11044 11543
11045 11544
11046 // Captures a live object list from the present heap. 11545 // Captures a live object list from the present heap.
11047 static MaybeObject* Runtime_HasLOLEnabled(Arguments args) { 11546 static MaybeObject* Runtime_HasLOLEnabled(RUNTIME_CALLING_CONVENTION) {
11547 RUNTIME_GET_ISOLATE;
11048 #ifdef LIVE_OBJECT_LIST 11548 #ifdef LIVE_OBJECT_LIST
11049 return Heap::true_value(); 11549 return isolate->heap()->true_value();
11050 #else 11550 #else
11051 return Heap::false_value(); 11551 return isolate->heap()->false_value();
11052 #endif 11552 #endif
11053 } 11553 }
11054 11554
11055 11555
11056 // Captures a live object list from the present heap. 11556 // Captures a live object list from the present heap.
11057 static MaybeObject* Runtime_CaptureLOL(Arguments args) { 11557 static MaybeObject* Runtime_CaptureLOL(RUNTIME_CALLING_CONVENTION) {
11558 RUNTIME_GET_ISOLATE;
11058 #ifdef LIVE_OBJECT_LIST 11559 #ifdef LIVE_OBJECT_LIST
11059 return LiveObjectList::Capture(); 11560 return LiveObjectList::Capture();
11060 #else 11561 #else
11061 return Heap::undefined_value(); 11562 return isolate->heap()->undefined_value();
11062 #endif 11563 #endif
11063 } 11564 }
11064 11565
11065 11566
11066 // Deletes the specified live object list. 11567 // Deletes the specified live object list.
11067 static MaybeObject* Runtime_DeleteLOL(Arguments args) { 11568 static MaybeObject* Runtime_DeleteLOL(RUNTIME_CALLING_CONVENTION) {
11569 RUNTIME_GET_ISOLATE;
11068 #ifdef LIVE_OBJECT_LIST 11570 #ifdef LIVE_OBJECT_LIST
11069 CONVERT_SMI_CHECKED(id, args[0]); 11571 CONVERT_SMI_CHECKED(id, args[0]);
11070 bool success = LiveObjectList::Delete(id); 11572 bool success = LiveObjectList::Delete(id);
11071 return success ? Heap::true_value() : Heap::false_value(); 11573 return success ? isolate->heap()->true_value() :
11574 isolate->heap()->false_value();
11072 #else 11575 #else
11073 return Heap::undefined_value(); 11576 return isolate->heap()->undefined_value();
11074 #endif 11577 #endif
11075 } 11578 }
11076 11579
11077 11580
11078 // Generates the response to a debugger request for a dump of the objects 11581 // Generates the response to a debugger request for a dump of the objects
11079 // contained in the difference between the captured live object lists 11582 // contained in the difference between the captured live object lists
11080 // specified by id1 and id2. 11583 // specified by id1 and id2.
11081 // If id1 is 0 (i.e. not a valid lol), then the whole of lol id2 will be 11584 // If id1 is 0 (i.e. not a valid lol), then the whole of lol id2 will be
11082 // dumped. 11585 // dumped.
11083 static MaybeObject* Runtime_DumpLOL(Arguments args) { 11586 static MaybeObject* Runtime_DumpLOL(RUNTIME_CALLING_CONVENTION) {
11587 RUNTIME_GET_ISOLATE;
11084 #ifdef LIVE_OBJECT_LIST 11588 #ifdef LIVE_OBJECT_LIST
11085 HandleScope scope; 11589 HandleScope scope;
11086 CONVERT_SMI_CHECKED(id1, args[0]); 11590 CONVERT_SMI_CHECKED(id1, args[0]);
11087 CONVERT_SMI_CHECKED(id2, args[1]); 11591 CONVERT_SMI_CHECKED(id2, args[1]);
11088 CONVERT_SMI_CHECKED(start, args[2]); 11592 CONVERT_SMI_CHECKED(start, args[2]);
11089 CONVERT_SMI_CHECKED(count, args[3]); 11593 CONVERT_SMI_CHECKED(count, args[3]);
11090 CONVERT_ARG_CHECKED(JSObject, filter_obj, 4); 11594 CONVERT_ARG_CHECKED(JSObject, filter_obj, 4);
11091 EnterDebugger enter_debugger; 11595 EnterDebugger enter_debugger;
11092 return LiveObjectList::Dump(id1, id2, start, count, filter_obj); 11596 return LiveObjectList::Dump(id1, id2, start, count, filter_obj);
11093 #else 11597 #else
11094 return Heap::undefined_value(); 11598 return isolate->heap()->undefined_value();
11095 #endif 11599 #endif
11096 } 11600 }
11097 11601
11098 11602
11099 // Gets the specified object as requested by the debugger. 11603 // Gets the specified object as requested by the debugger.
11100 // This is only used for obj ids shown in live object lists. 11604 // This is only used for obj ids shown in live object lists.
11101 static MaybeObject* Runtime_GetLOLObj(Arguments args) { 11605 static MaybeObject* Runtime_GetLOLObj(RUNTIME_CALLING_CONVENTION) {
11606 RUNTIME_GET_ISOLATE;
11102 #ifdef LIVE_OBJECT_LIST 11607 #ifdef LIVE_OBJECT_LIST
11103 CONVERT_SMI_CHECKED(obj_id, args[0]); 11608 CONVERT_SMI_CHECKED(obj_id, args[0]);
11104 Object* result = LiveObjectList::GetObj(obj_id); 11609 Object* result = LiveObjectList::GetObj(obj_id);
11105 return result; 11610 return result;
11106 #else 11611 #else
11107 return Heap::undefined_value(); 11612 return isolate->heap()->undefined_value();
11108 #endif 11613 #endif
11109 } 11614 }
11110 11615
11111 11616
11112 // Gets the obj id for the specified address if valid. 11617 // Gets the obj id for the specified address if valid.
11113 // This is only used for obj ids shown in live object lists. 11618 // This is only used for obj ids shown in live object lists.
11114 static MaybeObject* Runtime_GetLOLObjId(Arguments args) { 11619 static MaybeObject* Runtime_GetLOLObjId(RUNTIME_CALLING_CONVENTION) {
11620 RUNTIME_GET_ISOLATE;
11115 #ifdef LIVE_OBJECT_LIST 11621 #ifdef LIVE_OBJECT_LIST
11116 HandleScope scope; 11622 HandleScope scope;
11117 CONVERT_ARG_CHECKED(String, address, 0); 11623 CONVERT_ARG_CHECKED(String, address, 0);
11118 Object* result = LiveObjectList::GetObjId(address); 11624 Object* result = LiveObjectList::GetObjId(address);
11119 return result; 11625 return result;
11120 #else 11626 #else
11121 return Heap::undefined_value(); 11627 return isolate->heap()->undefined_value();
11122 #endif 11628 #endif
11123 } 11629 }
11124 11630
11125 11631
11126 // Gets the retainers that references the specified object alive. 11632 // Gets the retainers that references the specified object alive.
11127 static MaybeObject* Runtime_GetLOLObjRetainers(Arguments args) { 11633 static MaybeObject* Runtime_GetLOLObjRetainers(RUNTIME_CALLING_CONVENTION) {
11634 RUNTIME_GET_ISOLATE;
11128 #ifdef LIVE_OBJECT_LIST 11635 #ifdef LIVE_OBJECT_LIST
11129 HandleScope scope; 11636 HandleScope scope;
11130 CONVERT_SMI_CHECKED(obj_id, args[0]); 11637 CONVERT_SMI_CHECKED(obj_id, args[0]);
11131 RUNTIME_ASSERT(args[1]->IsUndefined() || args[1]->IsJSObject()); 11638 RUNTIME_ASSERT(args[1]->IsUndefined() || args[1]->IsJSObject());
11132 RUNTIME_ASSERT(args[2]->IsUndefined() || args[2]->IsBoolean()); 11639 RUNTIME_ASSERT(args[2]->IsUndefined() || args[2]->IsBoolean());
11133 RUNTIME_ASSERT(args[3]->IsUndefined() || args[3]->IsSmi()); 11640 RUNTIME_ASSERT(args[3]->IsUndefined() || args[3]->IsSmi());
11134 RUNTIME_ASSERT(args[4]->IsUndefined() || args[4]->IsSmi()); 11641 RUNTIME_ASSERT(args[4]->IsUndefined() || args[4]->IsSmi());
11135 CONVERT_ARG_CHECKED(JSObject, filter_obj, 5); 11642 CONVERT_ARG_CHECKED(JSObject, filter_obj, 5);
11136 11643
11137 Handle<JSObject> instance_filter; 11644 Handle<JSObject> instance_filter;
(...skipping 13 matching lines...) Expand all
11151 limit = Smi::cast(args[4])->value(); 11658 limit = Smi::cast(args[4])->value();
11152 } 11659 }
11153 11660
11154 return LiveObjectList::GetObjRetainers(obj_id, 11661 return LiveObjectList::GetObjRetainers(obj_id,
11155 instance_filter, 11662 instance_filter,
11156 verbose, 11663 verbose,
11157 start, 11664 start,
11158 limit, 11665 limit,
11159 filter_obj); 11666 filter_obj);
11160 #else 11667 #else
11161 return Heap::undefined_value(); 11668 return isolate->heap()->undefined_value();
11162 #endif 11669 #endif
11163 } 11670 }
11164 11671
11165 11672
11166 // Gets the reference path between 2 objects. 11673 // Gets the reference path between 2 objects.
11167 static MaybeObject* Runtime_GetLOLPath(Arguments args) { 11674 static MaybeObject* Runtime_GetLOLPath(RUNTIME_CALLING_CONVENTION) {
11675 RUNTIME_GET_ISOLATE;
11168 #ifdef LIVE_OBJECT_LIST 11676 #ifdef LIVE_OBJECT_LIST
11169 HandleScope scope; 11677 HandleScope scope;
11170 CONVERT_SMI_CHECKED(obj_id1, args[0]); 11678 CONVERT_SMI_CHECKED(obj_id1, args[0]);
11171 CONVERT_SMI_CHECKED(obj_id2, args[1]); 11679 CONVERT_SMI_CHECKED(obj_id2, args[1]);
11172 RUNTIME_ASSERT(args[2]->IsUndefined() || args[2]->IsJSObject()); 11680 RUNTIME_ASSERT(args[2]->IsUndefined() || args[2]->IsJSObject());
11173 11681
11174 Handle<JSObject> instance_filter; 11682 Handle<JSObject> instance_filter;
11175 if (args[2]->IsJSObject()) { 11683 if (args[2]->IsJSObject()) {
11176 instance_filter = args.at<JSObject>(2); 11684 instance_filter = args.at<JSObject>(2);
11177 } 11685 }
11178 11686
11179 Object* result = 11687 Object* result =
11180 LiveObjectList::GetPath(obj_id1, obj_id2, instance_filter); 11688 LiveObjectList::GetPath(obj_id1, obj_id2, instance_filter);
11181 return result; 11689 return result;
11182 #else 11690 #else
11183 return Heap::undefined_value(); 11691 return isolate->heap()->undefined_value();
11184 #endif 11692 #endif
11185 } 11693 }
11186 11694
11187 11695
11188 // Generates the response to a debugger request for a list of all 11696 // Generates the response to a debugger request for a list of all
11189 // previously captured live object lists. 11697 // previously captured live object lists.
11190 static MaybeObject* Runtime_InfoLOL(Arguments args) { 11698 static MaybeObject* Runtime_InfoLOL(RUNTIME_CALLING_CONVENTION) {
11699 RUNTIME_GET_ISOLATE;
11191 #ifdef LIVE_OBJECT_LIST 11700 #ifdef LIVE_OBJECT_LIST
11192 CONVERT_SMI_CHECKED(start, args[0]); 11701 CONVERT_SMI_CHECKED(start, args[0]);
11193 CONVERT_SMI_CHECKED(count, args[1]); 11702 CONVERT_SMI_CHECKED(count, args[1]);
11194 return LiveObjectList::Info(start, count); 11703 return LiveObjectList::Info(start, count);
11195 #else 11704 #else
11196 return Heap::undefined_value(); 11705 return isolate->heap()->undefined_value();
11197 #endif 11706 #endif
11198 } 11707 }
11199 11708
11200 11709
11201 // Gets a dump of the specified object as requested by the debugger. 11710 // Gets a dump of the specified object as requested by the debugger.
11202 // This is only used for obj ids shown in live object lists. 11711 // This is only used for obj ids shown in live object lists.
11203 static MaybeObject* Runtime_PrintLOLObj(Arguments args) { 11712 static MaybeObject* Runtime_PrintLOLObj(RUNTIME_CALLING_CONVENTION) {
11713 RUNTIME_GET_ISOLATE;
11204 #ifdef LIVE_OBJECT_LIST 11714 #ifdef LIVE_OBJECT_LIST
11205 HandleScope scope; 11715 HandleScope scope;
11206 CONVERT_SMI_CHECKED(obj_id, args[0]); 11716 CONVERT_SMI_CHECKED(obj_id, args[0]);
11207 Object* result = LiveObjectList::PrintObj(obj_id); 11717 Object* result = LiveObjectList::PrintObj(obj_id);
11208 return result; 11718 return result;
11209 #else 11719 #else
11210 return Heap::undefined_value(); 11720 return isolate->heap()->undefined_value();
11211 #endif 11721 #endif
11212 } 11722 }
11213 11723
11214 11724
11215 // Resets and releases all previously captured live object lists. 11725 // Resets and releases all previously captured live object lists.
11216 static MaybeObject* Runtime_ResetLOL(Arguments args) { 11726 static MaybeObject* Runtime_ResetLOL(RUNTIME_CALLING_CONVENTION) {
11727 RUNTIME_GET_ISOLATE;
11217 #ifdef LIVE_OBJECT_LIST 11728 #ifdef LIVE_OBJECT_LIST
11218 LiveObjectList::Reset(); 11729 LiveObjectList::Reset();
11219 return Heap::undefined_value(); 11730 return isolate->heap()->undefined_value();
11220 #else 11731 #else
11221 return Heap::undefined_value(); 11732 return isolate->heap()->undefined_value();
11222 #endif 11733 #endif
11223 } 11734 }
11224 11735
11225 11736
11226 // Generates the response to a debugger request for a summary of the types 11737 // Generates the response to a debugger request for a summary of the types
11227 // of objects in the difference between the captured live object lists 11738 // of objects in the difference between the captured live object lists
11228 // specified by id1 and id2. 11739 // specified by id1 and id2.
11229 // If id1 is 0 (i.e. not a valid lol), then the whole of lol id2 will be 11740 // If id1 is 0 (i.e. not a valid lol), then the whole of lol id2 will be
11230 // summarized. 11741 // summarized.
11231 static MaybeObject* Runtime_SummarizeLOL(Arguments args) { 11742 static MaybeObject* Runtime_SummarizeLOL(RUNTIME_CALLING_CONVENTION) {
11743 RUNTIME_GET_ISOLATE;
11232 #ifdef LIVE_OBJECT_LIST 11744 #ifdef LIVE_OBJECT_LIST
11233 HandleScope scope; 11745 HandleScope scope;
11234 CONVERT_SMI_CHECKED(id1, args[0]); 11746 CONVERT_SMI_CHECKED(id1, args[0]);
11235 CONVERT_SMI_CHECKED(id2, args[1]); 11747 CONVERT_SMI_CHECKED(id2, args[1]);
11236 CONVERT_ARG_CHECKED(JSObject, filter_obj, 2); 11748 CONVERT_ARG_CHECKED(JSObject, filter_obj, 2);
11237 11749
11238 EnterDebugger enter_debugger; 11750 EnterDebugger enter_debugger;
11239 return LiveObjectList::Summarize(id1, id2, filter_obj); 11751 return LiveObjectList::Summarize(id1, id2, filter_obj);
11240 #else 11752 #else
11241 return Heap::undefined_value(); 11753 return isolate->heap()->undefined_value();
11242 #endif 11754 #endif
11243 } 11755 }
11244 11756
11245 #endif // ENABLE_DEBUGGER_SUPPORT 11757 #endif // ENABLE_DEBUGGER_SUPPORT
11246 11758
11247 11759
11248 #ifdef ENABLE_LOGGING_AND_PROFILING 11760 #ifdef ENABLE_LOGGING_AND_PROFILING
11249 static MaybeObject* Runtime_ProfilerResume(Arguments args) { 11761 static MaybeObject* Runtime_ProfilerResume(RUNTIME_CALLING_CONVENTION) {
11762 RUNTIME_GET_ISOLATE;
11250 NoHandleAllocation ha; 11763 NoHandleAllocation ha;
11251 ASSERT(args.length() == 2); 11764 ASSERT(args.length() == 2);
11252 11765
11253 CONVERT_CHECKED(Smi, smi_modules, args[0]); 11766 CONVERT_CHECKED(Smi, smi_modules, args[0]);
11254 CONVERT_CHECKED(Smi, smi_tag, args[1]); 11767 CONVERT_CHECKED(Smi, smi_tag, args[1]);
11255 v8::V8::ResumeProfilerEx(smi_modules->value(), smi_tag->value()); 11768 v8::V8::ResumeProfilerEx(smi_modules->value(), smi_tag->value());
11256 return Heap::undefined_value(); 11769 return isolate->heap()->undefined_value();
11257 } 11770 }
11258 11771
11259 11772
11260 static MaybeObject* Runtime_ProfilerPause(Arguments args) { 11773 static MaybeObject* Runtime_ProfilerPause(RUNTIME_CALLING_CONVENTION) {
11774 RUNTIME_GET_ISOLATE;
11261 NoHandleAllocation ha; 11775 NoHandleAllocation ha;
11262 ASSERT(args.length() == 2); 11776 ASSERT(args.length() == 2);
11263 11777
11264 CONVERT_CHECKED(Smi, smi_modules, args[0]); 11778 CONVERT_CHECKED(Smi, smi_modules, args[0]);
11265 CONVERT_CHECKED(Smi, smi_tag, args[1]); 11779 CONVERT_CHECKED(Smi, smi_tag, args[1]);
11266 v8::V8::PauseProfilerEx(smi_modules->value(), smi_tag->value()); 11780 v8::V8::PauseProfilerEx(smi_modules->value(), smi_tag->value());
11267 return Heap::undefined_value(); 11781 return isolate->heap()->undefined_value();
11268 } 11782 }
11269 11783
11270 #endif // ENABLE_LOGGING_AND_PROFILING 11784 #endif // ENABLE_LOGGING_AND_PROFILING
11271 11785
11272 // Finds the script object from the script data. NOTE: This operation uses 11786 // Finds the script object from the script data. NOTE: This operation uses
11273 // heap traversal to find the function generated for the source position 11787 // heap traversal to find the function generated for the source position
11274 // for the requested break point. For lazily compiled functions several heap 11788 // for the requested break point. For lazily compiled functions several heap
11275 // traversals might be required rendering this operation as a rather slow 11789 // traversals might be required rendering this operation as a rather slow
11276 // operation. However for setting break points which is normally done through 11790 // operation. However for setting break points which is normally done through
11277 // some kind of user interaction the performance is not crucial. 11791 // some kind of user interaction the performance is not crucial.
(...skipping 10 matching lines...) Expand all
11288 if (obj->IsScript()) { 11802 if (obj->IsScript()) {
11289 if (Script::cast(obj)->name()->IsString()) { 11803 if (Script::cast(obj)->name()->IsString()) {
11290 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { 11804 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) {
11291 script = Handle<Script>(Script::cast(obj)); 11805 script = Handle<Script>(Script::cast(obj));
11292 } 11806 }
11293 } 11807 }
11294 } 11808 }
11295 } 11809 }
11296 11810
11297 // If no script with the requested script data is found return undefined. 11811 // If no script with the requested script data is found return undefined.
11298 if (script.is_null()) return Factory::undefined_value(); 11812 if (script.is_null()) return FACTORY->undefined_value();
11299 11813
11300 // Return the script found. 11814 // Return the script found.
11301 return GetScriptWrapper(script); 11815 return GetScriptWrapper(script);
11302 } 11816 }
11303 11817
11304 11818
11305 // Get the script object from script data. NOTE: Regarding performance 11819 // Get the script object from script data. NOTE: Regarding performance
11306 // see the NOTE for GetScriptFromScriptData. 11820 // see the NOTE for GetScriptFromScriptData.
11307 // args[0]: script data for the script to find the source for 11821 // args[0]: script data for the script to find the source for
11308 static MaybeObject* Runtime_GetScript(Arguments args) { 11822 static MaybeObject* Runtime_GetScript(RUNTIME_CALLING_CONVENTION) {
11309 HandleScope scope; 11823 RUNTIME_GET_ISOLATE;
11824 HandleScope scope(isolate);
11310 11825
11311 ASSERT(args.length() == 1); 11826 ASSERT(args.length() == 1);
11312 11827
11313 CONVERT_CHECKED(String, script_name, args[0]); 11828 CONVERT_CHECKED(String, script_name, args[0]);
11314 11829
11315 // Find the requested script. 11830 // Find the requested script.
11316 Handle<Object> result = 11831 Handle<Object> result =
11317 Runtime_GetScriptFromScriptName(Handle<String>(script_name)); 11832 Runtime_GetScriptFromScriptName(Handle<String>(script_name));
11318 return *result; 11833 return *result;
11319 } 11834 }
(...skipping 23 matching lines...) Expand all
11343 // obvious builtin calls. Some builtin calls (such as Number.ADD 11858 // obvious builtin calls. Some builtin calls (such as Number.ADD
11344 // which is invoked using 'call') are very difficult to recognize 11859 // which is invoked using 'call') are very difficult to recognize
11345 // so we're leaving them in for now. 11860 // so we're leaving them in for now.
11346 return *seen_caller && !frame->receiver()->IsJSBuiltinsObject(); 11861 return *seen_caller && !frame->receiver()->IsJSBuiltinsObject();
11347 } 11862 }
11348 11863
11349 11864
11350 // Collect the raw data for a stack trace. Returns an array of 4 11865 // Collect the raw data for a stack trace. Returns an array of 4
11351 // element segments each containing a receiver, function, code and 11866 // element segments each containing a receiver, function, code and
11352 // native code offset. 11867 // native code offset.
11353 static MaybeObject* Runtime_CollectStackTrace(Arguments args) { 11868 static MaybeObject* Runtime_CollectStackTrace(RUNTIME_CALLING_CONVENTION) {
11869 RUNTIME_GET_ISOLATE;
11354 ASSERT_EQ(args.length(), 2); 11870 ASSERT_EQ(args.length(), 2);
11355 Handle<Object> caller = args.at<Object>(0); 11871 Handle<Object> caller = args.at<Object>(0);
11356 CONVERT_NUMBER_CHECKED(int32_t, limit, Int32, args[1]); 11872 CONVERT_NUMBER_CHECKED(int32_t, limit, Int32, args[1]);
11357 11873
11358 HandleScope scope; 11874 HandleScope scope(isolate);
11875 Factory* factory = isolate->factory();
11359 11876
11360 limit = Max(limit, 0); // Ensure that limit is not negative. 11877 limit = Max(limit, 0); // Ensure that limit is not negative.
11361 int initial_size = Min(limit, 10); 11878 int initial_size = Min(limit, 10);
11362 Handle<FixedArray> elements = 11879 Handle<FixedArray> elements =
11363 Factory::NewFixedArrayWithHoles(initial_size * 4); 11880 factory->NewFixedArrayWithHoles(initial_size * 4);
11364 11881
11365 StackFrameIterator iter; 11882 StackFrameIterator iter;
11366 // If the caller parameter is a function we skip frames until we're 11883 // If the caller parameter is a function we skip frames until we're
11367 // under it before starting to collect. 11884 // under it before starting to collect.
11368 bool seen_caller = !caller->IsJSFunction(); 11885 bool seen_caller = !caller->IsJSFunction();
11369 int cursor = 0; 11886 int cursor = 0;
11370 int frames_seen = 0; 11887 int frames_seen = 0;
11371 while (!iter.done() && frames_seen < limit) { 11888 while (!iter.done() && frames_seen < limit) {
11372 StackFrame* raw_frame = iter.frame(); 11889 StackFrame* raw_frame = iter.frame();
11373 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) { 11890 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) {
11374 frames_seen++; 11891 frames_seen++;
11375 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); 11892 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame);
11376 List<FrameSummary> frames(3); // Max 2 levels of inlining. 11893 List<FrameSummary> frames(3); // Max 2 levels of inlining.
11377 frame->Summarize(&frames); 11894 frame->Summarize(&frames);
11378 for (int i = frames.length() - 1; i >= 0; i--) { 11895 for (int i = frames.length() - 1; i >= 0; i--) {
11379 if (cursor + 4 > elements->length()) { 11896 if (cursor + 4 > elements->length()) {
11380 int new_capacity = JSObject::NewElementsCapacity(elements->length()); 11897 int new_capacity = JSObject::NewElementsCapacity(elements->length());
11381 Handle<FixedArray> new_elements = 11898 Handle<FixedArray> new_elements =
11382 Factory::NewFixedArrayWithHoles(new_capacity); 11899 factory->NewFixedArrayWithHoles(new_capacity);
11383 for (int i = 0; i < cursor; i++) { 11900 for (int i = 0; i < cursor; i++) {
11384 new_elements->set(i, elements->get(i)); 11901 new_elements->set(i, elements->get(i));
11385 } 11902 }
11386 elements = new_elements; 11903 elements = new_elements;
11387 } 11904 }
11388 ASSERT(cursor + 4 <= elements->length()); 11905 ASSERT(cursor + 4 <= elements->length());
11389 11906
11390 Handle<Object> recv = frames[i].receiver(); 11907 Handle<Object> recv = frames[i].receiver();
11391 Handle<JSFunction> fun = frames[i].function(); 11908 Handle<JSFunction> fun = frames[i].function();
11392 Handle<Code> code = frames[i].code(); 11909 Handle<Code> code = frames[i].code();
11393 Handle<Smi> offset(Smi::FromInt(frames[i].offset())); 11910 Handle<Smi> offset(Smi::FromInt(frames[i].offset()));
11394 elements->set(cursor++, *recv); 11911 elements->set(cursor++, *recv);
11395 elements->set(cursor++, *fun); 11912 elements->set(cursor++, *fun);
11396 elements->set(cursor++, *code); 11913 elements->set(cursor++, *code);
11397 elements->set(cursor++, *offset); 11914 elements->set(cursor++, *offset);
11398 } 11915 }
11399 } 11916 }
11400 iter.Advance(); 11917 iter.Advance();
11401 } 11918 }
11402 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); 11919 Handle<JSArray> result = factory->NewJSArrayWithElements(elements);
11403 result->set_length(Smi::FromInt(cursor)); 11920 result->set_length(Smi::FromInt(cursor));
11404 return *result; 11921 return *result;
11405 } 11922 }
11406 11923
11407 11924
11408 // Returns V8 version as a string. 11925 // Returns V8 version as a string.
11409 static MaybeObject* Runtime_GetV8Version(Arguments args) { 11926 static MaybeObject* Runtime_GetV8Version(RUNTIME_CALLING_CONVENTION) {
11927 RUNTIME_GET_ISOLATE;
11410 ASSERT_EQ(args.length(), 0); 11928 ASSERT_EQ(args.length(), 0);
11411 11929
11412 NoHandleAllocation ha; 11930 NoHandleAllocation ha;
11413 11931
11414 const char* version_string = v8::V8::GetVersion(); 11932 const char* version_string = v8::V8::GetVersion();
11415 11933
11416 return Heap::AllocateStringFromAscii(CStrVector(version_string), NOT_TENURED); 11934 return isolate->heap()->AllocateStringFromAscii(CStrVector(version_string),
11935 NOT_TENURED);
11417 } 11936 }
11418 11937
11419 11938
11420 static MaybeObject* Runtime_Abort(Arguments args) { 11939 static MaybeObject* Runtime_Abort(RUNTIME_CALLING_CONVENTION) {
11940 RUNTIME_GET_ISOLATE;
11421 ASSERT(args.length() == 2); 11941 ASSERT(args.length() == 2);
11422 OS::PrintError("abort: %s\n", reinterpret_cast<char*>(args[0]) + 11942 OS::PrintError("abort: %s\n", reinterpret_cast<char*>(args[0]) +
11423 Smi::cast(args[1])->value()); 11943 Smi::cast(args[1])->value());
11424 Top::PrintStack(); 11944 isolate->PrintStack();
11425 OS::Abort(); 11945 OS::Abort();
11426 UNREACHABLE(); 11946 UNREACHABLE();
11427 return NULL; 11947 return NULL;
11428 } 11948 }
11429 11949
11430 11950
11431 static MaybeObject* Runtime_GetFromCache(Arguments args) { 11951 static MaybeObject* Runtime_GetFromCache(RUNTIME_CALLING_CONVENTION) {
11952 RUNTIME_GET_ISOLATE;
11432 // This is only called from codegen, so checks might be more lax. 11953 // This is only called from codegen, so checks might be more lax.
11433 CONVERT_CHECKED(JSFunctionResultCache, cache, args[0]); 11954 CONVERT_CHECKED(JSFunctionResultCache, cache, args[0]);
11434 Object* key = args[1]; 11955 Object* key = args[1];
11435 11956
11436 int finger_index = cache->finger_index(); 11957 int finger_index = cache->finger_index();
11437 Object* o = cache->get(finger_index); 11958 Object* o = cache->get(finger_index);
11438 if (o == key) { 11959 if (o == key) {
11439 // The fastest case: hit the same place again. 11960 // The fastest case: hit the same place again.
11440 return cache->get(finger_index + 1); 11961 return cache->get(finger_index + 1);
11441 } 11962 }
(...skipping 13 matching lines...) Expand all
11455 11976
11456 for (int i = size - 2; i > finger_index; i -= 2) { 11977 for (int i = size - 2; i > finger_index; i -= 2) {
11457 o = cache->get(i); 11978 o = cache->get(i);
11458 if (o == key) { 11979 if (o == key) {
11459 cache->set_finger_index(i); 11980 cache->set_finger_index(i);
11460 return cache->get(i + 1); 11981 return cache->get(i + 1);
11461 } 11982 }
11462 } 11983 }
11463 11984
11464 // There is no value in the cache. Invoke the function and cache result. 11985 // There is no value in the cache. Invoke the function and cache result.
11465 HandleScope scope; 11986 HandleScope scope(isolate);
11466 11987
11467 Handle<JSFunctionResultCache> cache_handle(cache); 11988 Handle<JSFunctionResultCache> cache_handle(cache);
11468 Handle<Object> key_handle(key); 11989 Handle<Object> key_handle(key);
11469 Handle<Object> value; 11990 Handle<Object> value;
11470 { 11991 {
11471 Handle<JSFunction> factory(JSFunction::cast( 11992 Handle<JSFunction> factory(JSFunction::cast(
11472 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); 11993 cache_handle->get(JSFunctionResultCache::kFactoryIndex)));
11473 // TODO(antonm): consider passing a receiver when constructing a cache. 11994 // TODO(antonm): consider passing a receiver when constructing a cache.
11474 Handle<Object> receiver(Top::global_context()->global()); 11995 Handle<Object> receiver(isolate->global_context()->global());
11475 // This handle is nor shared, nor used later, so it's safe. 11996 // This handle is nor shared, nor used later, so it's safe.
11476 Object** argv[] = { key_handle.location() }; 11997 Object** argv[] = { key_handle.location() };
11477 bool pending_exception = false; 11998 bool pending_exception = false;
11478 value = Execution::Call(factory, 11999 value = Execution::Call(factory,
11479 receiver, 12000 receiver,
11480 1, 12001 1,
11481 argv, 12002 argv,
11482 &pending_exception); 12003 &pending_exception);
11483 if (pending_exception) return Failure::Exception(); 12004 if (pending_exception) return Failure::Exception();
11484 } 12005 }
(...skipping 28 matching lines...) Expand all
11513 cache_handle->set_finger_index(index); 12034 cache_handle->set_finger_index(index);
11514 12035
11515 #ifdef DEBUG 12036 #ifdef DEBUG
11516 cache_handle->JSFunctionResultCacheVerify(); 12037 cache_handle->JSFunctionResultCacheVerify();
11517 #endif 12038 #endif
11518 12039
11519 return *value; 12040 return *value;
11520 } 12041 }
11521 12042
11522 12043
11523 static MaybeObject* Runtime_NewMessageObject(Arguments args) { 12044 static MaybeObject* Runtime_NewMessageObject(RUNTIME_CALLING_CONVENTION) {
11524 HandleScope scope; 12045 RUNTIME_GET_ISOLATE;
12046 HandleScope scope(isolate);
11525 CONVERT_ARG_CHECKED(String, type, 0); 12047 CONVERT_ARG_CHECKED(String, type, 0);
11526 CONVERT_ARG_CHECKED(JSArray, arguments, 1); 12048 CONVERT_ARG_CHECKED(JSArray, arguments, 1);
11527 return *Factory::NewJSMessageObject(type, 12049 return *isolate->factory()->NewJSMessageObject(
11528 arguments, 12050 type,
11529 0, 12051 arguments,
11530 0, 12052 0,
11531 Factory::undefined_value(), 12053 0,
11532 Factory::undefined_value(), 12054 isolate->factory()->undefined_value(),
11533 Factory::undefined_value()); 12055 isolate->factory()->undefined_value(),
12056 isolate->factory()->undefined_value());
11534 } 12057 }
11535 12058
11536 12059
11537 static MaybeObject* Runtime_MessageGetType(Arguments args) { 12060 static MaybeObject* Runtime_MessageGetType(RUNTIME_CALLING_CONVENTION) {
12061 RUNTIME_GET_ISOLATE;
11538 CONVERT_CHECKED(JSMessageObject, message, args[0]); 12062 CONVERT_CHECKED(JSMessageObject, message, args[0]);
11539 return message->type(); 12063 return message->type();
11540 } 12064 }
11541 12065
11542 12066
11543 static MaybeObject* Runtime_MessageGetArguments(Arguments args) { 12067 static MaybeObject* Runtime_MessageGetArguments(RUNTIME_CALLING_CONVENTION) {
12068 RUNTIME_GET_ISOLATE;
11544 CONVERT_CHECKED(JSMessageObject, message, args[0]); 12069 CONVERT_CHECKED(JSMessageObject, message, args[0]);
11545 return message->arguments(); 12070 return message->arguments();
11546 } 12071 }
11547 12072
11548 12073
11549 static MaybeObject* Runtime_MessageGetStartPosition(Arguments args) { 12074 static MaybeObject* Runtime_MessageGetStartPosition(
12075 RUNTIME_CALLING_CONVENTION) {
12076 RUNTIME_GET_ISOLATE;
11550 CONVERT_CHECKED(JSMessageObject, message, args[0]); 12077 CONVERT_CHECKED(JSMessageObject, message, args[0]);
11551 return Smi::FromInt(message->start_position()); 12078 return Smi::FromInt(message->start_position());
11552 } 12079 }
11553 12080
11554 12081
11555 static MaybeObject* Runtime_MessageGetScript(Arguments args) { 12082 static MaybeObject* Runtime_MessageGetScript(RUNTIME_CALLING_CONVENTION) {
12083 RUNTIME_GET_ISOLATE;
11556 CONVERT_CHECKED(JSMessageObject, message, args[0]); 12084 CONVERT_CHECKED(JSMessageObject, message, args[0]);
11557 return message->script(); 12085 return message->script();
11558 } 12086 }
11559 12087
11560 12088
11561 #ifdef DEBUG 12089 #ifdef DEBUG
11562 // ListNatives is ONLY used by the fuzz-natives.js in debug mode 12090 // ListNatives is ONLY used by the fuzz-natives.js in debug mode
11563 // Exclude the code in release mode. 12091 // Exclude the code in release mode.
11564 static MaybeObject* Runtime_ListNatives(Arguments args) { 12092 static MaybeObject* Runtime_ListNatives(RUNTIME_CALLING_CONVENTION) {
12093 RUNTIME_GET_ISOLATE;
11565 ASSERT(args.length() == 0); 12094 ASSERT(args.length() == 0);
11566 HandleScope scope; 12095 HandleScope scope;
11567 #define COUNT_ENTRY(Name, argc, ressize) + 1 12096 #define COUNT_ENTRY(Name, argc, ressize) + 1
11568 int entry_count = 0 12097 int entry_count = 0
11569 RUNTIME_FUNCTION_LIST(COUNT_ENTRY) 12098 RUNTIME_FUNCTION_LIST(COUNT_ENTRY)
11570 INLINE_FUNCTION_LIST(COUNT_ENTRY) 12099 INLINE_FUNCTION_LIST(COUNT_ENTRY)
11571 INLINE_RUNTIME_FUNCTION_LIST(COUNT_ENTRY); 12100 INLINE_RUNTIME_FUNCTION_LIST(COUNT_ENTRY);
11572 #undef COUNT_ENTRY 12101 #undef COUNT_ENTRY
11573 Handle<FixedArray> elements = Factory::NewFixedArray(entry_count); 12102 Factory* factory = isolate->factory();
12103 Handle<FixedArray> elements = factory->NewFixedArray(entry_count);
11574 int index = 0; 12104 int index = 0;
11575 bool inline_runtime_functions = false; 12105 bool inline_runtime_functions = false;
11576 #define ADD_ENTRY(Name, argc, ressize) \ 12106 #define ADD_ENTRY(Name, argc, ressize) \
11577 { \ 12107 { \
11578 HandleScope inner; \ 12108 HandleScope inner; \
11579 Handle<String> name; \ 12109 Handle<String> name; \
11580 /* Inline runtime functions have an underscore in front of the name. */ \ 12110 /* Inline runtime functions have an underscore in front of the name. */ \
11581 if (inline_runtime_functions) { \ 12111 if (inline_runtime_functions) { \
11582 name = Factory::NewStringFromAscii( \ 12112 name = factory->NewStringFromAscii( \
11583 Vector<const char>("_" #Name, StrLength("_" #Name))); \ 12113 Vector<const char>("_" #Name, StrLength("_" #Name))); \
11584 } else { \ 12114 } else { \
11585 name = Factory::NewStringFromAscii( \ 12115 name = factory->NewStringFromAscii( \
11586 Vector<const char>(#Name, StrLength(#Name))); \ 12116 Vector<const char>(#Name, StrLength(#Name))); \
11587 } \ 12117 } \
11588 Handle<FixedArray> pair_elements = Factory::NewFixedArray(2); \ 12118 Handle<FixedArray> pair_elements = factory->NewFixedArray(2); \
11589 pair_elements->set(0, *name); \ 12119 pair_elements->set(0, *name); \
11590 pair_elements->set(1, Smi::FromInt(argc)); \ 12120 pair_elements->set(1, Smi::FromInt(argc)); \
11591 Handle<JSArray> pair = Factory::NewJSArrayWithElements(pair_elements); \ 12121 Handle<JSArray> pair = factory->NewJSArrayWithElements(pair_elements); \
11592 elements->set(index++, *pair); \ 12122 elements->set(index++, *pair); \
11593 } 12123 }
11594 inline_runtime_functions = false; 12124 inline_runtime_functions = false;
11595 RUNTIME_FUNCTION_LIST(ADD_ENTRY) 12125 RUNTIME_FUNCTION_LIST(ADD_ENTRY)
11596 inline_runtime_functions = true; 12126 inline_runtime_functions = true;
11597 INLINE_FUNCTION_LIST(ADD_ENTRY) 12127 INLINE_FUNCTION_LIST(ADD_ENTRY)
11598 INLINE_RUNTIME_FUNCTION_LIST(ADD_ENTRY) 12128 INLINE_RUNTIME_FUNCTION_LIST(ADD_ENTRY)
11599 #undef ADD_ENTRY 12129 #undef ADD_ENTRY
11600 ASSERT_EQ(index, entry_count); 12130 ASSERT_EQ(index, entry_count);
11601 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); 12131 Handle<JSArray> result = factory->NewJSArrayWithElements(elements);
11602 return *result; 12132 return *result;
11603 } 12133 }
11604 #endif 12134 #endif
11605 12135
11606 12136
11607 static MaybeObject* Runtime_Log(Arguments args) { 12137 static MaybeObject* Runtime_Log(RUNTIME_CALLING_CONVENTION) {
12138 RUNTIME_GET_ISOLATE;
11608 ASSERT(args.length() == 2); 12139 ASSERT(args.length() == 2);
11609 CONVERT_CHECKED(String, format, args[0]); 12140 CONVERT_CHECKED(String, format, args[0]);
11610 CONVERT_CHECKED(JSArray, elms, args[1]); 12141 CONVERT_CHECKED(JSArray, elms, args[1]);
11611 Vector<const char> chars = format->ToAsciiVector(); 12142 Vector<const char> chars = format->ToAsciiVector();
11612 Logger::LogRuntime(chars, elms); 12143 LOGGER->LogRuntime(chars, elms);
11613 return Heap::undefined_value(); 12144 return isolate->heap()->undefined_value();
11614 } 12145 }
11615 12146
11616 12147
11617 static MaybeObject* Runtime_IS_VAR(Arguments args) { 12148 static MaybeObject* Runtime_IS_VAR(RUNTIME_CALLING_CONVENTION) {
11618 UNREACHABLE(); // implemented as macro in the parser 12149 UNREACHABLE(); // implemented as macro in the parser
11619 return NULL; 12150 return NULL;
11620 } 12151 }
11621 12152
11622 12153
11623 // ---------------------------------------------------------------------------- 12154 // ----------------------------------------------------------------------------
11624 // Implementation of Runtime 12155 // Implementation of Runtime
11625 12156
11626 #define F(name, number_of_args, result_size) \ 12157 #define F(name, number_of_args, result_size) \
11627 { Runtime::k##name, Runtime::RUNTIME, #name, \ 12158 { Runtime::k##name, Runtime::RUNTIME, #name, \
11628 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, 12159 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size },
11629 12160
11630 12161
11631 #define I(name, number_of_args, result_size) \ 12162 #define I(name, number_of_args, result_size) \
11632 { Runtime::kInline##name, Runtime::INLINE, \ 12163 { Runtime::kInline##name, Runtime::INLINE, \
11633 "_" #name, NULL, number_of_args, result_size }, 12164 "_" #name, NULL, number_of_args, result_size },
11634 12165
11635 Runtime::Function kIntrinsicFunctions[] = { 12166 static const Runtime::Function kIntrinsicFunctions[] = {
11636 RUNTIME_FUNCTION_LIST(F) 12167 RUNTIME_FUNCTION_LIST(F)
11637 INLINE_FUNCTION_LIST(I) 12168 INLINE_FUNCTION_LIST(I)
11638 INLINE_RUNTIME_FUNCTION_LIST(I) 12169 INLINE_RUNTIME_FUNCTION_LIST(I)
11639 }; 12170 };
11640 12171
11641 12172
11642 MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Object* dictionary) { 12173 MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Heap* heap,
12174 Object* dictionary) {
12175 ASSERT(Isolate::Current()->heap() == heap);
11643 ASSERT(dictionary != NULL); 12176 ASSERT(dictionary != NULL);
11644 ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0); 12177 ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0);
11645 for (int i = 0; i < kNumFunctions; ++i) { 12178 for (int i = 0; i < kNumFunctions; ++i) {
11646 Object* name_symbol; 12179 Object* name_symbol;
11647 { MaybeObject* maybe_name_symbol = 12180 { MaybeObject* maybe_name_symbol =
11648 Heap::LookupAsciiSymbol(kIntrinsicFunctions[i].name); 12181 heap->LookupAsciiSymbol(kIntrinsicFunctions[i].name);
11649 if (!maybe_name_symbol->ToObject(&name_symbol)) return maybe_name_symbol; 12182 if (!maybe_name_symbol->ToObject(&name_symbol)) return maybe_name_symbol;
11650 } 12183 }
11651 StringDictionary* string_dictionary = StringDictionary::cast(dictionary); 12184 StringDictionary* string_dictionary = StringDictionary::cast(dictionary);
11652 { MaybeObject* maybe_dictionary = string_dictionary->Add( 12185 { MaybeObject* maybe_dictionary = string_dictionary->Add(
11653 String::cast(name_symbol), 12186 String::cast(name_symbol),
11654 Smi::FromInt(i), 12187 Smi::FromInt(i),
11655 PropertyDetails(NONE, NORMAL)); 12188 PropertyDetails(NONE, NORMAL));
11656 if (!maybe_dictionary->ToObject(&dictionary)) { 12189 if (!maybe_dictionary->ToObject(&dictionary)) {
11657 // Non-recoverable failure. Calling code must restart heap 12190 // Non-recoverable failure. Calling code must restart heap
11658 // initialization. 12191 // initialization.
11659 return maybe_dictionary; 12192 return maybe_dictionary;
11660 } 12193 }
11661 } 12194 }
11662 } 12195 }
11663 return dictionary; 12196 return dictionary;
11664 } 12197 }
11665 12198
11666 12199
11667 Runtime::Function* Runtime::FunctionForSymbol(Handle<String> name) { 12200 const Runtime::Function* Runtime::FunctionForSymbol(Handle<String> name) {
11668 int entry = Heap::intrinsic_function_names()->FindEntry(*name); 12201 Heap* heap = name->GetHeap();
12202 int entry = heap->intrinsic_function_names()->FindEntry(*name);
11669 if (entry != kNotFound) { 12203 if (entry != kNotFound) {
11670 Object* smi_index = Heap::intrinsic_function_names()->ValueAt(entry); 12204 Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry);
11671 int function_index = Smi::cast(smi_index)->value(); 12205 int function_index = Smi::cast(smi_index)->value();
11672 return &(kIntrinsicFunctions[function_index]); 12206 return &(kIntrinsicFunctions[function_index]);
11673 } 12207 }
11674 return NULL; 12208 return NULL;
11675 } 12209 }
11676 12210
11677 12211
11678 Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 12212 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
11679 return &(kIntrinsicFunctions[static_cast<int>(id)]); 12213 return &(kIntrinsicFunctions[static_cast<int>(id)]);
11680 } 12214 }
11681 12215
11682 12216
11683 void Runtime::PerformGC(Object* result) { 12217 void Runtime::PerformGC(Object* result) {
11684 Failure* failure = Failure::cast(result); 12218 Failure* failure = Failure::cast(result);
11685 if (failure->IsRetryAfterGC()) { 12219 if (failure->IsRetryAfterGC()) {
11686 // Try to do a garbage collection; ignore it if it fails. The C 12220 // Try to do a garbage collection; ignore it if it fails. The C
11687 // entry stub will throw an out-of-memory exception in that case. 12221 // entry stub will throw an out-of-memory exception in that case.
11688 Heap::CollectGarbage(failure->allocation_space()); 12222 HEAP->CollectGarbage(failure->allocation_space());
11689 } else { 12223 } else {
11690 // Handle last resort GC and make sure to allow future allocations 12224 // Handle last resort GC and make sure to allow future allocations
11691 // to grow the heap without causing GCs (if possible). 12225 // to grow the heap without causing GCs (if possible).
11692 Counters::gc_last_resort_from_js.Increment(); 12226 COUNTERS->gc_last_resort_from_js()->Increment();
11693 Heap::CollectAllGarbage(Heap::kNoGCFlags); 12227 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
11694 } 12228 }
11695 } 12229 }
11696 12230
11697 12231
11698 } } // namespace v8::internal 12232 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698