OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 while (!Is<C>(obj)) { | 43 while (!Is<C>(obj)) { |
44 if (obj == Heap::null_value()) return NULL; | 44 if (obj == Heap::null_value()) return NULL; |
45 obj = obj->GetPrototype(); | 45 obj = obj->GetPrototype(); |
46 } | 46 } |
47 *found_it = true; | 47 *found_it = true; |
48 return C::cast(obj); | 48 return C::cast(obj); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 // Entry point that never should be called. | 52 // Entry point that never should be called. |
53 Object* Accessors::IllegalSetter(JSObject*, Object*, void*) { | 53 MaybeObject* Accessors::IllegalSetter(JSObject*, Object*, void*) { |
54 UNREACHABLE(); | 54 UNREACHABLE(); |
55 return NULL; | 55 return NULL; |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 Object* Accessors::IllegalGetAccessor(Object* object, void*) { | 59 Object* Accessors::IllegalGetAccessor(Object* object, void*) { |
60 UNREACHABLE(); | 60 UNREACHABLE(); |
61 return object; | 61 return object; |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 Object* Accessors::ReadOnlySetAccessor(JSObject*, Object* value, void*) { | 65 MaybeObject* Accessors::ReadOnlySetAccessor(JSObject*, Object* value, void*) { |
66 // According to ECMA-262, section 8.6.2.2, page 28, setting | 66 // According to ECMA-262, section 8.6.2.2, page 28, setting |
67 // read-only properties must be silently ignored. | 67 // read-only properties must be silently ignored. |
68 return value; | 68 return value; |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 // | 72 // |
73 // Accessors::ArrayLength | 73 // Accessors::ArrayLength |
74 // | 74 // |
75 | 75 |
76 | 76 |
77 Object* Accessors::ArrayGetLength(Object* object, void*) { | 77 MaybeObject* Accessors::ArrayGetLength(Object* object, void*) { |
78 // Traverse the prototype chain until we reach an array. | 78 // Traverse the prototype chain until we reach an array. |
79 bool found_it = false; | 79 bool found_it = false; |
80 JSArray* holder = FindInPrototypeChain<JSArray>(object, &found_it); | 80 JSArray* holder = FindInPrototypeChain<JSArray>(object, &found_it); |
81 if (!found_it) return Smi::FromInt(0); | 81 if (!found_it) return Smi::FromInt(0); |
82 return holder->length(); | 82 return holder->length(); |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 // The helper function will 'flatten' Number objects. | 86 // The helper function will 'flatten' Number objects. |
87 Object* Accessors::FlattenNumber(Object* value) { | 87 Object* Accessors::FlattenNumber(Object* value) { |
88 if (value->IsNumber() || !value->IsJSValue()) return value; | 88 if (value->IsNumber() || !value->IsJSValue()) return value; |
89 JSValue* wrapper = JSValue::cast(value); | 89 JSValue* wrapper = JSValue::cast(value); |
90 ASSERT( | 90 ASSERT( |
91 Top::context()->global_context()->number_function()->has_initial_map()); | 91 Top::context()->global_context()->number_function()->has_initial_map()); |
92 Map* number_map = | 92 Map* number_map = |
93 Top::context()->global_context()->number_function()->initial_map(); | 93 Top::context()->global_context()->number_function()->initial_map(); |
94 if (wrapper->map() == number_map) return wrapper->value(); | 94 if (wrapper->map() == number_map) return wrapper->value(); |
95 return value; | 95 return value; |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 Object* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { | 99 MaybeObject* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { |
100 value = FlattenNumber(value); | 100 value = FlattenNumber(value); |
101 | 101 |
102 // Need to call methods that may trigger GC. | 102 // Need to call methods that may trigger GC. |
103 HandleScope scope; | 103 HandleScope scope; |
104 | 104 |
105 // Protect raw pointers. | 105 // Protect raw pointers. |
106 Handle<JSObject> object_handle(object); | 106 Handle<JSObject> object_handle(object); |
107 Handle<Object> value_handle(value); | 107 Handle<Object> value_handle(value); |
108 | 108 |
109 bool has_exception; | 109 bool has_exception; |
(...skipping 27 matching lines...) Expand all Loading... |
137 ArraySetLength, | 137 ArraySetLength, |
138 0 | 138 0 |
139 }; | 139 }; |
140 | 140 |
141 | 141 |
142 // | 142 // |
143 // Accessors::StringLength | 143 // Accessors::StringLength |
144 // | 144 // |
145 | 145 |
146 | 146 |
147 Object* Accessors::StringGetLength(Object* object, void*) { | 147 MaybeObject* Accessors::StringGetLength(Object* object, void*) { |
148 Object* value = object; | 148 Object* value = object; |
149 if (object->IsJSValue()) value = JSValue::cast(object)->value(); | 149 if (object->IsJSValue()) value = JSValue::cast(object)->value(); |
150 if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); | 150 if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); |
151 // If object is not a string we return 0 to be compatible with WebKit. | 151 // If object is not a string we return 0 to be compatible with WebKit. |
152 // Note: Firefox returns the length of ToString(object). | 152 // Note: Firefox returns the length of ToString(object). |
153 return Smi::FromInt(0); | 153 return Smi::FromInt(0); |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 const AccessorDescriptor Accessors::StringLength = { | 157 const AccessorDescriptor Accessors::StringLength = { |
158 StringGetLength, | 158 StringGetLength, |
159 IllegalSetter, | 159 IllegalSetter, |
160 0 | 160 0 |
161 }; | 161 }; |
162 | 162 |
163 | 163 |
164 // | 164 // |
165 // Accessors::ScriptSource | 165 // Accessors::ScriptSource |
166 // | 166 // |
167 | 167 |
168 | 168 |
169 Object* Accessors::ScriptGetSource(Object* object, void*) { | 169 MaybeObject* Accessors::ScriptGetSource(Object* object, void*) { |
170 Object* script = JSValue::cast(object)->value(); | 170 Object* script = JSValue::cast(object)->value(); |
171 return Script::cast(script)->source(); | 171 return Script::cast(script)->source(); |
172 } | 172 } |
173 | 173 |
174 | 174 |
175 const AccessorDescriptor Accessors::ScriptSource = { | 175 const AccessorDescriptor Accessors::ScriptSource = { |
176 ScriptGetSource, | 176 ScriptGetSource, |
177 IllegalSetter, | 177 IllegalSetter, |
178 0 | 178 0 |
179 }; | 179 }; |
180 | 180 |
181 | 181 |
182 // | 182 // |
183 // Accessors::ScriptName | 183 // Accessors::ScriptName |
184 // | 184 // |
185 | 185 |
186 | 186 |
187 Object* Accessors::ScriptGetName(Object* object, void*) { | 187 MaybeObject* Accessors::ScriptGetName(Object* object, void*) { |
188 Object* script = JSValue::cast(object)->value(); | 188 Object* script = JSValue::cast(object)->value(); |
189 return Script::cast(script)->name(); | 189 return Script::cast(script)->name(); |
190 } | 190 } |
191 | 191 |
192 | 192 |
193 const AccessorDescriptor Accessors::ScriptName = { | 193 const AccessorDescriptor Accessors::ScriptName = { |
194 ScriptGetName, | 194 ScriptGetName, |
195 IllegalSetter, | 195 IllegalSetter, |
196 0 | 196 0 |
197 }; | 197 }; |
198 | 198 |
199 | 199 |
200 // | 200 // |
201 // Accessors::ScriptId | 201 // Accessors::ScriptId |
202 // | 202 // |
203 | 203 |
204 | 204 |
205 Object* Accessors::ScriptGetId(Object* object, void*) { | 205 MaybeObject* Accessors::ScriptGetId(Object* object, void*) { |
206 Object* script = JSValue::cast(object)->value(); | 206 Object* script = JSValue::cast(object)->value(); |
207 return Script::cast(script)->id(); | 207 return Script::cast(script)->id(); |
208 } | 208 } |
209 | 209 |
210 | 210 |
211 const AccessorDescriptor Accessors::ScriptId = { | 211 const AccessorDescriptor Accessors::ScriptId = { |
212 ScriptGetId, | 212 ScriptGetId, |
213 IllegalSetter, | 213 IllegalSetter, |
214 0 | 214 0 |
215 }; | 215 }; |
216 | 216 |
217 | 217 |
218 // | 218 // |
219 // Accessors::ScriptLineOffset | 219 // Accessors::ScriptLineOffset |
220 // | 220 // |
221 | 221 |
222 | 222 |
223 Object* Accessors::ScriptGetLineOffset(Object* object, void*) { | 223 MaybeObject* Accessors::ScriptGetLineOffset(Object* object, void*) { |
224 Object* script = JSValue::cast(object)->value(); | 224 Object* script = JSValue::cast(object)->value(); |
225 return Script::cast(script)->line_offset(); | 225 return Script::cast(script)->line_offset(); |
226 } | 226 } |
227 | 227 |
228 | 228 |
229 const AccessorDescriptor Accessors::ScriptLineOffset = { | 229 const AccessorDescriptor Accessors::ScriptLineOffset = { |
230 ScriptGetLineOffset, | 230 ScriptGetLineOffset, |
231 IllegalSetter, | 231 IllegalSetter, |
232 0 | 232 0 |
233 }; | 233 }; |
234 | 234 |
235 | 235 |
236 // | 236 // |
237 // Accessors::ScriptColumnOffset | 237 // Accessors::ScriptColumnOffset |
238 // | 238 // |
239 | 239 |
240 | 240 |
241 Object* Accessors::ScriptGetColumnOffset(Object* object, void*) { | 241 MaybeObject* Accessors::ScriptGetColumnOffset(Object* object, void*) { |
242 Object* script = JSValue::cast(object)->value(); | 242 Object* script = JSValue::cast(object)->value(); |
243 return Script::cast(script)->column_offset(); | 243 return Script::cast(script)->column_offset(); |
244 } | 244 } |
245 | 245 |
246 | 246 |
247 const AccessorDescriptor Accessors::ScriptColumnOffset = { | 247 const AccessorDescriptor Accessors::ScriptColumnOffset = { |
248 ScriptGetColumnOffset, | 248 ScriptGetColumnOffset, |
249 IllegalSetter, | 249 IllegalSetter, |
250 0 | 250 0 |
251 }; | 251 }; |
252 | 252 |
253 | 253 |
254 // | 254 // |
255 // Accessors::ScriptData | 255 // Accessors::ScriptData |
256 // | 256 // |
257 | 257 |
258 | 258 |
259 Object* Accessors::ScriptGetData(Object* object, void*) { | 259 MaybeObject* Accessors::ScriptGetData(Object* object, void*) { |
260 Object* script = JSValue::cast(object)->value(); | 260 Object* script = JSValue::cast(object)->value(); |
261 return Script::cast(script)->data(); | 261 return Script::cast(script)->data(); |
262 } | 262 } |
263 | 263 |
264 | 264 |
265 const AccessorDescriptor Accessors::ScriptData = { | 265 const AccessorDescriptor Accessors::ScriptData = { |
266 ScriptGetData, | 266 ScriptGetData, |
267 IllegalSetter, | 267 IllegalSetter, |
268 0 | 268 0 |
269 }; | 269 }; |
270 | 270 |
271 | 271 |
272 // | 272 // |
273 // Accessors::ScriptType | 273 // Accessors::ScriptType |
274 // | 274 // |
275 | 275 |
276 | 276 |
277 Object* Accessors::ScriptGetType(Object* object, void*) { | 277 MaybeObject* Accessors::ScriptGetType(Object* object, void*) { |
278 Object* script = JSValue::cast(object)->value(); | 278 Object* script = JSValue::cast(object)->value(); |
279 return Script::cast(script)->type(); | 279 return Script::cast(script)->type(); |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 const AccessorDescriptor Accessors::ScriptType = { | 283 const AccessorDescriptor Accessors::ScriptType = { |
284 ScriptGetType, | 284 ScriptGetType, |
285 IllegalSetter, | 285 IllegalSetter, |
286 0 | 286 0 |
287 }; | 287 }; |
288 | 288 |
289 | 289 |
290 // | 290 // |
291 // Accessors::ScriptCompilationType | 291 // Accessors::ScriptCompilationType |
292 // | 292 // |
293 | 293 |
294 | 294 |
295 Object* Accessors::ScriptGetCompilationType(Object* object, void*) { | 295 MaybeObject* Accessors::ScriptGetCompilationType(Object* object, void*) { |
296 Object* script = JSValue::cast(object)->value(); | 296 Object* script = JSValue::cast(object)->value(); |
297 return Script::cast(script)->compilation_type(); | 297 return Script::cast(script)->compilation_type(); |
298 } | 298 } |
299 | 299 |
300 | 300 |
301 const AccessorDescriptor Accessors::ScriptCompilationType = { | 301 const AccessorDescriptor Accessors::ScriptCompilationType = { |
302 ScriptGetCompilationType, | 302 ScriptGetCompilationType, |
303 IllegalSetter, | 303 IllegalSetter, |
304 0 | 304 0 |
305 }; | 305 }; |
306 | 306 |
307 | 307 |
308 // | 308 // |
309 // Accessors::ScriptGetLineEnds | 309 // Accessors::ScriptGetLineEnds |
310 // | 310 // |
311 | 311 |
312 | 312 |
313 Object* Accessors::ScriptGetLineEnds(Object* object, void*) { | 313 MaybeObject* Accessors::ScriptGetLineEnds(Object* object, void*) { |
314 HandleScope scope; | 314 HandleScope scope; |
315 Handle<Script> script(Script::cast(JSValue::cast(object)->value())); | 315 Handle<Script> script(Script::cast(JSValue::cast(object)->value())); |
316 InitScriptLineEnds(script); | 316 InitScriptLineEnds(script); |
317 ASSERT(script->line_ends()->IsFixedArray()); | 317 ASSERT(script->line_ends()->IsFixedArray()); |
318 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 318 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
319 Handle<FixedArray> copy = Factory::CopyFixedArray(line_ends); | 319 Handle<FixedArray> copy = Factory::CopyFixedArray(line_ends); |
320 Handle<JSArray> js_array = Factory::NewJSArrayWithElements(copy); | 320 Handle<JSArray> js_array = Factory::NewJSArrayWithElements(copy); |
321 return *js_array; | 321 return *js_array; |
322 } | 322 } |
323 | 323 |
324 | 324 |
325 const AccessorDescriptor Accessors::ScriptLineEnds = { | 325 const AccessorDescriptor Accessors::ScriptLineEnds = { |
326 ScriptGetLineEnds, | 326 ScriptGetLineEnds, |
327 IllegalSetter, | 327 IllegalSetter, |
328 0 | 328 0 |
329 }; | 329 }; |
330 | 330 |
331 | 331 |
332 // | 332 // |
333 // Accessors::ScriptGetContextData | 333 // Accessors::ScriptGetContextData |
334 // | 334 // |
335 | 335 |
336 | 336 |
337 Object* Accessors::ScriptGetContextData(Object* object, void*) { | 337 MaybeObject* Accessors::ScriptGetContextData(Object* object, void*) { |
338 Object* script = JSValue::cast(object)->value(); | 338 Object* script = JSValue::cast(object)->value(); |
339 return Script::cast(script)->context_data(); | 339 return Script::cast(script)->context_data(); |
340 } | 340 } |
341 | 341 |
342 | 342 |
343 const AccessorDescriptor Accessors::ScriptContextData = { | 343 const AccessorDescriptor Accessors::ScriptContextData = { |
344 ScriptGetContextData, | 344 ScriptGetContextData, |
345 IllegalSetter, | 345 IllegalSetter, |
346 0 | 346 0 |
347 }; | 347 }; |
348 | 348 |
349 | 349 |
350 // | 350 // |
351 // Accessors::ScriptGetEvalFromScript | 351 // Accessors::ScriptGetEvalFromScript |
352 // | 352 // |
353 | 353 |
354 | 354 |
355 Object* Accessors::ScriptGetEvalFromScript(Object* object, void*) { | 355 MaybeObject* Accessors::ScriptGetEvalFromScript(Object* object, void*) { |
356 Object* script = JSValue::cast(object)->value(); | 356 Object* script = JSValue::cast(object)->value(); |
357 if (!Script::cast(script)->eval_from_shared()->IsUndefined()) { | 357 if (!Script::cast(script)->eval_from_shared()->IsUndefined()) { |
358 Handle<SharedFunctionInfo> eval_from_shared( | 358 Handle<SharedFunctionInfo> eval_from_shared( |
359 SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared())); | 359 SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared())); |
360 | 360 |
361 if (eval_from_shared->script()->IsScript()) { | 361 if (eval_from_shared->script()->IsScript()) { |
362 Handle<Script> eval_from_script(Script::cast(eval_from_shared->script())); | 362 Handle<Script> eval_from_script(Script::cast(eval_from_shared->script())); |
363 return *GetScriptWrapper(eval_from_script); | 363 return *GetScriptWrapper(eval_from_script); |
364 } | 364 } |
365 } | 365 } |
366 return Heap::undefined_value(); | 366 return Heap::undefined_value(); |
367 } | 367 } |
368 | 368 |
369 | 369 |
370 const AccessorDescriptor Accessors::ScriptEvalFromScript = { | 370 const AccessorDescriptor Accessors::ScriptEvalFromScript = { |
371 ScriptGetEvalFromScript, | 371 ScriptGetEvalFromScript, |
372 IllegalSetter, | 372 IllegalSetter, |
373 0 | 373 0 |
374 }; | 374 }; |
375 | 375 |
376 | 376 |
377 // | 377 // |
378 // Accessors::ScriptGetEvalFromScriptPosition | 378 // Accessors::ScriptGetEvalFromScriptPosition |
379 // | 379 // |
380 | 380 |
381 | 381 |
382 Object* Accessors::ScriptGetEvalFromScriptPosition(Object* object, void*) { | 382 MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Object* object, void*) { |
383 HandleScope scope; | 383 HandleScope scope; |
384 Handle<Script> script(Script::cast(JSValue::cast(object)->value())); | 384 Handle<Script> script(Script::cast(JSValue::cast(object)->value())); |
385 | 385 |
386 // If this is not a script compiled through eval there is no eval position. | 386 // If this is not a script compiled through eval there is no eval position. |
387 int compilation_type = Smi::cast(script->compilation_type())->value(); | 387 int compilation_type = Smi::cast(script->compilation_type())->value(); |
388 if (compilation_type != Script::COMPILATION_TYPE_EVAL) { | 388 if (compilation_type != Script::COMPILATION_TYPE_EVAL) { |
389 return Heap::undefined_value(); | 389 return Heap::undefined_value(); |
390 } | 390 } |
391 | 391 |
392 // Get the function from where eval was called and find the source position | 392 // Get the function from where eval was called and find the source position |
(...skipping 10 matching lines...) Expand all Loading... |
403 IllegalSetter, | 403 IllegalSetter, |
404 0 | 404 0 |
405 }; | 405 }; |
406 | 406 |
407 | 407 |
408 // | 408 // |
409 // Accessors::ScriptGetEvalFromFunctionName | 409 // Accessors::ScriptGetEvalFromFunctionName |
410 // | 410 // |
411 | 411 |
412 | 412 |
413 Object* Accessors::ScriptGetEvalFromFunctionName(Object* object, void*) { | 413 MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Object* object, void*) { |
414 Object* script = JSValue::cast(object)->value(); | 414 Object* script = JSValue::cast(object)->value(); |
415 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast( | 415 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast( |
416 Script::cast(script)->eval_from_shared())); | 416 Script::cast(script)->eval_from_shared())); |
417 | 417 |
418 | 418 |
419 // Find the name of the function calling eval. | 419 // Find the name of the function calling eval. |
420 if (!shared->name()->IsUndefined()) { | 420 if (!shared->name()->IsUndefined()) { |
421 return shared->name(); | 421 return shared->name(); |
422 } else { | 422 } else { |
423 return shared->inferred_name(); | 423 return shared->inferred_name(); |
424 } | 424 } |
425 } | 425 } |
426 | 426 |
427 | 427 |
428 const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = { | 428 const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = { |
429 ScriptGetEvalFromFunctionName, | 429 ScriptGetEvalFromFunctionName, |
430 IllegalSetter, | 430 IllegalSetter, |
431 0 | 431 0 |
432 }; | 432 }; |
433 | 433 |
434 | 434 |
435 // | 435 // |
436 // Accessors::FunctionPrototype | 436 // Accessors::FunctionPrototype |
437 // | 437 // |
438 | 438 |
439 | 439 |
440 Object* Accessors::FunctionGetPrototype(Object* object, void*) { | 440 MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { |
441 bool found_it = false; | 441 bool found_it = false; |
442 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 442 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
443 if (!found_it) return Heap::undefined_value(); | 443 if (!found_it) return Heap::undefined_value(); |
444 if (!function->has_prototype()) { | 444 if (!function->has_prototype()) { |
445 Object* prototype = Heap::AllocateFunctionPrototype(function); | 445 Object* prototype; |
446 if (prototype->IsFailure()) return prototype; | 446 { MaybeObject* maybe_prototype = Heap::AllocateFunctionPrototype(function); |
447 Object* result = function->SetPrototype(prototype); | 447 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
448 if (result->IsFailure()) return result; | 448 } |
| 449 Object* result; |
| 450 { MaybeObject* maybe_result = function->SetPrototype(prototype); |
| 451 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 452 } |
449 } | 453 } |
450 return function->prototype(); | 454 return function->prototype(); |
451 } | 455 } |
452 | 456 |
453 | 457 |
454 Object* Accessors::FunctionSetPrototype(JSObject* object, | 458 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, |
455 Object* value, | 459 Object* value, |
456 void*) { | 460 void*) { |
457 bool found_it = false; | 461 bool found_it = false; |
458 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 462 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
459 if (!found_it) return Heap::undefined_value(); | 463 if (!found_it) return Heap::undefined_value(); |
460 if (function->has_initial_map()) { | 464 if (function->has_initial_map()) { |
461 // If the function has allocated the initial map | 465 // If the function has allocated the initial map |
462 // replace it with a copy containing the new prototype. | 466 // replace it with a copy containing the new prototype. |
463 Object* new_map = function->initial_map()->CopyDropTransitions(); | 467 Object* new_map; |
464 if (new_map->IsFailure()) return new_map; | 468 { MaybeObject* maybe_new_map = |
| 469 function->initial_map()->CopyDropTransitions(); |
| 470 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; |
| 471 } |
465 function->set_initial_map(Map::cast(new_map)); | 472 function->set_initial_map(Map::cast(new_map)); |
466 } | 473 } |
467 Object* prototype = function->SetPrototype(value); | 474 Object* prototype; |
468 if (prototype->IsFailure()) return prototype; | 475 { MaybeObject* maybe_prototype = function->SetPrototype(value); |
| 476 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
| 477 } |
469 ASSERT(function->prototype() == value); | 478 ASSERT(function->prototype() == value); |
470 return function; | 479 return function; |
471 } | 480 } |
472 | 481 |
473 | 482 |
474 const AccessorDescriptor Accessors::FunctionPrototype = { | 483 const AccessorDescriptor Accessors::FunctionPrototype = { |
475 FunctionGetPrototype, | 484 FunctionGetPrototype, |
476 FunctionSetPrototype, | 485 FunctionSetPrototype, |
477 0 | 486 0 |
478 }; | 487 }; |
479 | 488 |
480 | 489 |
481 // | 490 // |
482 // Accessors::FunctionLength | 491 // Accessors::FunctionLength |
483 // | 492 // |
484 | 493 |
485 | 494 |
486 Object* Accessors::FunctionGetLength(Object* object, void*) { | 495 MaybeObject* Accessors::FunctionGetLength(Object* object, void*) { |
487 bool found_it = false; | 496 bool found_it = false; |
488 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 497 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
489 if (!found_it) return Smi::FromInt(0); | 498 if (!found_it) return Smi::FromInt(0); |
490 // Check if already compiled. | 499 // Check if already compiled. |
491 if (!function->shared()->is_compiled()) { | 500 if (!function->shared()->is_compiled()) { |
492 // If the function isn't compiled yet, the length is not computed | 501 // If the function isn't compiled yet, the length is not computed |
493 // correctly yet. Compile it now and return the right length. | 502 // correctly yet. Compile it now and return the right length. |
494 HandleScope scope; | 503 HandleScope scope; |
495 Handle<SharedFunctionInfo> shared(function->shared()); | 504 Handle<SharedFunctionInfo> shared(function->shared()); |
496 if (!CompileLazyShared(shared, KEEP_EXCEPTION)) { | 505 if (!CompileLazyShared(shared, KEEP_EXCEPTION)) { |
(...skipping 11 matching lines...) Expand all Loading... |
508 ReadOnlySetAccessor, | 517 ReadOnlySetAccessor, |
509 0 | 518 0 |
510 }; | 519 }; |
511 | 520 |
512 | 521 |
513 // | 522 // |
514 // Accessors::FunctionName | 523 // Accessors::FunctionName |
515 // | 524 // |
516 | 525 |
517 | 526 |
518 Object* Accessors::FunctionGetName(Object* object, void*) { | 527 MaybeObject* Accessors::FunctionGetName(Object* object, void*) { |
519 bool found_it = false; | 528 bool found_it = false; |
520 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); | 529 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); |
521 if (!found_it) return Heap::undefined_value(); | 530 if (!found_it) return Heap::undefined_value(); |
522 return holder->shared()->name(); | 531 return holder->shared()->name(); |
523 } | 532 } |
524 | 533 |
525 | 534 |
526 const AccessorDescriptor Accessors::FunctionName = { | 535 const AccessorDescriptor Accessors::FunctionName = { |
527 FunctionGetName, | 536 FunctionGetName, |
528 ReadOnlySetAccessor, | 537 ReadOnlySetAccessor, |
529 0 | 538 0 |
530 }; | 539 }; |
531 | 540 |
532 | 541 |
533 // | 542 // |
534 // Accessors::FunctionArguments | 543 // Accessors::FunctionArguments |
535 // | 544 // |
536 | 545 |
537 | 546 |
538 Object* Accessors::FunctionGetArguments(Object* object, void*) { | 547 MaybeObject* Accessors::FunctionGetArguments(Object* object, void*) { |
539 HandleScope scope; | 548 HandleScope scope; |
540 bool found_it = false; | 549 bool found_it = false; |
541 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); | 550 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); |
542 if (!found_it) return Heap::undefined_value(); | 551 if (!found_it) return Heap::undefined_value(); |
543 Handle<JSFunction> function(holder); | 552 Handle<JSFunction> function(holder); |
544 | 553 |
545 // Find the top invocation of the function by traversing frames. | 554 // Find the top invocation of the function by traversing frames. |
546 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) { | 555 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) { |
547 // Skip all frames that aren't invocations of the given function. | 556 // Skip all frames that aren't invocations of the given function. |
548 JavaScriptFrame* frame = it.frame(); | 557 JavaScriptFrame* frame = it.frame(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 ReadOnlySetAccessor, | 596 ReadOnlySetAccessor, |
588 0 | 597 0 |
589 }; | 598 }; |
590 | 599 |
591 | 600 |
592 // | 601 // |
593 // Accessors::FunctionCaller | 602 // Accessors::FunctionCaller |
594 // | 603 // |
595 | 604 |
596 | 605 |
597 Object* Accessors::FunctionGetCaller(Object* object, void*) { | 606 MaybeObject* Accessors::FunctionGetCaller(Object* object, void*) { |
598 HandleScope scope; | 607 HandleScope scope; |
| 608 AssertNoAllocation no_alloc; |
599 bool found_it = false; | 609 bool found_it = false; |
600 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); | 610 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); |
601 if (!found_it) return Heap::undefined_value(); | 611 if (!found_it) return Heap::undefined_value(); |
602 Handle<JSFunction> function(holder); | 612 Handle<JSFunction> function(holder); |
603 | 613 |
604 // Find the top invocation of the function by traversing frames. | 614 // Find the top invocation of the function by traversing frames. |
605 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) { | 615 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) { |
606 // Skip all frames that aren't invocations of the given function. | 616 // Skip all frames that aren't invocations of the given function. |
607 if (it.frame()->function() != *function) continue; | 617 if (it.frame()->function() != *function) continue; |
608 // Once we have found the frame, we need to go to the caller | 618 // Once we have found the frame, we need to go to the caller |
(...skipping 17 matching lines...) Expand all Loading... |
626 ReadOnlySetAccessor, | 636 ReadOnlySetAccessor, |
627 0 | 637 0 |
628 }; | 638 }; |
629 | 639 |
630 | 640 |
631 // | 641 // |
632 // Accessors::ObjectPrototype | 642 // Accessors::ObjectPrototype |
633 // | 643 // |
634 | 644 |
635 | 645 |
636 Object* Accessors::ObjectGetPrototype(Object* receiver, void*) { | 646 MaybeObject* Accessors::ObjectGetPrototype(Object* receiver, void*) { |
637 Object* current = receiver->GetPrototype(); | 647 Object* current = receiver->GetPrototype(); |
638 while (current->IsJSObject() && | 648 while (current->IsJSObject() && |
639 JSObject::cast(current)->map()->is_hidden_prototype()) { | 649 JSObject::cast(current)->map()->is_hidden_prototype()) { |
640 current = current->GetPrototype(); | 650 current = current->GetPrototype(); |
641 } | 651 } |
642 return current; | 652 return current; |
643 } | 653 } |
644 | 654 |
645 | 655 |
646 Object* Accessors::ObjectSetPrototype(JSObject* receiver, | 656 MaybeObject* Accessors::ObjectSetPrototype(JSObject* receiver, |
647 Object* value, | 657 Object* value, |
648 void*) { | 658 void*) { |
649 const bool skip_hidden_prototypes = true; | 659 const bool skip_hidden_prototypes = true; |
650 // To be consistent with other Set functions, return the value. | 660 // To be consistent with other Set functions, return the value. |
651 return receiver->SetPrototype(value, skip_hidden_prototypes); | 661 return receiver->SetPrototype(value, skip_hidden_prototypes); |
652 } | 662 } |
653 | 663 |
654 | 664 |
655 const AccessorDescriptor Accessors::ObjectPrototype = { | 665 const AccessorDescriptor Accessors::ObjectPrototype = { |
656 ObjectGetPrototype, | 666 ObjectGetPrototype, |
657 ObjectSetPrototype, | 667 ObjectSetPrototype, |
658 0 | 668 0 |
659 }; | 669 }; |
660 | 670 |
661 } } // namespace v8::internal | 671 } } // namespace v8::internal |
OLD | NEW |