Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 Handle<String> name, | 47 Handle<String> name, |
| 48 AccessorGetterCallback getter, | 48 AccessorGetterCallback getter, |
| 49 AccessorSetterCallback setter, | 49 AccessorSetterCallback setter, |
| 50 PropertyAttributes attributes) { | 50 PropertyAttributes attributes) { |
| 51 Factory* factory = isolate->factory(); | 51 Factory* factory = isolate->factory(); |
| 52 Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo(); | 52 Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo(); |
| 53 info->set_property_attributes(attributes); | 53 info->set_property_attributes(attributes); |
| 54 info->set_all_can_read(true); | 54 info->set_all_can_read(true); |
| 55 info->set_all_can_write(true); | 55 info->set_all_can_write(true); |
| 56 info->set_prohibits_overwriting(false); | 56 info->set_prohibits_overwriting(false); |
| 57 info->set_name(*factory->length_string()); | 57 info->set_name(*name); |
| 58 info->set_property_attributes(attributes); | |
| 59 Handle<Object> get = v8::FromCData(isolate, getter); | 58 Handle<Object> get = v8::FromCData(isolate, getter); |
| 60 Handle<Object> set = v8::FromCData(isolate, setter); | 59 Handle<Object> set = v8::FromCData(isolate, setter); |
| 61 info->set_getter(*get); | 60 info->set_getter(*get); |
| 62 info->set_setter(*set); | 61 info->set_setter(*set); |
| 63 return info; | 62 return info; |
| 64 } | 63 } |
| 65 | 64 |
| 66 | 65 |
| 67 template <class C> | 66 template <class C> |
| 68 static C* FindInstanceOf(Isolate* isolate, Object* obj) { | 67 static C* FindInstanceOf(Isolate* isolate, Object* obj) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 Isolate* isolate, PropertyAttributes attributes) { | 286 Isolate* isolate, PropertyAttributes attributes) { |
| 288 return MakeAccessor(isolate, | 287 return MakeAccessor(isolate, |
| 289 isolate->factory()->length_string(), | 288 isolate->factory()->length_string(), |
| 290 &StringLengthGetter, | 289 &StringLengthGetter, |
| 291 &StringLengthSetter, | 290 &StringLengthSetter, |
| 292 attributes); | 291 attributes); |
| 293 } | 292 } |
| 294 | 293 |
| 295 | 294 |
| 296 // | 295 // |
| 296 // Accessors::ScriptColumnOffset | |
| 297 // | |
| 298 | |
| 299 | |
| 300 void Accessors::ScriptColumnOffsetGetter( | |
| 301 v8::Local<v8::String> name, | |
| 302 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
| 303 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
| 304 DisallowHeapAllocation no_allocation; | |
| 305 HandleScope scope(isolate); | |
| 306 Object* object = *Utils::OpenHandle(*info.This()); | |
| 307 Object* res = Script::cast(JSValue::cast(object)->value())->column_offset(); | |
| 308 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate))); | |
| 309 } | |
| 310 | |
| 311 | |
| 312 void Accessors::ScriptColumnOffsetSetter( | |
| 313 v8::Local<v8::String> name, | |
| 314 v8::Local<v8::Value> value, | |
| 315 const v8::PropertyCallbackInfo<void>& info) { | |
| 316 UNREACHABLE(); | |
| 317 } | |
| 318 | |
| 319 | |
| 320 Handle<AccessorInfo> Accessors::ScriptColumnOffsetInfo( | |
| 321 Isolate* isolate, PropertyAttributes attributes) { | |
| 322 Handle<String> name(isolate->factory()->InternalizeOneByteString( | |
| 323 STATIC_ASCII_VECTOR("column_offset"))); | |
| 324 return MakeAccessor(isolate, | |
| 325 name, | |
| 326 &ScriptColumnOffsetGetter, | |
| 327 &ScriptColumnOffsetSetter, | |
| 328 attributes); | |
| 329 } | |
| 330 | |
| 331 | |
| 332 // | |
| 333 // Accessors::ScriptId | |
| 334 // | |
| 335 | |
| 336 | |
| 337 void Accessors::ScriptIdGetter( | |
| 338 v8::Local<v8::String> name, | |
| 339 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
| 340 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
| 341 DisallowHeapAllocation no_allocation; | |
| 342 HandleScope scope(isolate); | |
| 343 Object* object = *Utils::OpenHandle(*info.This()); | |
| 344 Object* id = Script::cast(JSValue::cast(object)->value())->id(); | |
| 345 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(id, isolate))); | |
| 346 } | |
| 347 | |
| 348 | |
| 349 void Accessors::ScriptIdSetter( | |
| 350 v8::Local<v8::String> name, | |
| 351 v8::Local<v8::Value> value, | |
| 352 const v8::PropertyCallbackInfo<void>& info) { | |
| 353 UNREACHABLE(); | |
| 354 } | |
| 355 | |
| 356 | |
| 357 Handle<AccessorInfo> Accessors::ScriptIdInfo( | |
| 358 Isolate* isolate, PropertyAttributes attributes) { | |
| 359 Handle<String> name(isolate->factory()->InternalizeOneByteString( | |
| 360 STATIC_ASCII_VECTOR("id"))); | |
| 361 return MakeAccessor(isolate, | |
| 362 name, | |
| 363 &ScriptIdGetter, | |
| 364 &ScriptIdSetter, | |
| 365 attributes); | |
| 366 } | |
| 367 | |
| 368 | |
| 369 // | |
| 370 // Accessors::ScriptName | |
| 371 // | |
| 372 | |
| 373 | |
| 374 void Accessors::ScriptNameGetter( | |
| 375 v8::Local<v8::String> name, | |
| 376 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
| 377 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
| 378 DisallowHeapAllocation no_allocation; | |
| 379 HandleScope scope(isolate); | |
| 380 Object* object = *Utils::OpenHandle(*info.This()); | |
| 381 Object* source = Script::cast(JSValue::cast(object)->value())->name(); | |
| 382 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(source, isolate))); | |
| 383 } | |
| 384 | |
| 385 | |
| 386 void Accessors::ScriptNameSetter( | |
| 387 v8::Local<v8::String> name, | |
| 388 v8::Local<v8::Value> value, | |
| 389 const v8::PropertyCallbackInfo<void>& info) { | |
|
Yang
2014/04/15 14:50:35
You could have one single setter that's unreachabl
ulan
2014/04/15 14:55:19
I use one macro to access both the getter and the
| |
| 390 UNREACHABLE(); | |
| 391 } | |
| 392 | |
| 393 | |
| 394 Handle<AccessorInfo> Accessors::ScriptNameInfo( | |
| 395 Isolate* isolate, PropertyAttributes attributes) { | |
| 396 return MakeAccessor(isolate, | |
| 397 isolate->factory()->name_string(), | |
| 398 &ScriptNameGetter, | |
| 399 &ScriptNameSetter, | |
| 400 attributes); | |
| 401 } | |
| 402 | |
| 403 | |
| 404 // | |
| 297 // Accessors::ScriptSource | 405 // Accessors::ScriptSource |
| 298 // | 406 // |
| 299 | 407 |
| 300 | 408 |
| 301 MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, | 409 void Accessors::ScriptSourceGetter( |
| 302 Object* object, | 410 v8::Local<v8::String> name, |
| 303 void*) { | 411 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 304 Object* script = JSValue::cast(object)->value(); | 412 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 305 return Script::cast(script)->source(); | 413 DisallowHeapAllocation no_allocation; |
| 414 HandleScope scope(isolate); | |
| 415 Object* object = *Utils::OpenHandle(*info.This()); | |
| 416 Object* source = Script::cast(JSValue::cast(object)->value())->source(); | |
| 417 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(source, isolate))); | |
| 306 } | 418 } |
| 307 | 419 |
| 308 | 420 |
| 309 const AccessorDescriptor Accessors::ScriptSource = { | 421 void Accessors::ScriptSourceSetter( |
| 310 ScriptGetSource, | 422 v8::Local<v8::String> name, |
| 311 IllegalSetter, | 423 v8::Local<v8::Value> value, |
| 312 0 | 424 const v8::PropertyCallbackInfo<void>& info) { |
| 313 }; | 425 UNREACHABLE(); |
| 314 | |
| 315 | |
| 316 // | |
| 317 // Accessors::ScriptName | |
| 318 // | |
| 319 | |
| 320 | |
| 321 MaybeObject* Accessors::ScriptGetName(Isolate* isolate, | |
| 322 Object* object, | |
| 323 void*) { | |
| 324 Object* script = JSValue::cast(object)->value(); | |
| 325 return Script::cast(script)->name(); | |
| 326 } | 426 } |
| 327 | 427 |
| 328 | 428 |
| 329 const AccessorDescriptor Accessors::ScriptName = { | 429 Handle<AccessorInfo> Accessors::ScriptSourceInfo( |
| 330 ScriptGetName, | 430 Isolate* isolate, PropertyAttributes attributes) { |
| 331 IllegalSetter, | 431 return MakeAccessor(isolate, |
| 332 0 | 432 isolate->factory()->source_string(), |
| 333 }; | 433 &ScriptSourceGetter, |
| 334 | 434 &ScriptSourceSetter, |
| 335 | 435 attributes); |
| 336 // | |
| 337 // Accessors::ScriptId | |
| 338 // | |
| 339 | |
| 340 | |
| 341 MaybeObject* Accessors::ScriptGetId(Isolate* isolate, Object* object, void*) { | |
| 342 Object* script = JSValue::cast(object)->value(); | |
| 343 return Script::cast(script)->id(); | |
| 344 } | 436 } |
| 345 | 437 |
| 346 | 438 |
| 347 const AccessorDescriptor Accessors::ScriptId = { | |
| 348 ScriptGetId, | |
| 349 IllegalSetter, | |
| 350 0 | |
| 351 }; | |
| 352 | |
| 353 | |
| 354 // | 439 // |
| 355 // Accessors::ScriptLineOffset | 440 // Accessors::ScriptLineOffset |
| 356 // | 441 // |
| 357 | 442 |
| 358 | 443 |
| 359 MaybeObject* Accessors::ScriptGetLineOffset(Isolate* isolate, | 444 void Accessors::ScriptLineOffsetGetter( |
| 360 Object* object, | 445 v8::Local<v8::String> name, |
| 361 void*) { | 446 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 362 Object* script = JSValue::cast(object)->value(); | 447 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 363 return Script::cast(script)->line_offset(); | 448 DisallowHeapAllocation no_allocation; |
| 449 HandleScope scope(isolate); | |
| 450 Object* object = *Utils::OpenHandle(*info.This()); | |
| 451 Object* res = Script::cast(JSValue::cast(object)->value())->line_offset(); | |
| 452 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate))); | |
| 364 } | 453 } |
| 365 | 454 |
| 366 | 455 |
| 367 const AccessorDescriptor Accessors::ScriptLineOffset = { | 456 void Accessors::ScriptLineOffsetSetter( |
| 368 ScriptGetLineOffset, | 457 v8::Local<v8::String> name, |
| 369 IllegalSetter, | 458 v8::Local<v8::Value> value, |
| 370 0 | 459 const v8::PropertyCallbackInfo<void>& info) { |
| 371 }; | 460 UNREACHABLE(); |
| 461 } | |
| 462 | |
| 463 | |
| 464 Handle<AccessorInfo> Accessors::ScriptLineOffsetInfo( | |
| 465 Isolate* isolate, PropertyAttributes attributes) { | |
| 466 Handle<String> name(isolate->factory()->InternalizeOneByteString( | |
| 467 STATIC_ASCII_VECTOR("line_offset"))); | |
| 468 return MakeAccessor(isolate, | |
| 469 name, | |
| 470 &ScriptLineOffsetGetter, | |
| 471 &ScriptLineOffsetSetter, | |
| 472 attributes); | |
| 473 } | |
| 372 | 474 |
| 373 | 475 |
| 374 // | 476 // |
| 375 // Accessors::ScriptColumnOffset | |
| 376 // | |
| 377 | |
| 378 | |
| 379 MaybeObject* Accessors::ScriptGetColumnOffset(Isolate* isolate, | |
| 380 Object* object, | |
| 381 void*) { | |
| 382 Object* script = JSValue::cast(object)->value(); | |
| 383 return Script::cast(script)->column_offset(); | |
| 384 } | |
| 385 | |
| 386 | |
| 387 const AccessorDescriptor Accessors::ScriptColumnOffset = { | |
| 388 ScriptGetColumnOffset, | |
| 389 IllegalSetter, | |
| 390 0 | |
| 391 }; | |
| 392 | |
| 393 | |
| 394 // | |
| 395 // Accessors::ScriptType | 477 // Accessors::ScriptType |
| 396 // | 478 // |
| 397 | 479 |
| 398 | 480 |
| 399 MaybeObject* Accessors::ScriptGetType(Isolate* isolate, | 481 MaybeObject* Accessors::ScriptGetType(Isolate* isolate, |
| 400 Object* object, | 482 Object* object, |
| 401 void*) { | 483 void*) { |
| 402 Object* script = JSValue::cast(object)->value(); | 484 Object* script = JSValue::cast(object)->value(); |
| 403 return Script::cast(script)->type(); | 485 return Script::cast(script)->type(); |
| 404 } | 486 } |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 info->set_data(Smi::FromInt(index)); | 1090 info->set_data(Smi::FromInt(index)); |
| 1009 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1091 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
| 1010 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1092 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
| 1011 info->set_getter(*getter); | 1093 info->set_getter(*getter); |
| 1012 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1094 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
| 1013 return info; | 1095 return info; |
| 1014 } | 1096 } |
| 1015 | 1097 |
| 1016 | 1098 |
| 1017 } } // namespace v8::internal | 1099 } } // namespace v8::internal |
| OLD | NEW |