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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 int dep_count, | 534 int dep_count, |
535 const char** deps, | 535 const char** deps, |
536 int source_length) | 536 int source_length) |
537 : name_(name), | 537 : name_(name), |
538 source_length_(source_length >= 0 ? | 538 source_length_(source_length >= 0 ? |
539 source_length : | 539 source_length : |
540 (source ? static_cast<int>(strlen(source)) : 0)), | 540 (source ? static_cast<int>(strlen(source)) : 0)), |
541 source_(source, source_length_), | 541 source_(source, source_length_), |
542 dep_count_(dep_count), | 542 dep_count_(dep_count), |
543 deps_(deps), | 543 deps_(deps), |
544 auto_enable_(false) { | 544 auto_enable_(false) { } |
545 CHECK(source != NULL || source_length_ == 0); | |
546 } | |
547 | 545 |
548 | 546 |
549 v8::Handle<Primitive> Undefined() { | 547 v8::Handle<Primitive> Undefined() { |
550 i::Isolate* isolate = i::Isolate::Current(); | 548 i::Isolate* isolate = i::Isolate::Current(); |
551 if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { | 549 if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { |
552 return v8::Handle<v8::Primitive>(); | 550 return v8::Handle<v8::Primitive>(); |
553 } | 551 } |
554 return v8::Handle<Primitive>(ToApi<Primitive>( | 552 return v8::Handle<Primitive>(ToApi<Primitive>( |
555 isolate->factory()->undefined_value())); | 553 isolate->factory()->undefined_value())); |
556 } | 554 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 } | 756 } |
759 | 757 |
760 // Content of 'last_context' could be NULL. | 758 // Content of 'last_context' could be NULL. |
761 i::Context* last_context = | 759 i::Context* last_context = |
762 isolate->handle_scope_implementer()->RestoreContext(); | 760 isolate->handle_scope_implementer()->RestoreContext(); |
763 isolate->set_context(last_context); | 761 isolate->set_context(last_context); |
764 isolate->set_context_exit_happened(true); | 762 isolate->set_context_exit_happened(true); |
765 } | 763 } |
766 | 764 |
767 | 765 |
768 void Context::SetData(v8::Handle<Value> data) { | 766 void Context::SetData(v8::Handle<String> data) { |
769 i::Handle<i::Context> env = Utils::OpenHandle(this); | 767 i::Handle<i::Context> env = Utils::OpenHandle(this); |
770 i::Isolate* isolate = env->GetIsolate(); | 768 i::Isolate* isolate = env->GetIsolate(); |
771 if (IsDeadCheck(isolate, "v8::Context::SetData()")) return; | 769 if (IsDeadCheck(isolate, "v8::Context::SetData()")) return; |
772 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); | 770 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
773 ASSERT(env->IsNativeContext()); | 771 ASSERT(env->IsNativeContext()); |
774 if (env->IsNativeContext()) { | 772 if (env->IsNativeContext()) { |
775 env->set_data(*raw_data); | 773 env->set_data(*raw_data); |
776 } | 774 } |
777 } | 775 } |
778 | 776 |
779 | 777 |
780 v8::Local<v8::Value> Context::GetData() { | 778 v8::Local<v8::Value> Context::GetData() { |
781 i::Handle<i::Context> env = Utils::OpenHandle(this); | 779 i::Handle<i::Context> env = Utils::OpenHandle(this); |
782 i::Isolate* isolate = env->GetIsolate(); | 780 i::Isolate* isolate = env->GetIsolate(); |
783 if (IsDeadCheck(isolate, "v8::Context::GetData()")) { | 781 if (IsDeadCheck(isolate, "v8::Context::GetData()")) { |
| 782 return v8::Local<Value>(); |
| 783 } |
| 784 i::Object* raw_result = NULL; |
| 785 ASSERT(env->IsNativeContext()); |
| 786 if (env->IsNativeContext()) { |
| 787 raw_result = env->data(); |
| 788 } else { |
784 return Local<Value>(); | 789 return Local<Value>(); |
785 } | 790 } |
786 ASSERT(env->IsNativeContext()); | 791 i::Handle<i::Object> result(raw_result, isolate); |
787 if (!env->IsNativeContext()) { | |
788 return Local<Value>(); | |
789 } | |
790 i::Handle<i::Object> result(env->data(), isolate); | |
791 return Utils::ToLocal(result); | 792 return Utils::ToLocal(result); |
792 } | 793 } |
793 | 794 |
794 | 795 |
795 i::Object** v8::HandleScope::RawClose(i::Object** value) { | 796 i::Object** v8::HandleScope::RawClose(i::Object** value) { |
796 if (!ApiCheck(!is_closed_, | 797 if (!ApiCheck(!is_closed_, |
797 "v8::HandleScope::Close()", | 798 "v8::HandleScope::Close()", |
798 "Local scope has already been closed")) { | 799 "Local scope has already been closed")) { |
799 return 0; | 800 return 0; |
800 } | 801 } |
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 } | 3395 } |
3395 | 3396 |
3396 } // namespace | 3397 } // namespace |
3397 | 3398 |
3398 | 3399 |
3399 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { | 3400 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
3400 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3401 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3401 ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); | 3402 ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
3402 ENTER_V8(isolate); | 3403 ENTER_V8(isolate); |
3403 i::HandleScope scope(isolate); | 3404 i::HandleScope scope(isolate); |
3404 if (!ApiCheck(length >= 0 && length <= i::ExternalPixelArray::kMaxLength, | 3405 if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength, |
3405 "v8::Object::SetIndexedPropertiesToPixelData()", | 3406 "v8::Object::SetIndexedPropertiesToPixelData()", |
3406 "length exceeds max acceptable value")) { | 3407 "length exceeds max acceptable value")) { |
3407 return; | 3408 return; |
3408 } | 3409 } |
3409 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3410 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3410 if (!ApiCheck(!self->IsJSArray(), | 3411 if (!ApiCheck(!self->IsJSArray(), |
3411 "v8::Object::SetIndexedPropertiesToPixelData()", | 3412 "v8::Object::SetIndexedPropertiesToPixelData()", |
3412 "JSArray is not supported")) { | 3413 "JSArray is not supported")) { |
3413 return; | 3414 return; |
3414 } | 3415 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3450 | 3451 |
3451 | 3452 |
3452 void v8::Object::SetIndexedPropertiesToExternalArrayData( | 3453 void v8::Object::SetIndexedPropertiesToExternalArrayData( |
3453 void* data, | 3454 void* data, |
3454 ExternalArrayType array_type, | 3455 ExternalArrayType array_type, |
3455 int length) { | 3456 int length) { |
3456 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3457 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3457 ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); | 3458 ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
3458 ENTER_V8(isolate); | 3459 ENTER_V8(isolate); |
3459 i::HandleScope scope(isolate); | 3460 i::HandleScope scope(isolate); |
3460 if (!ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, | 3461 if (!ApiCheck(length <= i::ExternalArray::kMaxLength, |
3461 "v8::Object::SetIndexedPropertiesToExternalArrayData()", | 3462 "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
3462 "length exceeds max acceptable value")) { | 3463 "length exceeds max acceptable value")) { |
3463 return; | 3464 return; |
3464 } | 3465 } |
3465 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3466 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3466 if (!ApiCheck(!self->IsJSArray(), | 3467 if (!ApiCheck(!self->IsJSArray(), |
3467 "v8::Object::SetIndexedPropertiesToExternalArrayData()", | 3468 "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
3468 "JSArray is not supported")) { | 3469 "JSArray is not supported")) { |
3469 return; | 3470 return; |
3470 } | 3471 } |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4079 if (i::StringShape(*str).IsExternalTwoByte()) { | 4080 if (i::StringShape(*str).IsExternalTwoByte()) { |
4080 const void* resource = | 4081 const void* resource = |
4081 i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); | 4082 i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
4082 expected = reinterpret_cast<const ExternalStringResource*>(resource); | 4083 expected = reinterpret_cast<const ExternalStringResource*>(resource); |
4083 } else { | 4084 } else { |
4084 expected = NULL; | 4085 expected = NULL; |
4085 } | 4086 } |
4086 CHECK_EQ(expected, value); | 4087 CHECK_EQ(expected, value); |
4087 } | 4088 } |
4088 | 4089 |
4089 void v8::String::VerifyExternalStringResourceBase( | |
4090 v8::String::ExternalStringResourceBase* value, Encoding encoding) const { | |
4091 i::Handle<i::String> str = Utils::OpenHandle(this); | |
4092 const v8::String::ExternalStringResourceBase* expected; | |
4093 Encoding expectedEncoding; | |
4094 if (i::StringShape(*str).IsExternalAscii()) { | |
4095 const void* resource = | |
4096 i::Handle<i::ExternalAsciiString>::cast(str)->resource(); | |
4097 expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); | |
4098 expectedEncoding = ASCII_ENCODING; | |
4099 } else if (i::StringShape(*str).IsExternalTwoByte()) { | |
4100 const void* resource = | |
4101 i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); | |
4102 expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); | |
4103 expectedEncoding = TWO_BYTE_ENCODING; | |
4104 } else { | |
4105 expected = NULL; | |
4106 expectedEncoding = str->IsAsciiRepresentation() ? ASCII_ENCODING | |
4107 : TWO_BYTE_ENCODING; | |
4108 } | |
4109 CHECK_EQ(expected, value); | |
4110 CHECK_EQ(expectedEncoding, encoding); | |
4111 } | |
4112 | 4090 |
4113 const v8::String::ExternalAsciiStringResource* | 4091 const v8::String::ExternalAsciiStringResource* |
4114 v8::String::GetExternalAsciiStringResource() const { | 4092 v8::String::GetExternalAsciiStringResource() const { |
4115 i::Handle<i::String> str = Utils::OpenHandle(this); | 4093 i::Handle<i::String> str = Utils::OpenHandle(this); |
4116 if (IsDeadCheck(str->GetIsolate(), | 4094 if (IsDeadCheck(str->GetIsolate(), |
4117 "v8::String::GetExternalAsciiStringResource()")) { | 4095 "v8::String::GetExternalAsciiStringResource()")) { |
4118 return NULL; | 4096 return NULL; |
4119 } | 4097 } |
4120 if (i::StringShape(*str).IsExternalAscii()) { | 4098 if (i::StringShape(*str).IsExternalAscii()) { |
4121 const void* resource = | 4099 const void* resource = |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4592 return false; | 4570 return false; |
4593 } | 4571 } |
4594 ENTER_V8(isolate); | 4572 ENTER_V8(isolate); |
4595 i::Object** ctx = reinterpret_cast<i::Object**>(this); | 4573 i::Object** ctx = reinterpret_cast<i::Object**>(this); |
4596 i::Handle<i::Context> context = | 4574 i::Handle<i::Context> context = |
4597 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | 4575 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
4598 return !context->allow_code_gen_from_strings()->IsFalse(); | 4576 return !context->allow_code_gen_from_strings()->IsFalse(); |
4599 } | 4577 } |
4600 | 4578 |
4601 | 4579 |
4602 void Context::SetErrorMessageForCodeGenerationFromStrings( | |
4603 Handle<String> error) { | |
4604 i::Isolate* isolate = i::Isolate::Current(); | |
4605 if (IsDeadCheck(isolate, | |
4606 "v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) { | |
4607 return; | |
4608 } | |
4609 ENTER_V8(isolate); | |
4610 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
4611 i::Handle<i::Context> context = | |
4612 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
4613 i::Handle<i::Object> error_handle = Utils::OpenHandle(*error); | |
4614 context->set_error_message_for_code_gen_from_strings(*error_handle); | |
4615 } | |
4616 | |
4617 | |
4618 void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) { | 4580 void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) { |
4619 i::GlobalHandles::SetWrapperClassId(global_handle, class_id); | 4581 i::GlobalHandles::SetWrapperClassId(global_handle, class_id); |
4620 } | 4582 } |
4621 | 4583 |
4622 | 4584 |
4623 Local<v8::Object> ObjectTemplate::NewInstance() { | 4585 Local<v8::Object> ObjectTemplate::NewInstance() { |
4624 i::Isolate* isolate = i::Isolate::Current(); | 4586 i::Isolate* isolate = i::Isolate::Current(); |
4625 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", | 4587 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
4626 return Local<v8::Object>()); | 4588 return Local<v8::Object>()); |
4627 LOG_API(isolate, "ObjectTemplate::NewInstance"); | 4589 LOG_API(isolate, "ObjectTemplate::NewInstance"); |
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6590 | 6552 |
6591 v->VisitPointers(blocks_.first(), first_block_limit_); | 6553 v->VisitPointers(blocks_.first(), first_block_limit_); |
6592 | 6554 |
6593 for (int i = 1; i < blocks_.length(); i++) { | 6555 for (int i = 1; i < blocks_.length(); i++) { |
6594 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6556 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
6595 } | 6557 } |
6596 } | 6558 } |
6597 | 6559 |
6598 | 6560 |
6599 } } // namespace v8::internal | 6561 } } // namespace v8::internal |
OLD | NEW |