OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
11 #include "src/accessors.h" | 11 #include "src/accessors.h" |
12 #include "src/allocation-site-scopes.h" | 12 #include "src/allocation-site-scopes.h" |
13 #include "src/api.h" | 13 #include "src/api.h" |
| 14 #include "src/api-natives.h" |
14 #include "src/arguments.h" | 15 #include "src/arguments.h" |
15 #include "src/base/bits.h" | 16 #include "src/base/bits.h" |
16 #include "src/base/utils/random-number-generator.h" | 17 #include "src/base/utils/random-number-generator.h" |
17 #include "src/bootstrapper.h" | 18 #include "src/bootstrapper.h" |
18 #include "src/code-stubs.h" | 19 #include "src/code-stubs.h" |
19 #include "src/codegen.h" | 20 #include "src/codegen.h" |
20 #include "src/compilation-dependencies.h" | 21 #include "src/compilation-dependencies.h" |
21 #include "src/compiler.h" | 22 #include "src/compiler.h" |
22 #include "src/date.h" | 23 #include "src/date.h" |
23 #include "src/debug/debug.h" | 24 #include "src/debug/debug.h" |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 return ReadAbsentProperty(isolate, receiver, name, language_mode); | 1169 return ReadAbsentProperty(isolate, receiver, name, language_mode); |
1169 } | 1170 } |
1170 Handle<Object> return_value = v8::Utils::OpenHandle(*result); | 1171 Handle<Object> return_value = v8::Utils::OpenHandle(*result); |
1171 return_value->VerifyApiCallResultType(); | 1172 return_value->VerifyApiCallResultType(); |
1172 // Rebox handle before return. | 1173 // Rebox handle before return. |
1173 return handle(*return_value, isolate); | 1174 return handle(*return_value, isolate); |
1174 } | 1175 } |
1175 | 1176 |
1176 // Regular accessor. | 1177 // Regular accessor. |
1177 Handle<Object> getter(AccessorPair::cast(*structure)->getter(), isolate); | 1178 Handle<Object> getter(AccessorPair::cast(*structure)->getter(), isolate); |
1178 if (getter->IsCallable()) { | 1179 if (getter->IsFunctionTemplateInfo()) { |
| 1180 auto result = Builtins::InvokeApiFunction( |
| 1181 Handle<FunctionTemplateInfo>::cast(getter), receiver, 0, nullptr); |
| 1182 if (isolate->has_pending_exception()) { |
| 1183 return MaybeHandle<Object>(); |
| 1184 } |
| 1185 Handle<Object> return_value; |
| 1186 if (result.ToHandle(&return_value)) { |
| 1187 return_value->VerifyApiCallResultType(); |
| 1188 return handle(*return_value, isolate); |
| 1189 } |
| 1190 } else if (getter->IsCallable()) { |
1179 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 1191 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
1180 return Object::GetPropertyWithDefinedGetter( | 1192 return Object::GetPropertyWithDefinedGetter( |
1181 receiver, Handle<JSReceiver>::cast(getter)); | 1193 receiver, Handle<JSReceiver>::cast(getter)); |
1182 } | 1194 } |
1183 // Getter is not a function. | 1195 // Getter is not a function. |
1184 return ReadAbsentProperty(isolate, receiver, it->GetName(), language_mode); | 1196 return ReadAbsentProperty(isolate, receiver, it->GetName(), language_mode); |
1185 } | 1197 } |
1186 | 1198 |
1187 | 1199 |
1188 bool AccessorInfo::IsCompatibleReceiverMap(Isolate* isolate, | 1200 bool AccessorInfo::IsCompatibleReceiverMap(Isolate* isolate, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name)); | 1238 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name)); |
1227 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder, | 1239 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder, |
1228 should_throw); | 1240 should_throw); |
1229 args.Call(call_fun, v8::Utils::ToLocal(name), v8::Utils::ToLocal(value)); | 1241 args.Call(call_fun, v8::Utils::ToLocal(name), v8::Utils::ToLocal(value)); |
1230 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); | 1242 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); |
1231 return Just(true); | 1243 return Just(true); |
1232 } | 1244 } |
1233 | 1245 |
1234 // Regular accessor. | 1246 // Regular accessor. |
1235 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); | 1247 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); |
1236 if (setter->IsCallable()) { | 1248 if (setter->IsFunctionTemplateInfo()) { |
| 1249 Handle<Object> argv[] = {value}; |
| 1250 auto result = |
| 1251 Builtins::InvokeApiFunction(Handle<FunctionTemplateInfo>::cast(setter), |
| 1252 receiver, arraysize(argv), argv); |
| 1253 if (isolate->has_pending_exception()) { |
| 1254 return Nothing<bool>(); |
| 1255 } |
| 1256 return Just(true); |
| 1257 } else if (setter->IsCallable()) { |
1237 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 1258 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
1238 return SetPropertyWithDefinedSetter( | 1259 return SetPropertyWithDefinedSetter( |
1239 receiver, Handle<JSReceiver>::cast(setter), value, should_throw); | 1260 receiver, Handle<JSReceiver>::cast(setter), value, should_throw); |
1240 } | 1261 } |
1241 | 1262 |
1242 RETURN_FAILURE(isolate, should_throw, | 1263 RETURN_FAILURE(isolate, should_throw, |
1243 NewTypeError(MessageTemplate::kNoSetterInCallback, | 1264 NewTypeError(MessageTemplate::kNoSetterInCallback, |
1244 it->GetName(), it->GetHolder<JSObject>())); | 1265 it->GetName(), it->GetHolder<JSObject>())); |
1245 } | 1266 } |
1246 | 1267 |
(...skipping 6022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7269 return Nothing<bool>(); | 7290 return Nothing<bool>(); |
7270 } | 7291 } |
7271 desc->set_value(value); | 7292 desc->set_value(value); |
7272 // 5b. Set D.[[Writable]] to the value of X's [[Writable]] attribute | 7293 // 5b. Set D.[[Writable]] to the value of X's [[Writable]] attribute |
7273 desc->set_writable((attrs & READ_ONLY) == 0); | 7294 desc->set_writable((attrs & READ_ONLY) == 0); |
7274 } else { | 7295 } else { |
7275 // 6. Else X is an accessor property, so | 7296 // 6. Else X is an accessor property, so |
7276 Handle<AccessorPair> accessors = | 7297 Handle<AccessorPair> accessors = |
7277 Handle<AccessorPair>::cast(it->GetAccessors()); | 7298 Handle<AccessorPair>::cast(it->GetAccessors()); |
7278 // 6a. Set D.[[Get]] to the value of X's [[Get]] attribute. | 7299 // 6a. Set D.[[Get]] to the value of X's [[Get]] attribute. |
7279 desc->set_get(handle(accessors->GetComponent(ACCESSOR_GETTER), isolate)); | 7300 desc->set_get(AccessorPair::GetComponent(accessors, ACCESSOR_GETTER)); |
7280 // 6b. Set D.[[Set]] to the value of X's [[Set]] attribute. | 7301 // 6b. Set D.[[Set]] to the value of X's [[Set]] attribute. |
7281 desc->set_set(handle(accessors->GetComponent(ACCESSOR_SETTER), isolate)); | 7302 desc->set_set(AccessorPair::GetComponent(accessors, ACCESSOR_SETTER)); |
7282 } | 7303 } |
7283 | 7304 |
7284 // 7. Set D.[[Enumerable]] to the value of X's [[Enumerable]] attribute. | 7305 // 7. Set D.[[Enumerable]] to the value of X's [[Enumerable]] attribute. |
7285 desc->set_enumerable((attrs & DONT_ENUM) == 0); | 7306 desc->set_enumerable((attrs & DONT_ENUM) == 0); |
7286 // 8. Set D.[[Configurable]] to the value of X's [[Configurable]] attribute. | 7307 // 8. Set D.[[Configurable]] to the value of X's [[Configurable]] attribute. |
7287 desc->set_configurable((attrs & DONT_DELETE) == 0); | 7308 desc->set_configurable((attrs & DONT_DELETE) == 0); |
7288 // 9. Return D. | 7309 // 9. Return D. |
7289 DCHECK(PropertyDescriptor::IsAccessorDescriptor(desc) != | 7310 DCHECK(PropertyDescriptor::IsAccessorDescriptor(desc) != |
7290 PropertyDescriptor::IsDataDescriptor(desc)); | 7311 PropertyDescriptor::IsDataDescriptor(desc)); |
7291 return Just(true); | 7312 return Just(true); |
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9058 bool preexists = false; | 9079 bool preexists = false; |
9059 if (is_observed) { | 9080 if (is_observed) { |
9060 CHECK(GetPropertyAttributes(it).IsJust()); | 9081 CHECK(GetPropertyAttributes(it).IsJust()); |
9061 preexists = it->IsFound(); | 9082 preexists = it->IsFound(); |
9062 if (preexists && (it->state() == LookupIterator::DATA || | 9083 if (preexists && (it->state() == LookupIterator::DATA || |
9063 it->GetAccessors()->IsAccessorInfo())) { | 9084 it->GetAccessors()->IsAccessorInfo())) { |
9064 old_value = GetProperty(it).ToHandleChecked(); | 9085 old_value = GetProperty(it).ToHandleChecked(); |
9065 } | 9086 } |
9066 } | 9087 } |
9067 | 9088 |
9068 DCHECK(getter->IsCallable() || getter->IsUndefined() || getter->IsNull()); | 9089 DCHECK(getter->IsCallable() || getter->IsUndefined() || getter->IsNull() || |
9069 DCHECK(setter->IsCallable() || setter->IsUndefined() || setter->IsNull()); | 9090 getter->IsFunctionTemplateInfo()); |
| 9091 DCHECK(setter->IsCallable() || setter->IsUndefined() || setter->IsNull() || |
| 9092 getter->IsFunctionTemplateInfo()); |
9070 // At least one of the accessors needs to be a new value. | 9093 // At least one of the accessors needs to be a new value. |
9071 DCHECK(!getter->IsNull() || !setter->IsNull()); | 9094 DCHECK(!getter->IsNull() || !setter->IsNull()); |
9072 if (!getter->IsNull()) { | 9095 if (!getter->IsNull()) { |
9073 it->TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes); | 9096 it->TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes); |
9074 } | 9097 } |
9075 if (!setter->IsNull()) { | 9098 if (!setter->IsNull()) { |
9076 it->TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes); | 9099 it->TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes); |
9077 } | 9100 } |
9078 | 9101 |
9079 if (is_observed) { | 9102 if (is_observed) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9158 case LookupIterator::JSPROXY: | 9181 case LookupIterator::JSPROXY: |
9159 return isolate->factory()->undefined_value(); | 9182 return isolate->factory()->undefined_value(); |
9160 | 9183 |
9161 case LookupIterator::INTEGER_INDEXED_EXOTIC: | 9184 case LookupIterator::INTEGER_INDEXED_EXOTIC: |
9162 return isolate->factory()->undefined_value(); | 9185 return isolate->factory()->undefined_value(); |
9163 case LookupIterator::DATA: | 9186 case LookupIterator::DATA: |
9164 continue; | 9187 continue; |
9165 case LookupIterator::ACCESSOR: { | 9188 case LookupIterator::ACCESSOR: { |
9166 Handle<Object> maybe_pair = it.GetAccessors(); | 9189 Handle<Object> maybe_pair = it.GetAccessors(); |
9167 if (maybe_pair->IsAccessorPair()) { | 9190 if (maybe_pair->IsAccessorPair()) { |
9168 return handle( | 9191 return AccessorPair::GetComponent( |
9169 AccessorPair::cast(*maybe_pair)->GetComponent(component), | 9192 Handle<AccessorPair>::cast(maybe_pair), component); |
9170 isolate); | |
9171 } | 9193 } |
9172 } | 9194 } |
9173 } | 9195 } |
9174 } | 9196 } |
9175 | 9197 |
9176 return isolate->factory()->undefined_value(); | 9198 return isolate->factory()->undefined_value(); |
9177 } | 9199 } |
9178 | 9200 |
9179 | 9201 |
9180 Object* JSObject::SlowReverseLookup(Object* value) { | 9202 Object* JSObject::SlowReverseLookup(Object* value) { |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10971 } | 10993 } |
10972 | 10994 |
10973 | 10995 |
10974 Handle<AccessorPair> AccessorPair::Copy(Handle<AccessorPair> pair) { | 10996 Handle<AccessorPair> AccessorPair::Copy(Handle<AccessorPair> pair) { |
10975 Handle<AccessorPair> copy = pair->GetIsolate()->factory()->NewAccessorPair(); | 10997 Handle<AccessorPair> copy = pair->GetIsolate()->factory()->NewAccessorPair(); |
10976 copy->set_getter(pair->getter()); | 10998 copy->set_getter(pair->getter()); |
10977 copy->set_setter(pair->setter()); | 10999 copy->set_setter(pair->setter()); |
10978 return copy; | 11000 return copy; |
10979 } | 11001 } |
10980 | 11002 |
10981 | 11003 Handle<Object> AccessorPair::GetComponent(Handle<AccessorPair> accessor_pair, |
10982 Object* AccessorPair::GetComponent(AccessorComponent component) { | 11004 AccessorComponent component) { |
10983 Object* accessor = get(component); | 11005 Object* accessor = accessor_pair->get(component); |
10984 return accessor->IsTheHole() ? GetHeap()->undefined_value() : accessor; | 11006 if (accessor->IsFunctionTemplateInfo()) { |
| 11007 return ApiNatives::InstantiateFunction( |
| 11008 handle(FunctionTemplateInfo::cast(accessor))) |
| 11009 .ToHandleChecked(); |
| 11010 } |
| 11011 Isolate* isolate = accessor_pair->GetIsolate(); |
| 11012 if (accessor->IsTheHole()) { |
| 11013 return isolate->factory()->undefined_value(); |
| 11014 } |
| 11015 return handle(accessor, isolate); |
10985 } | 11016 } |
10986 | 11017 |
10987 | |
10988 Handle<DeoptimizationInputData> DeoptimizationInputData::New( | 11018 Handle<DeoptimizationInputData> DeoptimizationInputData::New( |
10989 Isolate* isolate, int deopt_entry_count, PretenureFlag pretenure) { | 11019 Isolate* isolate, int deopt_entry_count, PretenureFlag pretenure) { |
10990 return Handle<DeoptimizationInputData>::cast( | 11020 return Handle<DeoptimizationInputData>::cast( |
10991 isolate->factory()->NewFixedArray(LengthFor(deopt_entry_count), | 11021 isolate->factory()->NewFixedArray(LengthFor(deopt_entry_count), |
10992 pretenure)); | 11022 pretenure)); |
10993 } | 11023 } |
10994 | 11024 |
10995 | 11025 |
10996 Handle<DeoptimizationOutputData> DeoptimizationOutputData::New( | 11026 Handle<DeoptimizationOutputData> DeoptimizationOutputData::New( |
10997 Isolate* isolate, | 11027 Isolate* isolate, |
(...skipping 8848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19846 if (cell->value() != *new_value) { | 19876 if (cell->value() != *new_value) { |
19847 cell->set_value(*new_value); | 19877 cell->set_value(*new_value); |
19848 Isolate* isolate = cell->GetIsolate(); | 19878 Isolate* isolate = cell->GetIsolate(); |
19849 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19879 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19850 isolate, DependentCode::kPropertyCellChangedGroup); | 19880 isolate, DependentCode::kPropertyCellChangedGroup); |
19851 } | 19881 } |
19852 } | 19882 } |
19853 | 19883 |
19854 } // namespace internal | 19884 } // namespace internal |
19855 } // namespace v8 | 19885 } // namespace v8 |
OLD | NEW |