OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ | 90 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ |
91 EXCEPTION_BAILOUT_CHECK_GENERIC( \ | 91 EXCEPTION_BAILOUT_CHECK_GENERIC( \ |
92 isolate, value, isolate->FireCallCompletedCallback();) | 92 isolate, value, isolate->FireCallCompletedCallback();) |
93 | 93 |
94 | 94 |
95 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ | 95 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
96 EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) | 96 EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) |
97 | 97 |
98 | 98 |
99 #define PREPARE_FOR_EXECUTION_GENERIC(context, function_name, bailout_value, \ | 99 #define PREPARE_FOR_EXECUTION_GENERIC(context, function_name, bailout_value, \ |
100 HandleScopeClass) \ | 100 HandleScopeClass, do_callback) \ |
101 auto isolate = context.IsEmpty() \ | 101 auto isolate = context.IsEmpty() \ |
102 ? i::Isolate::Current() \ | 102 ? i::Isolate::Current() \ |
103 : reinterpret_cast<i::Isolate*>(context->GetIsolate()); \ | 103 : reinterpret_cast<i::Isolate*>(context->GetIsolate()); \ |
104 if (IsExecutionTerminatingCheck(isolate)) { \ | 104 if (IsExecutionTerminatingCheck(isolate)) { \ |
105 return bailout_value; \ | 105 return bailout_value; \ |
106 } \ | 106 } \ |
107 HandleScopeClass handle_scope(isolate); \ | 107 HandleScopeClass handle_scope(isolate); \ |
108 CallDepthScope call_depth_scope(isolate, context, false); \ | 108 CallDepthScope call_depth_scope(isolate, context, do_callback); \ |
109 LOG_API(isolate, function_name); \ | 109 LOG_API(isolate, function_name); \ |
110 ENTER_V8(isolate); \ | 110 ENTER_V8(isolate); \ |
111 bool has_pending_exception = false | 111 bool has_pending_exception = false |
112 | 112 |
113 | 113 |
114 #define PREPARE_FOR_EXECUTION(context, function_name, T) \ | 114 #define PREPARE_FOR_EXECUTION(context, function_name, T) \ |
115 PREPARE_FOR_EXECUTION_GENERIC(context, function_name, MaybeLocal<T>(), \ | 115 PREPARE_FOR_EXECUTION_GENERIC(context, function_name, MaybeLocal<T>(), \ |
116 InternalEscapableScope) | 116 InternalEscapableScope, false) |
| 117 |
| 118 |
| 119 #define PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, function_name, T) \ |
| 120 PREPARE_FOR_EXECUTION_GENERIC(context, function_name, MaybeLocal<T>(), \ |
| 121 InternalEscapableScope, true) |
117 | 122 |
118 | 123 |
119 #define PREPARE_FOR_EXECUTION_PRIMITIVE(context, function_name, T) \ | 124 #define PREPARE_FOR_EXECUTION_PRIMITIVE(context, function_name, T) \ |
120 PREPARE_FOR_EXECUTION_GENERIC(context, function_name, Nothing<T>(), \ | 125 PREPARE_FOR_EXECUTION_GENERIC(context, function_name, Nothing<T>(), \ |
121 i::HandleScope) | 126 i::HandleScope, false) |
122 | 127 |
123 | 128 |
124 #define EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, value) \ | 129 #define EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, value) \ |
125 do { \ | 130 do { \ |
126 if (has_pending_exception) { \ | 131 if (has_pending_exception) { \ |
127 call_depth_scope.Escape(); \ | 132 call_depth_scope.Escape(); \ |
128 return value; \ | 133 return value; \ |
129 } \ | 134 } \ |
130 } while (false) | 135 } while (false) |
131 | 136 |
(...skipping 3435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3567 RETURN_ESCAPED(Utils::ToLocal(result)); | 3572 RETURN_ESCAPED(Utils::ToLocal(result)); |
3568 } | 3573 } |
3569 | 3574 |
3570 | 3575 |
3571 Local<Array> v8::Object::GetOwnPropertyNames() { | 3576 Local<Array> v8::Object::GetOwnPropertyNames() { |
3572 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 3577 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
3573 RETURN_TO_LOCAL_UNCHECKED(GetOwnPropertyNames(context), Array); | 3578 RETURN_TO_LOCAL_UNCHECKED(GetOwnPropertyNames(context), Array); |
3574 } | 3579 } |
3575 | 3580 |
3576 | 3581 |
3577 Local<String> v8::Object::ObjectProtoToString() { | 3582 MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) { |
3578 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); | 3583 auto self = Utils::OpenHandle(this); |
3579 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 3584 auto isolate = self->GetIsolate(); |
3580 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", | 3585 auto v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
3581 return Local<v8::String>()); | 3586 i::Handle<i::Object> name(self->class_name(), isolate); |
3582 ENTER_V8(i_isolate); | |
3583 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | |
3584 | |
3585 i::Handle<i::Object> name(self->class_name(), i_isolate); | |
3586 i::Handle<i::Object> tag; | 3587 i::Handle<i::Object> tag; |
3587 | 3588 |
3588 // Native implementation of Object.prototype.toString (v8natives.js): | 3589 // Native implementation of Object.prototype.toString (v8natives.js): |
3589 // var c = %_ClassOf(this); | 3590 // var c = %_ClassOf(this); |
3590 // if (c === 'Arguments') c = 'Object'; | 3591 // if (c === 'Arguments') c = 'Object'; |
3591 // return "[object " + c + "]"; | 3592 // return "[object " + c + "]"; |
3592 | 3593 |
3593 if (!name->IsString()) { | 3594 if (!name->IsString()) { |
3594 return v8::String::NewFromUtf8(isolate, "[object ]"); | 3595 return v8::String::NewFromUtf8(v8_isolate, "[object ]"); |
3595 } else { | 3596 } |
3596 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); | 3597 auto class_name = i::Handle<i::String>::cast(name); |
3597 if (i::String::Equals(class_name, | 3598 if (i::String::Equals(class_name, isolate->factory()->Arguments_string())) { |
3598 i_isolate->factory()->Arguments_string())) { | 3599 return v8::String::NewFromUtf8(v8_isolate, "[object Object]"); |
3599 return v8::String::NewFromUtf8(isolate, "[object Object]"); | 3600 } |
3600 } else { | 3601 if (internal::FLAG_harmony_tostring) { |
3601 if (internal::FLAG_harmony_tostring) { | 3602 PREPARE_FOR_EXECUTION(context, "v8::Object::ObjectProtoToString()", String); |
3602 i::Handle<i::Symbol> toStringTag = | 3603 auto toStringTag = isolate->factory()->to_string_tag_symbol(); |
3603 Utils::OpenHandle(*Symbol::GetToStringTag(isolate)); | 3604 has_pending_exception = !i::Runtime::GetObjectProperty( |
3604 EXCEPTION_PREAMBLE(i_isolate); | 3605 isolate, self, toStringTag).ToHandle(&tag); |
3605 has_pending_exception = | 3606 RETURN_ON_FAILED_EXECUTION(String); |
3606 !i::Runtime::GetObjectProperty(i_isolate, self, toStringTag) | 3607 if (tag->IsString()) { |
3607 .ToHandle(&tag); | 3608 class_name = i::Handle<i::String>::cast(tag).EscapeFrom(&handle_scope); |
3608 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>()); | |
3609 | |
3610 if (tag->IsString()) { | |
3611 class_name = i::Handle<i::String>::cast(tag); | |
3612 } | |
3613 } | |
3614 const char* prefix = "[object "; | |
3615 Local<String> str = Utils::ToLocal(class_name); | |
3616 const char* postfix = "]"; | |
3617 | |
3618 int prefix_len = i::StrLength(prefix); | |
3619 int str_len = str->Utf8Length(); | |
3620 int postfix_len = i::StrLength(postfix); | |
3621 | |
3622 int buf_len = prefix_len + str_len + postfix_len; | |
3623 i::ScopedVector<char> buf(buf_len); | |
3624 | |
3625 // Write prefix. | |
3626 char* ptr = buf.start(); | |
3627 i::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize); | |
3628 ptr += prefix_len; | |
3629 | |
3630 // Write real content. | |
3631 str->WriteUtf8(ptr, str_len); | |
3632 ptr += str_len; | |
3633 | |
3634 // Write postfix. | |
3635 i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize); | |
3636 | |
3637 // Copy the buffer into a heap-allocated string and return it. | |
3638 Local<String> result = v8::String::NewFromUtf8( | |
3639 isolate, buf.start(), String::kNormalString, buf_len); | |
3640 return result; | |
3641 } | 3609 } |
3642 } | 3610 } |
| 3611 const char* prefix = "[object "; |
| 3612 Local<String> str = Utils::ToLocal(class_name); |
| 3613 const char* postfix = "]"; |
| 3614 |
| 3615 int prefix_len = i::StrLength(prefix); |
| 3616 int str_len = str->Utf8Length(); |
| 3617 int postfix_len = i::StrLength(postfix); |
| 3618 |
| 3619 int buf_len = prefix_len + str_len + postfix_len; |
| 3620 i::ScopedVector<char> buf(buf_len); |
| 3621 |
| 3622 // Write prefix. |
| 3623 char* ptr = buf.start(); |
| 3624 i::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
| 3625 ptr += prefix_len; |
| 3626 |
| 3627 // Write real content. |
| 3628 str->WriteUtf8(ptr, str_len); |
| 3629 ptr += str_len; |
| 3630 |
| 3631 // Write postfix. |
| 3632 i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
| 3633 |
| 3634 // Copy the buffer into a heap-allocated string and return it. |
| 3635 return v8::String::NewFromUtf8(v8_isolate, buf.start(), String::kNormalString, |
| 3636 buf_len); |
3643 } | 3637 } |
3644 | 3638 |
3645 | 3639 |
| 3640 Local<String> v8::Object::ObjectProtoToString() { |
| 3641 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 3642 RETURN_TO_LOCAL_UNCHECKED(ObjectProtoToString(context), String); |
| 3643 } |
| 3644 |
| 3645 |
3646 Local<String> v8::Object::GetConstructorName() { | 3646 Local<String> v8::Object::GetConstructorName() { |
3647 auto self = Utils::OpenHandle(this); | 3647 auto self = Utils::OpenHandle(this); |
3648 i::Handle<i::String> name(self->constructor_name()); | 3648 i::Handle<i::String> name(self->constructor_name()); |
3649 return Utils::ToLocal(name); | 3649 return Utils::ToLocal(name); |
3650 } | 3650 } |
3651 | 3651 |
3652 | 3652 |
3653 Maybe<bool> v8::Object::Delete(Local<Context> context, Local<Value> key) { | 3653 Maybe<bool> v8::Object::Delete(Local<Context> context, Local<Value> key) { |
3654 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Delete()", bool); | 3654 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Delete()", bool); |
3655 auto self = Utils::OpenHandle(this); | 3655 auto self = Utils::OpenHandle(this); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4030 i::Deoptimizer::DeoptimizeGlobalObject(*obj); | 4030 i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
4031 | 4031 |
4032 i::Handle<i::Map> new_map = | 4032 i::Handle<i::Map> new_map = |
4033 i::Map::Copy(i::Handle<i::Map>(obj->map()), "APITurnOnAccessCheck"); | 4033 i::Map::Copy(i::Handle<i::Map>(obj->map()), "APITurnOnAccessCheck"); |
4034 new_map->set_is_access_check_needed(true); | 4034 new_map->set_is_access_check_needed(true); |
4035 i::JSObject::MigrateToMap(obj, new_map); | 4035 i::JSObject::MigrateToMap(obj, new_map); |
4036 } | 4036 } |
4037 | 4037 |
4038 | 4038 |
4039 Local<v8::Object> v8::Object::Clone() { | 4039 Local<v8::Object> v8::Object::Clone() { |
4040 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4040 auto self = Utils::OpenHandle(this); |
4041 ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); | 4041 auto isolate = self->GetIsolate(); |
4042 ENTER_V8(isolate); | 4042 ENTER_V8(isolate); |
4043 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4043 auto result = isolate->factory()->CopyJSObject(self); |
4044 EXCEPTION_PREAMBLE(isolate); | 4044 CHECK(!result.is_null()); |
4045 i::Handle<i::JSObject> result = isolate->factory()->CopyJSObject(self); | |
4046 has_pending_exception = result.is_null(); | |
4047 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); | |
4048 return Utils::ToLocal(result); | 4045 return Utils::ToLocal(result); |
4049 } | 4046 } |
4050 | 4047 |
4051 | 4048 |
4052 Local<v8::Context> v8::Object::CreationContext() { | 4049 Local<v8::Context> v8::Object::CreationContext() { |
4053 auto self = Utils::OpenHandle(this); | 4050 auto self = Utils::OpenHandle(this); |
4054 auto context = handle(self->GetCreationContext()); | 4051 auto context = handle(self->GetCreationContext()); |
4055 return Utils::ToLocal(context); | 4052 return Utils::ToLocal(context); |
4056 } | 4053 } |
4057 | 4054 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4137 object, | 4134 object, |
4138 GetElementsKindFromExternalArrayType(array_type)); | 4135 GetElementsKindFromExternalArrayType(array_type)); |
4139 | 4136 |
4140 i::JSObject::SetMapAndElements(object, external_array_map, array); | 4137 i::JSObject::SetMapAndElements(object, external_array_map, array); |
4141 } | 4138 } |
4142 | 4139 |
4143 } // namespace | 4140 } // namespace |
4144 | 4141 |
4145 | 4142 |
4146 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { | 4143 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
4147 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4144 auto self = Utils::OpenHandle(this); |
4148 ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); | 4145 auto isolate = self->GetIsolate(); |
4149 ENTER_V8(isolate); | 4146 ENTER_V8(isolate); |
4150 i::HandleScope scope(isolate); | 4147 i::HandleScope scope(isolate); |
4151 if (!Utils::ApiCheck(length >= 0 && | 4148 if (!Utils::ApiCheck(length >= 0 && |
4152 length <= i::ExternalUint8ClampedArray::kMaxLength, | 4149 length <= i::ExternalUint8ClampedArray::kMaxLength, |
4153 "v8::Object::SetIndexedPropertiesToPixelData()", | 4150 "v8::Object::SetIndexedPropertiesToPixelData()", |
4154 "length exceeds max acceptable value")) { | 4151 "length exceeds max acceptable value")) { |
4155 return; | 4152 return; |
4156 } | 4153 } |
4157 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | |
4158 if (!Utils::ApiCheck(!self->IsJSArray(), | 4154 if (!Utils::ApiCheck(!self->IsJSArray(), |
4159 "v8::Object::SetIndexedPropertiesToPixelData()", | 4155 "v8::Object::SetIndexedPropertiesToPixelData()", |
4160 "JSArray is not supported")) { | 4156 "JSArray is not supported")) { |
4161 return; | 4157 return; |
4162 } | 4158 } |
4163 PrepareExternalArrayElements(self, data, kExternalUint8ClampedArray, length); | 4159 PrepareExternalArrayElements(self, data, kExternalUint8ClampedArray, length); |
4164 } | 4160 } |
4165 | 4161 |
4166 | 4162 |
4167 bool v8::Object::HasIndexedPropertiesInPixelData() { | 4163 bool v8::Object::HasIndexedPropertiesInPixelData() { |
4168 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4164 auto self = Utils::OpenHandle(this); |
4169 ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", | |
4170 return false); | |
4171 return self->HasExternalUint8ClampedElements(); | 4165 return self->HasExternalUint8ClampedElements(); |
4172 } | 4166 } |
4173 | 4167 |
4174 | 4168 |
4175 uint8_t* v8::Object::GetIndexedPropertiesPixelData() { | 4169 uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
4176 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4170 auto self = Utils::OpenHandle(this); |
4177 ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", | |
4178 return NULL); | |
4179 if (self->HasExternalUint8ClampedElements()) { | 4171 if (self->HasExternalUint8ClampedElements()) { |
4180 return i::ExternalUint8ClampedArray::cast(self->elements())-> | 4172 return i::ExternalUint8ClampedArray::cast(self->elements())-> |
4181 external_uint8_clamped_pointer(); | 4173 external_uint8_clamped_pointer(); |
4182 } else { | |
4183 return NULL; | |
4184 } | 4174 } |
| 4175 return nullptr; |
4185 } | 4176 } |
4186 | 4177 |
4187 | 4178 |
4188 int v8::Object::GetIndexedPropertiesPixelDataLength() { | 4179 int v8::Object::GetIndexedPropertiesPixelDataLength() { |
4189 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4180 auto self = Utils::OpenHandle(this); |
4190 ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", | |
4191 return -1); | |
4192 if (self->HasExternalUint8ClampedElements()) { | 4181 if (self->HasExternalUint8ClampedElements()) { |
4193 return i::ExternalUint8ClampedArray::cast(self->elements())->length(); | 4182 return i::ExternalUint8ClampedArray::cast(self->elements())->length(); |
4194 } else { | |
4195 return -1; | |
4196 } | 4183 } |
| 4184 return -1; |
4197 } | 4185 } |
4198 | 4186 |
4199 | 4187 |
4200 void v8::Object::SetIndexedPropertiesToExternalArrayData( | 4188 void v8::Object::SetIndexedPropertiesToExternalArrayData( |
4201 void* data, | 4189 void* data, |
4202 ExternalArrayType array_type, | 4190 ExternalArrayType array_type, |
4203 int length) { | 4191 int length) { |
4204 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4192 auto self = Utils::OpenHandle(this); |
4205 ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); | 4193 auto isolate = self->GetIsolate(); |
4206 ENTER_V8(isolate); | 4194 ENTER_V8(isolate); |
4207 i::HandleScope scope(isolate); | 4195 i::HandleScope scope(isolate); |
4208 if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, | 4196 if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, |
4209 "v8::Object::SetIndexedPropertiesToExternalArrayData()", | 4197 "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
4210 "length exceeds max acceptable value")) { | 4198 "length exceeds max acceptable value")) { |
4211 return; | 4199 return; |
4212 } | 4200 } |
4213 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | |
4214 if (!Utils::ApiCheck(!self->IsJSArray(), | 4201 if (!Utils::ApiCheck(!self->IsJSArray(), |
4215 "v8::Object::SetIndexedPropertiesToExternalArrayData()", | 4202 "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
4216 "JSArray is not supported")) { | 4203 "JSArray is not supported")) { |
4217 return; | 4204 return; |
4218 } | 4205 } |
4219 PrepareExternalArrayElements(self, data, array_type, length); | 4206 PrepareExternalArrayElements(self, data, array_type, length); |
4220 } | 4207 } |
4221 | 4208 |
4222 | 4209 |
4223 bool v8::Object::HasIndexedPropertiesInExternalArrayData() { | 4210 bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
4224 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4211 auto self = Utils::OpenHandle(this); |
4225 ON_BAILOUT(self->GetIsolate(), | |
4226 "v8::HasIndexedPropertiesInExternalArrayData()", | |
4227 return false); | |
4228 return self->HasExternalArrayElements(); | 4212 return self->HasExternalArrayElements(); |
4229 } | 4213 } |
4230 | 4214 |
4231 | 4215 |
4232 void* v8::Object::GetIndexedPropertiesExternalArrayData() { | 4216 void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
4233 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4217 auto self = Utils::OpenHandle(this); |
4234 ON_BAILOUT(self->GetIsolate(), | |
4235 "v8::GetIndexedPropertiesExternalArrayData()", | |
4236 return NULL); | |
4237 if (self->HasExternalArrayElements()) { | 4218 if (self->HasExternalArrayElements()) { |
4238 return i::ExternalArray::cast(self->elements())->external_pointer(); | 4219 return i::ExternalArray::cast(self->elements())->external_pointer(); |
4239 } else { | |
4240 return NULL; | |
4241 } | 4220 } |
| 4221 return nullptr; |
4242 } | 4222 } |
4243 | 4223 |
4244 | 4224 |
4245 ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { | 4225 ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
4246 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4226 auto self = Utils::OpenHandle(this); |
4247 ON_BAILOUT(self->GetIsolate(), | |
4248 "v8::GetIndexedPropertiesExternalArrayDataType()", | |
4249 return static_cast<ExternalArrayType>(-1)); | |
4250 switch (self->elements()->map()->instance_type()) { | 4227 switch (self->elements()->map()->instance_type()) { |
4251 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 4228 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
4252 case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \ | 4229 case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \ |
4253 return kExternal##Type##Array; | 4230 return kExternal##Type##Array; |
4254 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 4231 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
4255 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 4232 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
4256 default: | 4233 default: |
4257 return static_cast<ExternalArrayType>(-1); | 4234 return static_cast<ExternalArrayType>(-1); |
4258 } | 4235 } |
4259 } | 4236 } |
4260 | 4237 |
4261 | 4238 |
4262 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { | 4239 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
4263 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 4240 auto self = Utils::OpenHandle(this); |
4264 ON_BAILOUT(self->GetIsolate(), | |
4265 "v8::GetIndexedPropertiesExternalArrayDataLength()", | |
4266 return 0); | |
4267 if (self->HasExternalArrayElements()) { | 4241 if (self->HasExternalArrayElements()) { |
4268 return i::ExternalArray::cast(self->elements())->length(); | 4242 return i::ExternalArray::cast(self->elements())->length(); |
4269 } else { | |
4270 return -1; | |
4271 } | 4243 } |
| 4244 return -1; |
4272 } | 4245 } |
4273 | 4246 |
4274 | 4247 |
4275 bool v8::Object::IsCallable() { | 4248 bool v8::Object::IsCallable() { |
4276 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4249 auto self = Utils::OpenHandle(this); |
4277 ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); | 4250 return self->IsCallable(); |
4278 ENTER_V8(isolate); | |
4279 i::HandleScope scope(isolate); | |
4280 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | |
4281 return obj->IsCallable(); | |
4282 } | 4251 } |
4283 | 4252 |
4284 | 4253 |
4285 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv, | 4254 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, |
4286 int argc, | 4255 Handle<Value> recv, int argc, |
4287 v8::Handle<v8::Value> argv[]) { | 4256 Handle<Value> argv[]) { |
4288 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4257 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, "v8::Object::CallAsFunction()", |
4289 ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", | 4258 Value); |
4290 return Local<v8::Value>()); | |
4291 LOG_API(isolate, "Object::CallAsFunction"); | |
4292 ENTER_V8(isolate); | |
4293 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4259 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4294 i::HandleScope scope(isolate); | 4260 auto self = Utils::OpenHandle(this); |
4295 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | 4261 auto recv_obj = Utils::OpenHandle(*recv); |
4296 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); | |
4297 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); | 4262 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
4298 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4263 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4299 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); | 4264 i::Handle<i::JSFunction> fun; |
4300 if (obj->IsJSFunction()) { | 4265 if (self->IsJSFunction()) { |
4301 fun = i::Handle<i::JSFunction>::cast(obj); | 4266 fun = i::Handle<i::JSFunction>::cast(self); |
4302 } else { | 4267 } else { |
4303 EXCEPTION_PREAMBLE(isolate); | |
4304 i::Handle<i::Object> delegate; | 4268 i::Handle<i::Object> delegate; |
4305 has_pending_exception = !i::Execution::TryGetFunctionDelegate( | 4269 has_pending_exception = !i::Execution::TryGetFunctionDelegate(isolate, self) |
4306 isolate, obj).ToHandle(&delegate); | 4270 .ToHandle(&delegate); |
4307 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); | 4271 RETURN_ON_FAILED_EXECUTION(Value); |
4308 fun = i::Handle<i::JSFunction>::cast(delegate); | 4272 fun = i::Handle<i::JSFunction>::cast(delegate); |
4309 recv_obj = obj; | 4273 recv_obj = self; |
4310 } | 4274 } |
4311 EXCEPTION_PREAMBLE(isolate); | 4275 Local<Value> result; |
4312 i::Handle<i::Object> returned; | 4276 has_pending_exception = |
4313 has_pending_exception = !i::Execution::Call( | 4277 !ToLocal<Value>( |
4314 isolate, fun, recv_obj, argc, args, true).ToHandle(&returned); | 4278 i::Execution::Call(isolate, fun, recv_obj, argc, args, true), |
4315 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); | 4279 &result); |
4316 return Utils::ToLocal(scope.CloseAndEscape(returned)); | 4280 RETURN_ON_FAILED_EXECUTION(Value); |
| 4281 RETURN_ESCAPED(result); |
| 4282 } |
| 4283 |
| 4284 |
| 4285 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv, int argc, |
| 4286 v8::Handle<v8::Value> argv[]) { |
| 4287 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 4288 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); |
| 4289 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), |
| 4290 Value); |
| 4291 } |
| 4292 |
| 4293 |
| 4294 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, |
| 4295 Local<Value> argv[]) { |
| 4296 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, |
| 4297 "v8::Object::CallAsConstructor()", Value); |
| 4298 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
| 4299 auto self = Utils::OpenHandle(this); |
| 4300 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 4301 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
| 4302 if (self->IsJSFunction()) { |
| 4303 auto fun = i::Handle<i::JSFunction>::cast(self); |
| 4304 Local<Value> result; |
| 4305 has_pending_exception = |
| 4306 !ToLocal<Value>(i::Execution::New(fun, argc, args), &result); |
| 4307 RETURN_ON_FAILED_EXECUTION(Value); |
| 4308 RETURN_ESCAPED(result); |
| 4309 } |
| 4310 i::Handle<i::Object> delegate; |
| 4311 has_pending_exception = !i::Execution::TryGetConstructorDelegate( |
| 4312 isolate, self).ToHandle(&delegate); |
| 4313 RETURN_ON_FAILED_EXECUTION(Value); |
| 4314 if (!delegate->IsUndefined()) { |
| 4315 auto fun = i::Handle<i::JSFunction>::cast(delegate); |
| 4316 Local<Value> result; |
| 4317 has_pending_exception = |
| 4318 !ToLocal<Value>(i::Execution::Call(isolate, fun, self, argc, args), |
| 4319 &result); |
| 4320 RETURN_ON_FAILED_EXECUTION(Value); |
| 4321 DCHECK(!delegate->IsUndefined()); |
| 4322 RETURN_ESCAPED(result); |
| 4323 } |
| 4324 return MaybeLocal<Value>(); |
4317 } | 4325 } |
4318 | 4326 |
4319 | 4327 |
4320 Local<v8::Value> Object::CallAsConstructor(int argc, | 4328 Local<v8::Value> Object::CallAsConstructor(int argc, |
4321 v8::Handle<v8::Value> argv[]) { | 4329 v8::Handle<v8::Value> argv[]) { |
4322 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4330 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4323 ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", | 4331 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); |
4324 return Local<v8::Object>()); | 4332 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
4325 LOG_API(isolate, "Object::CallAsConstructor"); | |
4326 ENTER_V8(isolate); | |
4327 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | |
4328 i::HandleScope scope(isolate); | |
4329 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | |
4330 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); | |
4331 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | |
4332 if (obj->IsJSFunction()) { | |
4333 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); | |
4334 EXCEPTION_PREAMBLE(isolate); | |
4335 i::Handle<i::Object> returned; | |
4336 has_pending_exception = !i::Execution::New( | |
4337 fun, argc, args).ToHandle(&returned); | |
4338 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); | |
4339 return Utils::ToLocal(scope.CloseAndEscape( | |
4340 i::Handle<i::JSObject>::cast(returned))); | |
4341 } | |
4342 EXCEPTION_PREAMBLE(isolate); | |
4343 i::Handle<i::Object> delegate; | |
4344 has_pending_exception = !i::Execution::TryGetConstructorDelegate( | |
4345 isolate, obj).ToHandle(&delegate); | |
4346 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); | |
4347 if (!delegate->IsUndefined()) { | |
4348 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); | |
4349 EXCEPTION_PREAMBLE(isolate); | |
4350 i::Handle<i::Object> returned; | |
4351 has_pending_exception = !i::Execution::Call( | |
4352 isolate, fun, obj, argc, args).ToHandle(&returned); | |
4353 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); | |
4354 DCHECK(!delegate->IsUndefined()); | |
4355 return Utils::ToLocal(scope.CloseAndEscape(returned)); | |
4356 } | |
4357 return Local<v8::Object>(); | |
4358 } | 4333 } |
4359 | 4334 |
4360 | 4335 |
4361 Local<Function> Function::New(Isolate* v8_isolate, | 4336 Local<Function> Function::New(Isolate* v8_isolate, |
4362 FunctionCallback callback, | 4337 FunctionCallback callback, |
4363 Local<Value> data, | 4338 Local<Value> data, |
4364 int length) { | 4339 int length) { |
4365 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 4340 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
4366 LOG_API(isolate, "Function::New"); | 4341 LOG_API(isolate, "Function::New"); |
4367 ENTER_V8(isolate); | 4342 ENTER_V8(isolate); |
(...skipping 3638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8006 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7981 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8007 Address callback_address = | 7982 Address callback_address = |
8008 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7983 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8009 VMState<EXTERNAL> state(isolate); | 7984 VMState<EXTERNAL> state(isolate); |
8010 ExternalCallbackScope call_scope(isolate, callback_address); | 7985 ExternalCallbackScope call_scope(isolate, callback_address); |
8011 callback(info); | 7986 callback(info); |
8012 } | 7987 } |
8013 | 7988 |
8014 | 7989 |
8015 } } // namespace v8::internal | 7990 } } // namespace v8::internal |
OLD | NEW |