| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 template <class C> | 44 template <class C> |
| 45 static C* FindInstanceOf(Isolate* isolate, Object* obj) { | 45 static C* FindInstanceOf(Isolate* isolate, Object* obj) { |
| 46 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) { | 46 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) { |
| 47 if (Is<C>(cur)) return C::cast(cur); | 47 if (Is<C>(cur)) return C::cast(cur); |
| 48 } | 48 } |
| 49 return NULL; | 49 return NULL; |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 // Entry point that never should be called. | 53 // Entry point that never should be called. |
| 54 MaybeObject* Accessors::IllegalSetter(JSObject*, Object*, void*) { | 54 MaybeObject* Accessors::IllegalSetter(Isolate* isolate, |
| 55 JSObject*, |
| 56 Object*, |
| 57 void*) { |
| 55 UNREACHABLE(); | 58 UNREACHABLE(); |
| 56 return NULL; | 59 return NULL; |
| 57 } | 60 } |
| 58 | 61 |
| 59 | 62 |
| 60 Object* Accessors::IllegalGetAccessor(Object* object, void*) { | 63 Object* Accessors::IllegalGetAccessor(Isolate* isolate, |
| 64 Object* object, |
| 65 void*) { |
| 61 UNREACHABLE(); | 66 UNREACHABLE(); |
| 62 return object; | 67 return object; |
| 63 } | 68 } |
| 64 | 69 |
| 65 | 70 |
| 66 MaybeObject* Accessors::ReadOnlySetAccessor(JSObject*, Object* value, void*) { | 71 MaybeObject* Accessors::ReadOnlySetAccessor(Isolate* isolate, |
| 72 JSObject*, |
| 73 Object* value, |
| 74 void*) { |
| 67 // According to ECMA-262, section 8.6.2.2, page 28, setting | 75 // According to ECMA-262, section 8.6.2.2, page 28, setting |
| 68 // read-only properties must be silently ignored. | 76 // read-only properties must be silently ignored. |
| 69 return value; | 77 return value; |
| 70 } | 78 } |
| 71 | 79 |
| 72 | 80 |
| 73 // | 81 // |
| 74 // Accessors::ArrayLength | 82 // Accessors::ArrayLength |
| 75 // | 83 // |
| 76 | 84 |
| 77 | 85 |
| 78 MaybeObject* Accessors::ArrayGetLength(Object* object, void*) { | 86 MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, |
| 87 Object* object, |
| 88 void*) { |
| 79 // Traverse the prototype chain until we reach an array. | 89 // Traverse the prototype chain until we reach an array. |
| 80 JSArray* holder = FindInstanceOf<JSArray>(Isolate::Current(), object); | 90 JSArray* holder = FindInstanceOf<JSArray>(isolate, object); |
| 81 return holder == NULL ? Smi::FromInt(0) : holder->length(); | 91 return holder == NULL ? Smi::FromInt(0) : holder->length(); |
| 82 } | 92 } |
| 83 | 93 |
| 84 | 94 |
| 85 // The helper function will 'flatten' Number objects. | 95 // The helper function will 'flatten' Number objects. |
| 86 Object* Accessors::FlattenNumber(Object* value) { | 96 Object* Accessors::FlattenNumber(Isolate* isolate, Object* value) { |
| 87 if (value->IsNumber() || !value->IsJSValue()) return value; | 97 if (value->IsNumber() || !value->IsJSValue()) return value; |
| 88 JSValue* wrapper = JSValue::cast(value); | 98 JSValue* wrapper = JSValue::cast(value); |
| 89 ASSERT(Isolate::Current()->context()->native_context()->number_function()-> | 99 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()-> |
| 90 has_initial_map()); | 100 has_initial_map()); |
| 91 Map* number_map = Isolate::Current()->context()->native_context()-> | 101 Map* number_map = isolate->context()->native_context()-> |
| 92 number_function()->initial_map(); | 102 number_function()->initial_map(); |
| 93 if (wrapper->map() == number_map) return wrapper->value(); | 103 if (wrapper->map() == number_map) return wrapper->value(); |
| 94 return value; | 104 return value; |
| 95 } | 105 } |
| 96 | 106 |
| 97 | 107 |
| 98 MaybeObject* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { | 108 MaybeObject* Accessors::ArraySetLength(Isolate* isolate, |
| 99 Isolate* isolate = object->GetIsolate(); | 109 JSObject* object, |
| 100 | 110 Object* value, |
| 111 void*) { |
| 101 // This means one of the object's prototypes is a JSArray and the | 112 // This means one of the object's prototypes is a JSArray and the |
| 102 // object does not have a 'length' property. Calling SetProperty | 113 // object does not have a 'length' property. Calling SetProperty |
| 103 // causes an infinite loop. | 114 // causes an infinite loop. |
| 104 if (!object->IsJSArray()) { | 115 if (!object->IsJSArray()) { |
| 105 return object->SetLocalPropertyIgnoreAttributes( | 116 return object->SetLocalPropertyIgnoreAttributes( |
| 106 isolate->heap()->length_string(), value, NONE); | 117 isolate->heap()->length_string(), value, NONE); |
| 107 } | 118 } |
| 108 | 119 |
| 109 value = FlattenNumber(value); | 120 value = FlattenNumber(isolate, value); |
| 110 | 121 |
| 111 // Need to call methods that may trigger GC. | 122 // Need to call methods that may trigger GC. |
| 112 HandleScope scope(isolate); | 123 HandleScope scope(isolate); |
| 113 | 124 |
| 114 // Protect raw pointers. | 125 // Protect raw pointers. |
| 115 Handle<JSArray> array_handle(JSArray::cast(object), isolate); | 126 Handle<JSArray> array_handle(JSArray::cast(object), isolate); |
| 116 Handle<Object> value_handle(value, isolate); | 127 Handle<Object> value_handle(value, isolate); |
| 117 | 128 |
| 118 bool has_exception; | 129 bool has_exception; |
| 119 Handle<Object> uint32_v = Execution::ToUint32(value_handle, &has_exception); | 130 Handle<Object> uint32_v = Execution::ToUint32(value_handle, &has_exception); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 135 ArraySetLength, | 146 ArraySetLength, |
| 136 0 | 147 0 |
| 137 }; | 148 }; |
| 138 | 149 |
| 139 | 150 |
| 140 // | 151 // |
| 141 // Accessors::StringLength | 152 // Accessors::StringLength |
| 142 // | 153 // |
| 143 | 154 |
| 144 | 155 |
| 145 MaybeObject* Accessors::StringGetLength(Object* object, void*) { | 156 MaybeObject* Accessors::StringGetLength(Isolate* isolate, |
| 157 Object* object, |
| 158 void*) { |
| 146 Object* value = object; | 159 Object* value = object; |
| 147 if (object->IsJSValue()) value = JSValue::cast(object)->value(); | 160 if (object->IsJSValue()) value = JSValue::cast(object)->value(); |
| 148 if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); | 161 if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); |
| 149 // If object is not a string we return 0 to be compatible with WebKit. | 162 // If object is not a string we return 0 to be compatible with WebKit. |
| 150 // Note: Firefox returns the length of ToString(object). | 163 // Note: Firefox returns the length of ToString(object). |
| 151 return Smi::FromInt(0); | 164 return Smi::FromInt(0); |
| 152 } | 165 } |
| 153 | 166 |
| 154 | 167 |
| 155 const AccessorDescriptor Accessors::StringLength = { | 168 const AccessorDescriptor Accessors::StringLength = { |
| 156 StringGetLength, | 169 StringGetLength, |
| 157 IllegalSetter, | 170 IllegalSetter, |
| 158 0 | 171 0 |
| 159 }; | 172 }; |
| 160 | 173 |
| 161 | 174 |
| 162 // | 175 // |
| 163 // Accessors::ScriptSource | 176 // Accessors::ScriptSource |
| 164 // | 177 // |
| 165 | 178 |
| 166 | 179 |
| 167 MaybeObject* Accessors::ScriptGetSource(Object* object, void*) { | 180 MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, |
| 181 Object* object, |
| 182 void*) { |
| 168 Object* script = JSValue::cast(object)->value(); | 183 Object* script = JSValue::cast(object)->value(); |
| 169 return Script::cast(script)->source(); | 184 return Script::cast(script)->source(); |
| 170 } | 185 } |
| 171 | 186 |
| 172 | 187 |
| 173 const AccessorDescriptor Accessors::ScriptSource = { | 188 const AccessorDescriptor Accessors::ScriptSource = { |
| 174 ScriptGetSource, | 189 ScriptGetSource, |
| 175 IllegalSetter, | 190 IllegalSetter, |
| 176 0 | 191 0 |
| 177 }; | 192 }; |
| 178 | 193 |
| 179 | 194 |
| 180 // | 195 // |
| 181 // Accessors::ScriptName | 196 // Accessors::ScriptName |
| 182 // | 197 // |
| 183 | 198 |
| 184 | 199 |
| 185 MaybeObject* Accessors::ScriptGetName(Object* object, void*) { | 200 MaybeObject* Accessors::ScriptGetName(Isolate* isolate, |
| 201 Object* object, |
| 202 void*) { |
| 186 Object* script = JSValue::cast(object)->value(); | 203 Object* script = JSValue::cast(object)->value(); |
| 187 return Script::cast(script)->name(); | 204 return Script::cast(script)->name(); |
| 188 } | 205 } |
| 189 | 206 |
| 190 | 207 |
| 191 const AccessorDescriptor Accessors::ScriptName = { | 208 const AccessorDescriptor Accessors::ScriptName = { |
| 192 ScriptGetName, | 209 ScriptGetName, |
| 193 IllegalSetter, | 210 IllegalSetter, |
| 194 0 | 211 0 |
| 195 }; | 212 }; |
| 196 | 213 |
| 197 | 214 |
| 198 // | 215 // |
| 199 // Accessors::ScriptId | 216 // Accessors::ScriptId |
| 200 // | 217 // |
| 201 | 218 |
| 202 | 219 |
| 203 MaybeObject* Accessors::ScriptGetId(Object* object, void*) { | 220 MaybeObject* Accessors::ScriptGetId(Isolate* isolate, Object* object, void*) { |
| 204 Object* script = JSValue::cast(object)->value(); | 221 Object* script = JSValue::cast(object)->value(); |
| 205 return Script::cast(script)->id(); | 222 return Script::cast(script)->id(); |
| 206 } | 223 } |
| 207 | 224 |
| 208 | 225 |
| 209 const AccessorDescriptor Accessors::ScriptId = { | 226 const AccessorDescriptor Accessors::ScriptId = { |
| 210 ScriptGetId, | 227 ScriptGetId, |
| 211 IllegalSetter, | 228 IllegalSetter, |
| 212 0 | 229 0 |
| 213 }; | 230 }; |
| 214 | 231 |
| 215 | 232 |
| 216 // | 233 // |
| 217 // Accessors::ScriptLineOffset | 234 // Accessors::ScriptLineOffset |
| 218 // | 235 // |
| 219 | 236 |
| 220 | 237 |
| 221 MaybeObject* Accessors::ScriptGetLineOffset(Object* object, void*) { | 238 MaybeObject* Accessors::ScriptGetLineOffset(Isolate* isolate, |
| 239 Object* object, |
| 240 void*) { |
| 222 Object* script = JSValue::cast(object)->value(); | 241 Object* script = JSValue::cast(object)->value(); |
| 223 return Script::cast(script)->line_offset(); | 242 return Script::cast(script)->line_offset(); |
| 224 } | 243 } |
| 225 | 244 |
| 226 | 245 |
| 227 const AccessorDescriptor Accessors::ScriptLineOffset = { | 246 const AccessorDescriptor Accessors::ScriptLineOffset = { |
| 228 ScriptGetLineOffset, | 247 ScriptGetLineOffset, |
| 229 IllegalSetter, | 248 IllegalSetter, |
| 230 0 | 249 0 |
| 231 }; | 250 }; |
| 232 | 251 |
| 233 | 252 |
| 234 // | 253 // |
| 235 // Accessors::ScriptColumnOffset | 254 // Accessors::ScriptColumnOffset |
| 236 // | 255 // |
| 237 | 256 |
| 238 | 257 |
| 239 MaybeObject* Accessors::ScriptGetColumnOffset(Object* object, void*) { | 258 MaybeObject* Accessors::ScriptGetColumnOffset(Isolate* isolate, |
| 259 Object* object, |
| 260 void*) { |
| 240 Object* script = JSValue::cast(object)->value(); | 261 Object* script = JSValue::cast(object)->value(); |
| 241 return Script::cast(script)->column_offset(); | 262 return Script::cast(script)->column_offset(); |
| 242 } | 263 } |
| 243 | 264 |
| 244 | 265 |
| 245 const AccessorDescriptor Accessors::ScriptColumnOffset = { | 266 const AccessorDescriptor Accessors::ScriptColumnOffset = { |
| 246 ScriptGetColumnOffset, | 267 ScriptGetColumnOffset, |
| 247 IllegalSetter, | 268 IllegalSetter, |
| 248 0 | 269 0 |
| 249 }; | 270 }; |
| 250 | 271 |
| 251 | 272 |
| 252 // | 273 // |
| 253 // Accessors::ScriptData | 274 // Accessors::ScriptData |
| 254 // | 275 // |
| 255 | 276 |
| 256 | 277 |
| 257 MaybeObject* Accessors::ScriptGetData(Object* object, void*) { | 278 MaybeObject* Accessors::ScriptGetData(Isolate* isolate, |
| 279 Object* object, |
| 280 void*) { |
| 258 Object* script = JSValue::cast(object)->value(); | 281 Object* script = JSValue::cast(object)->value(); |
| 259 return Script::cast(script)->data(); | 282 return Script::cast(script)->data(); |
| 260 } | 283 } |
| 261 | 284 |
| 262 | 285 |
| 263 const AccessorDescriptor Accessors::ScriptData = { | 286 const AccessorDescriptor Accessors::ScriptData = { |
| 264 ScriptGetData, | 287 ScriptGetData, |
| 265 IllegalSetter, | 288 IllegalSetter, |
| 266 0 | 289 0 |
| 267 }; | 290 }; |
| 268 | 291 |
| 269 | 292 |
| 270 // | 293 // |
| 271 // Accessors::ScriptType | 294 // Accessors::ScriptType |
| 272 // | 295 // |
| 273 | 296 |
| 274 | 297 |
| 275 MaybeObject* Accessors::ScriptGetType(Object* object, void*) { | 298 MaybeObject* Accessors::ScriptGetType(Isolate* isolate, |
| 299 Object* object, |
| 300 void*) { |
| 276 Object* script = JSValue::cast(object)->value(); | 301 Object* script = JSValue::cast(object)->value(); |
| 277 return Script::cast(script)->type(); | 302 return Script::cast(script)->type(); |
| 278 } | 303 } |
| 279 | 304 |
| 280 | 305 |
| 281 const AccessorDescriptor Accessors::ScriptType = { | 306 const AccessorDescriptor Accessors::ScriptType = { |
| 282 ScriptGetType, | 307 ScriptGetType, |
| 283 IllegalSetter, | 308 IllegalSetter, |
| 284 0 | 309 0 |
| 285 }; | 310 }; |
| 286 | 311 |
| 287 | 312 |
| 288 // | 313 // |
| 289 // Accessors::ScriptCompilationType | 314 // Accessors::ScriptCompilationType |
| 290 // | 315 // |
| 291 | 316 |
| 292 | 317 |
| 293 MaybeObject* Accessors::ScriptGetCompilationType(Object* object, void*) { | 318 MaybeObject* Accessors::ScriptGetCompilationType(Isolate* isolate, |
| 319 Object* object, |
| 320 void*) { |
| 294 Object* script = JSValue::cast(object)->value(); | 321 Object* script = JSValue::cast(object)->value(); |
| 295 return Smi::FromInt(Script::cast(script)->compilation_type()); | 322 return Smi::FromInt(Script::cast(script)->compilation_type()); |
| 296 } | 323 } |
| 297 | 324 |
| 298 | 325 |
| 299 const AccessorDescriptor Accessors::ScriptCompilationType = { | 326 const AccessorDescriptor Accessors::ScriptCompilationType = { |
| 300 ScriptGetCompilationType, | 327 ScriptGetCompilationType, |
| 301 IllegalSetter, | 328 IllegalSetter, |
| 302 0 | 329 0 |
| 303 }; | 330 }; |
| 304 | 331 |
| 305 | 332 |
| 306 // | 333 // |
| 307 // Accessors::ScriptGetLineEnds | 334 // Accessors::ScriptGetLineEnds |
| 308 // | 335 // |
| 309 | 336 |
| 310 | 337 |
| 311 MaybeObject* Accessors::ScriptGetLineEnds(Object* object, void*) { | 338 MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate, |
| 339 Object* object, |
| 340 void*) { |
| 312 JSValue* wrapper = JSValue::cast(object); | 341 JSValue* wrapper = JSValue::cast(object); |
| 313 Isolate* isolate = wrapper->GetIsolate(); | |
| 314 HandleScope scope(isolate); | 342 HandleScope scope(isolate); |
| 315 Handle<Script> script(Script::cast(wrapper->value()), isolate); | 343 Handle<Script> script(Script::cast(wrapper->value()), isolate); |
| 316 InitScriptLineEnds(script); | 344 InitScriptLineEnds(script); |
| 317 ASSERT(script->line_ends()->IsFixedArray()); | 345 ASSERT(script->line_ends()->IsFixedArray()); |
| 318 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 346 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 319 // We do not want anyone to modify this array from JS. | 347 // We do not want anyone to modify this array from JS. |
| 320 ASSERT(*line_ends == isolate->heap()->empty_fixed_array() || | 348 ASSERT(*line_ends == isolate->heap()->empty_fixed_array() || |
| 321 line_ends->map() == isolate->heap()->fixed_cow_array_map()); | 349 line_ends->map() == isolate->heap()->fixed_cow_array_map()); |
| 322 Handle<JSArray> js_array = | 350 Handle<JSArray> js_array = |
| 323 isolate->factory()->NewJSArrayWithElements(line_ends); | 351 isolate->factory()->NewJSArrayWithElements(line_ends); |
| 324 return *js_array; | 352 return *js_array; |
| 325 } | 353 } |
| 326 | 354 |
| 327 | 355 |
| 328 const AccessorDescriptor Accessors::ScriptLineEnds = { | 356 const AccessorDescriptor Accessors::ScriptLineEnds = { |
| 329 ScriptGetLineEnds, | 357 ScriptGetLineEnds, |
| 330 IllegalSetter, | 358 IllegalSetter, |
| 331 0 | 359 0 |
| 332 }; | 360 }; |
| 333 | 361 |
| 334 | 362 |
| 335 // | 363 // |
| 336 // Accessors::ScriptGetContextData | 364 // Accessors::ScriptGetContextData |
| 337 // | 365 // |
| 338 | 366 |
| 339 | 367 |
| 340 MaybeObject* Accessors::ScriptGetContextData(Object* object, void*) { | 368 MaybeObject* Accessors::ScriptGetContextData(Isolate* isolate, |
| 369 Object* object, |
| 370 void*) { |
| 341 Object* script = JSValue::cast(object)->value(); | 371 Object* script = JSValue::cast(object)->value(); |
| 342 return Script::cast(script)->context_data(); | 372 return Script::cast(script)->context_data(); |
| 343 } | 373 } |
| 344 | 374 |
| 345 | 375 |
| 346 const AccessorDescriptor Accessors::ScriptContextData = { | 376 const AccessorDescriptor Accessors::ScriptContextData = { |
| 347 ScriptGetContextData, | 377 ScriptGetContextData, |
| 348 IllegalSetter, | 378 IllegalSetter, |
| 349 0 | 379 0 |
| 350 }; | 380 }; |
| 351 | 381 |
| 352 | 382 |
| 353 // | 383 // |
| 354 // Accessors::ScriptGetEvalFromScript | 384 // Accessors::ScriptGetEvalFromScript |
| 355 // | 385 // |
| 356 | 386 |
| 357 | 387 |
| 358 MaybeObject* Accessors::ScriptGetEvalFromScript(Object* object, void*) { | 388 MaybeObject* Accessors::ScriptGetEvalFromScript(Isolate* isolate, |
| 389 Object* object, |
| 390 void*) { |
| 359 Object* script = JSValue::cast(object)->value(); | 391 Object* script = JSValue::cast(object)->value(); |
| 360 if (!Script::cast(script)->eval_from_shared()->IsUndefined()) { | 392 if (!Script::cast(script)->eval_from_shared()->IsUndefined()) { |
| 361 Handle<SharedFunctionInfo> eval_from_shared( | 393 Handle<SharedFunctionInfo> eval_from_shared( |
| 362 SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared())); | 394 SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared())); |
| 363 | 395 |
| 364 if (eval_from_shared->script()->IsScript()) { | 396 if (eval_from_shared->script()->IsScript()) { |
| 365 Handle<Script> eval_from_script(Script::cast(eval_from_shared->script())); | 397 Handle<Script> eval_from_script(Script::cast(eval_from_shared->script())); |
| 366 return *GetScriptWrapper(eval_from_script); | 398 return *GetScriptWrapper(eval_from_script); |
| 367 } | 399 } |
| 368 } | 400 } |
| 369 return HEAP->undefined_value(); | 401 return HEAP->undefined_value(); |
| 370 } | 402 } |
| 371 | 403 |
| 372 | 404 |
| 373 const AccessorDescriptor Accessors::ScriptEvalFromScript = { | 405 const AccessorDescriptor Accessors::ScriptEvalFromScript = { |
| 374 ScriptGetEvalFromScript, | 406 ScriptGetEvalFromScript, |
| 375 IllegalSetter, | 407 IllegalSetter, |
| 376 0 | 408 0 |
| 377 }; | 409 }; |
| 378 | 410 |
| 379 | 411 |
| 380 // | 412 // |
| 381 // Accessors::ScriptGetEvalFromScriptPosition | 413 // Accessors::ScriptGetEvalFromScriptPosition |
| 382 // | 414 // |
| 383 | 415 |
| 384 | 416 |
| 385 MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Object* object, void*) { | 417 MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Isolate* isolate, |
| 418 Object* object, |
| 419 void*) { |
| 386 Script* raw_script = Script::cast(JSValue::cast(object)->value()); | 420 Script* raw_script = Script::cast(JSValue::cast(object)->value()); |
| 387 HandleScope scope(raw_script->GetIsolate()); | 421 HandleScope scope(isolate); |
| 388 Handle<Script> script(raw_script); | 422 Handle<Script> script(raw_script); |
| 389 | 423 |
| 390 // If this is not a script compiled through eval there is no eval position. | 424 // If this is not a script compiled through eval there is no eval position. |
| 391 if (script->compilation_type() != Script::COMPILATION_TYPE_EVAL) { | 425 if (script->compilation_type() != Script::COMPILATION_TYPE_EVAL) { |
| 392 return script->GetHeap()->undefined_value(); | 426 return script->GetHeap()->undefined_value(); |
| 393 } | 427 } |
| 394 | 428 |
| 395 // Get the function from where eval was called and find the source position | 429 // Get the function from where eval was called and find the source position |
| 396 // from the instruction offset. | 430 // from the instruction offset. |
| 397 Handle<Code> code(SharedFunctionInfo::cast( | 431 Handle<Code> code(SharedFunctionInfo::cast( |
| 398 script->eval_from_shared())->code()); | 432 script->eval_from_shared())->code()); |
| 399 return Smi::FromInt(code->SourcePosition(code->instruction_start() + | 433 return Smi::FromInt(code->SourcePosition(code->instruction_start() + |
| 400 script->eval_from_instructions_offset()->value())); | 434 script->eval_from_instructions_offset()->value())); |
| 401 } | 435 } |
| 402 | 436 |
| 403 | 437 |
| 404 const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = { | 438 const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = { |
| 405 ScriptGetEvalFromScriptPosition, | 439 ScriptGetEvalFromScriptPosition, |
| 406 IllegalSetter, | 440 IllegalSetter, |
| 407 0 | 441 0 |
| 408 }; | 442 }; |
| 409 | 443 |
| 410 | 444 |
| 411 // | 445 // |
| 412 // Accessors::ScriptGetEvalFromFunctionName | 446 // Accessors::ScriptGetEvalFromFunctionName |
| 413 // | 447 // |
| 414 | 448 |
| 415 | 449 |
| 416 MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Object* object, void*) { | 450 MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Isolate* isolate, |
| 451 Object* object, |
| 452 void*) { |
| 417 Object* script = JSValue::cast(object)->value(); | 453 Object* script = JSValue::cast(object)->value(); |
| 418 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast( | 454 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast( |
| 419 Script::cast(script)->eval_from_shared())); | 455 Script::cast(script)->eval_from_shared())); |
| 420 | 456 |
| 421 | 457 |
| 422 // Find the name of the function calling eval. | 458 // Find the name of the function calling eval. |
| 423 if (!shared->name()->IsUndefined()) { | 459 if (!shared->name()->IsUndefined()) { |
| 424 return shared->name(); | 460 return shared->name(); |
| 425 } else { | 461 } else { |
| 426 return shared->inferred_name(); | 462 return shared->inferred_name(); |
| 427 } | 463 } |
| 428 } | 464 } |
| 429 | 465 |
| 430 | 466 |
| 431 const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = { | 467 const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = { |
| 432 ScriptGetEvalFromFunctionName, | 468 ScriptGetEvalFromFunctionName, |
| 433 IllegalSetter, | 469 IllegalSetter, |
| 434 0 | 470 0 |
| 435 }; | 471 }; |
| 436 | 472 |
| 437 | 473 |
| 438 // | 474 // |
| 439 // Accessors::FunctionPrototype | 475 // Accessors::FunctionPrototype |
| 440 // | 476 // |
| 441 | 477 |
| 442 | 478 |
| 443 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { | 479 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { |
| 444 CALL_HEAP_FUNCTION(function->GetIsolate(), | 480 CALL_HEAP_FUNCTION(function->GetIsolate(), |
| 445 Accessors::FunctionGetPrototype(*function, NULL), | 481 Accessors::FunctionGetPrototype(function->GetIsolate(), |
| 482 *function, |
| 483 NULL), |
| 446 Object); | 484 Object); |
| 447 } | 485 } |
| 448 | 486 |
| 449 | 487 |
| 450 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, | 488 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, |
| 451 Handle<Object> prototype) { | 489 Handle<Object> prototype) { |
| 452 ASSERT(function->should_have_prototype()); | 490 ASSERT(function->should_have_prototype()); |
| 453 CALL_HEAP_FUNCTION(function->GetIsolate(), | 491 CALL_HEAP_FUNCTION(function->GetIsolate(), |
| 454 Accessors::FunctionSetPrototype(*function, | 492 Accessors::FunctionSetPrototype(function->GetIsolate(), |
| 493 *function, |
| 455 *prototype, | 494 *prototype, |
| 456 NULL), | 495 NULL), |
| 457 Object); | 496 Object); |
| 458 } | 497 } |
| 459 | 498 |
| 460 | 499 |
| 461 MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { | 500 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, |
| 462 Isolate* isolate = Isolate::Current(); | 501 Object* object, |
| 502 void*) { |
| 463 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); | 503 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); |
| 464 if (function_raw == NULL) return isolate->heap()->undefined_value(); | 504 if (function_raw == NULL) return isolate->heap()->undefined_value(); |
| 465 while (!function_raw->should_have_prototype()) { | 505 while (!function_raw->should_have_prototype()) { |
| 466 function_raw = FindInstanceOf<JSFunction>(isolate, | 506 function_raw = FindInstanceOf<JSFunction>(isolate, |
| 467 function_raw->GetPrototype()); | 507 function_raw->GetPrototype()); |
| 468 // There has to be one because we hit the getter. | 508 // There has to be one because we hit the getter. |
| 469 ASSERT(function_raw != NULL); | 509 ASSERT(function_raw != NULL); |
| 470 } | 510 } |
| 471 | 511 |
| 472 if (!function_raw->has_prototype()) { | 512 if (!function_raw->has_prototype()) { |
| 473 HandleScope scope(isolate); | 513 HandleScope scope(isolate); |
| 474 Handle<JSFunction> function(function_raw); | 514 Handle<JSFunction> function(function_raw); |
| 475 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); | 515 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); |
| 476 JSFunction::SetPrototype(function, proto); | 516 JSFunction::SetPrototype(function, proto); |
| 477 function_raw = *function; | 517 function_raw = *function; |
| 478 } | 518 } |
| 479 return function_raw->prototype(); | 519 return function_raw->prototype(); |
| 480 } | 520 } |
| 481 | 521 |
| 482 | 522 |
| 483 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, | 523 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, |
| 524 JSObject* object, |
| 484 Object* value_raw, | 525 Object* value_raw, |
| 485 void*) { | 526 void*) { |
| 486 Isolate* isolate = object->GetIsolate(); | |
| 487 Heap* heap = isolate->heap(); | 527 Heap* heap = isolate->heap(); |
| 488 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); | 528 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); |
| 489 if (function_raw == NULL) return heap->undefined_value(); | 529 if (function_raw == NULL) return heap->undefined_value(); |
| 490 if (!function_raw->should_have_prototype()) { | 530 if (!function_raw->should_have_prototype()) { |
| 491 // Since we hit this accessor, object will have no prototype property. | 531 // Since we hit this accessor, object will have no prototype property. |
| 492 return object->SetLocalPropertyIgnoreAttributes(heap->prototype_string(), | 532 return object->SetLocalPropertyIgnoreAttributes(heap->prototype_string(), |
| 493 value_raw, | 533 value_raw, |
| 494 NONE); | 534 NONE); |
| 495 } | 535 } |
| 496 | 536 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 527 FunctionSetPrototype, | 567 FunctionSetPrototype, |
| 528 0 | 568 0 |
| 529 }; | 569 }; |
| 530 | 570 |
| 531 | 571 |
| 532 // | 572 // |
| 533 // Accessors::FunctionLength | 573 // Accessors::FunctionLength |
| 534 // | 574 // |
| 535 | 575 |
| 536 | 576 |
| 537 MaybeObject* Accessors::FunctionGetLength(Object* object, void*) { | 577 MaybeObject* Accessors::FunctionGetLength(Isolate* isolate, |
| 538 Isolate* isolate = Isolate::Current(); | 578 Object* object, |
| 579 void*) { |
| 539 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object); | 580 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object); |
| 540 if (function == NULL) return Smi::FromInt(0); | 581 if (function == NULL) return Smi::FromInt(0); |
| 541 // Check if already compiled. | 582 // Check if already compiled. |
| 542 if (function->shared()->is_compiled()) { | 583 if (function->shared()->is_compiled()) { |
| 543 return Smi::FromInt(function->shared()->length()); | 584 return Smi::FromInt(function->shared()->length()); |
| 544 } | 585 } |
| 545 // If the function isn't compiled yet, the length is not computed correctly | 586 // If the function isn't compiled yet, the length is not computed correctly |
| 546 // yet. Compile it now and return the right length. | 587 // yet. Compile it now and return the right length. |
| 547 HandleScope scope(isolate); | 588 HandleScope scope(isolate); |
| 548 Handle<JSFunction> handle(function); | 589 Handle<JSFunction> handle(function); |
| 549 if (JSFunction::CompileLazy(handle, KEEP_EXCEPTION)) { | 590 if (JSFunction::CompileLazy(handle, KEEP_EXCEPTION)) { |
| 550 return Smi::FromInt(handle->shared()->length()); | 591 return Smi::FromInt(handle->shared()->length()); |
| 551 } | 592 } |
| 552 return Failure::Exception(); | 593 return Failure::Exception(); |
| 553 } | 594 } |
| 554 | 595 |
| 555 | 596 |
| 556 const AccessorDescriptor Accessors::FunctionLength = { | 597 const AccessorDescriptor Accessors::FunctionLength = { |
| 557 FunctionGetLength, | 598 FunctionGetLength, |
| 558 ReadOnlySetAccessor, | 599 ReadOnlySetAccessor, |
| 559 0 | 600 0 |
| 560 }; | 601 }; |
| 561 | 602 |
| 562 | 603 |
| 563 // | 604 // |
| 564 // Accessors::FunctionName | 605 // Accessors::FunctionName |
| 565 // | 606 // |
| 566 | 607 |
| 567 | 608 |
| 568 MaybeObject* Accessors::FunctionGetName(Object* object, void*) { | 609 MaybeObject* Accessors::FunctionGetName(Isolate* isolate, |
| 569 Isolate* isolate = Isolate::Current(); | 610 Object* object, |
| 611 void*) { |
| 570 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); | 612 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); |
| 571 return holder == NULL | 613 return holder == NULL |
| 572 ? isolate->heap()->undefined_value() | 614 ? isolate->heap()->undefined_value() |
| 573 : holder->shared()->name(); | 615 : holder->shared()->name(); |
| 574 } | 616 } |
| 575 | 617 |
| 576 | 618 |
| 577 const AccessorDescriptor Accessors::FunctionName = { | 619 const AccessorDescriptor Accessors::FunctionName = { |
| 578 FunctionGetName, | 620 FunctionGetName, |
| 579 ReadOnlySetAccessor, | 621 ReadOnlySetAccessor, |
| 580 0 | 622 0 |
| 581 }; | 623 }; |
| 582 | 624 |
| 583 | 625 |
| 584 // | 626 // |
| 585 // Accessors::FunctionArguments | 627 // Accessors::FunctionArguments |
| 586 // | 628 // |
| 587 | 629 |
| 588 | 630 |
| 589 Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) { | 631 Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) { |
| 590 CALL_HEAP_FUNCTION(function->GetIsolate(), | 632 CALL_HEAP_FUNCTION(function->GetIsolate(), |
| 591 Accessors::FunctionGetArguments(*function, NULL), | 633 Accessors::FunctionGetArguments(function->GetIsolate(), |
| 634 *function, |
| 635 NULL), |
| 592 Object); | 636 Object); |
| 593 } | 637 } |
| 594 | 638 |
| 595 | 639 |
| 596 static MaybeObject* ConstructArgumentsObjectForInlinedFunction( | 640 static MaybeObject* ConstructArgumentsObjectForInlinedFunction( |
| 597 JavaScriptFrame* frame, | 641 JavaScriptFrame* frame, |
| 598 Handle<JSFunction> inlined_function, | 642 Handle<JSFunction> inlined_function, |
| 599 int inlined_frame_index) { | 643 int inlined_frame_index) { |
| 600 Isolate* isolate = inlined_function->GetIsolate(); | 644 Isolate* isolate = inlined_function->GetIsolate(); |
| 601 Factory* factory = isolate->factory(); | 645 Factory* factory = isolate->factory(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 613 array->set(i, *value); | 657 array->set(i, *value); |
| 614 } | 658 } |
| 615 arguments->set_elements(*array); | 659 arguments->set_elements(*array); |
| 616 args_slots.Dispose(); | 660 args_slots.Dispose(); |
| 617 | 661 |
| 618 // Return the freshly allocated arguments object. | 662 // Return the freshly allocated arguments object. |
| 619 return *arguments; | 663 return *arguments; |
| 620 } | 664 } |
| 621 | 665 |
| 622 | 666 |
| 623 MaybeObject* Accessors::FunctionGetArguments(Object* object, void*) { | 667 MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate, |
| 624 Isolate* isolate = Isolate::Current(); | 668 Object* object, |
| 669 void*) { |
| 625 HandleScope scope(isolate); | 670 HandleScope scope(isolate); |
| 626 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); | 671 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); |
| 627 if (holder == NULL) return isolate->heap()->undefined_value(); | 672 if (holder == NULL) return isolate->heap()->undefined_value(); |
| 628 Handle<JSFunction> function(holder, isolate); | 673 Handle<JSFunction> function(holder, isolate); |
| 629 | 674 |
| 630 if (function->shared()->native()) return isolate->heap()->null_value(); | 675 if (function->shared()->native()) return isolate->heap()->null_value(); |
| 631 // Find the top invocation of the function by traversing frames. | 676 // Find the top invocation of the function by traversing frames. |
| 632 List<JSFunction*> functions(2); | 677 List<JSFunction*> functions(2); |
| 633 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { | 678 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { |
| 634 JavaScriptFrame* frame = it.frame(); | 679 JavaScriptFrame* frame = it.frame(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 ASSERT(functions_.length() > 0); | 781 ASSERT(functions_.length() > 0); |
| 737 frame_iterator_.Advance(); | 782 frame_iterator_.Advance(); |
| 738 index_ = functions_.length() - 1; | 783 index_ = functions_.length() - 1; |
| 739 } | 784 } |
| 740 JavaScriptFrameIterator frame_iterator_; | 785 JavaScriptFrameIterator frame_iterator_; |
| 741 List<JSFunction*> functions_; | 786 List<JSFunction*> functions_; |
| 742 int index_; | 787 int index_; |
| 743 }; | 788 }; |
| 744 | 789 |
| 745 | 790 |
| 746 MaybeObject* Accessors::FunctionGetCaller(Object* object, void*) { | 791 MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate, |
| 747 Isolate* isolate = Isolate::Current(); | 792 Object* object, |
| 793 void*) { |
| 748 HandleScope scope(isolate); | 794 HandleScope scope(isolate); |
| 749 DisallowHeapAllocation no_allocation; | 795 DisallowHeapAllocation no_allocation; |
| 750 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); | 796 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); |
| 751 if (holder == NULL) return isolate->heap()->undefined_value(); | 797 if (holder == NULL) return isolate->heap()->undefined_value(); |
| 752 if (holder->shared()->native()) return isolate->heap()->null_value(); | 798 if (holder->shared()->native()) return isolate->heap()->null_value(); |
| 753 Handle<JSFunction> function(holder, isolate); | 799 Handle<JSFunction> function(holder, isolate); |
| 754 | 800 |
| 755 FrameFunctionIterator it(isolate, no_allocation); | 801 FrameFunctionIterator it(isolate, no_allocation); |
| 756 | 802 |
| 757 // Find the function from the frames. | 803 // Find the function from the frames. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 info->set_data(Smi::FromInt(index)); | 905 info->set_data(Smi::FromInt(index)); |
| 860 Handle<Object> getter = v8::FromCData(&ModuleGetExport); | 906 Handle<Object> getter = v8::FromCData(&ModuleGetExport); |
| 861 Handle<Object> setter = v8::FromCData(&ModuleSetExport); | 907 Handle<Object> setter = v8::FromCData(&ModuleSetExport); |
| 862 info->set_getter(*getter); | 908 info->set_getter(*getter); |
| 863 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 909 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
| 864 return info; | 910 return info; |
| 865 } | 911 } |
| 866 | 912 |
| 867 | 913 |
| 868 } } // namespace v8::internal | 914 } } // namespace v8::internal |
| OLD | NEW |