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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/contexts.h" | 9 #include "src/contexts.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 | 187 |
188 // Tries to non-observably convert |value| to a valid array length. | 188 // Tries to non-observably convert |value| to a valid array length. |
189 // Returns false if it fails. | 189 // Returns false if it fails. |
190 static bool FastAsArrayLength(Isolate* isolate, Handle<Object> value, | 190 static bool FastAsArrayLength(Isolate* isolate, Handle<Object> value, |
191 uint32_t* length) { | 191 uint32_t* length) { |
192 if (value->ToArrayLength(length)) return true; | 192 if (value->ToArrayLength(length)) return true; |
193 // We don't support AsArrayLength, so use AsArrayIndex for now. This just | 193 // We don't support AsArrayLength, so use AsArrayIndex for now. This just |
194 // misses out on kMaxUInt32. | 194 // misses out on kMaxUInt32. |
195 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length); | 195 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length); |
196 if (!value->IsJSValue()) return false; | 196 return false; |
197 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); | |
198 DCHECK(wrapper->GetIsolate() | |
199 ->native_context() | |
200 ->number_function() | |
201 ->has_initial_map()); | |
202 // Only support fast unwrapping for the initial map. Otherwise valueOf might | |
203 // have been overwritten, in which case unwrapping is invalid. | |
204 if (wrapper->map() != isolate->number_function()->initial_map()) return false; | |
205 return wrapper->value()->ToArrayIndex(length); | |
206 } | 197 } |
207 | 198 |
208 | 199 |
209 void Accessors::ArrayLengthSetter( | 200 void Accessors::ArrayLengthSetter( |
210 v8::Local<v8::Name> name, | 201 v8::Local<v8::Name> name, |
211 v8::Local<v8::Value> val, | 202 v8::Local<v8::Value> val, |
212 const v8::PropertyCallbackInfo<void>& info) { | 203 const v8::PropertyCallbackInfo<void>& info) { |
213 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 204 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
214 HandleScope scope(isolate); | 205 HandleScope scope(isolate); |
215 | 206 |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1490 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
1500 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1491 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
1501 info->set_getter(*getter); | 1492 info->set_getter(*getter); |
1502 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1493 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
1503 return info; | 1494 return info; |
1504 } | 1495 } |
1505 | 1496 |
1506 | 1497 |
1507 } // namespace internal | 1498 } // namespace internal |
1508 } // namespace v8 | 1499 } // namespace v8 |
OLD | NEW |