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 2231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2242 } | 2242 } |
2243 | 2243 |
2244 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } | 2244 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } |
2245 | 2245 |
2246 | 2246 |
2247 bool StackFrame::IsConstructor() const { | 2247 bool StackFrame::IsConstructor() const { |
2248 return getBoolProperty(this, "isConstructor"); | 2248 return getBoolProperty(this, "isConstructor"); |
2249 } | 2249 } |
2250 | 2250 |
2251 | 2251 |
| 2252 // --- N a t i v e W e a k M a p --- |
| 2253 |
| 2254 NativeWeakMap* NativeWeakMap::New(Isolate* v8_isolate) { |
| 2255 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 2256 ENTER_V8(isolate); |
| 2257 i::HandleScope scope(isolate); |
| 2258 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); |
| 2259 i::Runtime::WeakCollectionInitialize(isolate, weakmap); |
| 2260 Local<Object> v8_obj = Utils::ToLocal(i::Handle<i::JSObject>::cast(weakmap)); |
| 2261 return new NativeWeakMap(v8_isolate, v8_obj); |
| 2262 } |
| 2263 |
| 2264 |
| 2265 NativeWeakMap::NativeWeakMap(Isolate* isolate, Handle<Object> weak_map) |
| 2266 : isolate_(isolate), map_(isolate, weak_map) {} |
| 2267 |
| 2268 |
| 2269 NativeWeakMap::~NativeWeakMap() {} |
| 2270 |
| 2271 |
| 2272 void NativeWeakMap::Set(Handle<Value> v8_key, Handle<Value> v8_value) { |
| 2273 v8::HandleScope handleScope(isolate_); |
| 2274 Local<Object> map_handle = Local<Object>::New(isolate_, map_); |
| 2275 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_); |
| 2276 ENTER_V8(isolate); |
| 2277 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key); |
| 2278 i::Handle<i::Object> value = Utils::OpenHandle(*v8_value); |
| 2279 i::Handle<i::JSWeakMap> weak_collection = |
| 2280 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle)); |
| 2281 if (!key->IsJSReceiver() && !key->IsSymbol()) { |
| 2282 DCHECK(false); |
| 2283 return; |
| 2284 } |
| 2285 i::Handle<i::ObjectHashTable> table( |
| 2286 i::ObjectHashTable::cast(weak_collection->table())); |
| 2287 if (!table->IsKey(*key)) { |
| 2288 DCHECK(false); |
| 2289 return; |
| 2290 } |
| 2291 i::Runtime::WeakCollectionSet(weak_collection, key, value); |
| 2292 } |
| 2293 |
| 2294 |
| 2295 Local<Value> NativeWeakMap::Get(Handle<Value> v8_key) { |
| 2296 v8::EscapableHandleScope handleScope(isolate_); |
| 2297 Local<Object> map_handle = Local<Object>::New(isolate_, map_); |
| 2298 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_); |
| 2299 ENTER_V8(isolate); |
| 2300 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key); |
| 2301 i::Handle<i::JSWeakMap> weak_collection = |
| 2302 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle)); |
| 2303 if (!key->IsJSReceiver() && !key->IsSymbol()) { |
| 2304 DCHECK(false); |
| 2305 return Undefined(isolate_); |
| 2306 } |
| 2307 i::Handle<i::ObjectHashTable> table( |
| 2308 i::ObjectHashTable::cast(weak_collection->table())); |
| 2309 if (!table->IsKey(*key)) { |
| 2310 DCHECK(false); |
| 2311 return Undefined(isolate_); |
| 2312 } |
| 2313 i::Handle<i::Object> lookup(table->Lookup(key), isolate); |
| 2314 if (lookup->IsTheHole()) return Undefined(isolate_); |
| 2315 Local<Value> result = Utils::ToLocal(lookup); |
| 2316 return handleScope.Escape(result); |
| 2317 } |
| 2318 |
| 2319 |
| 2320 bool NativeWeakMap::Has(Handle<Value> v8_key) { |
| 2321 v8::HandleScope handleScope(isolate_); |
| 2322 Local<Object> map_handle = Local<Object>::New(isolate_, map_); |
| 2323 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_); |
| 2324 ENTER_V8(isolate); |
| 2325 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key); |
| 2326 i::Handle<i::JSWeakMap> weak_collection = |
| 2327 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle)); |
| 2328 if (!key->IsJSReceiver() && !key->IsSymbol()) { |
| 2329 DCHECK(false); |
| 2330 return false; |
| 2331 } |
| 2332 i::Handle<i::ObjectHashTable> table( |
| 2333 i::ObjectHashTable::cast(weak_collection->table())); |
| 2334 if (!table->IsKey(*key)) { |
| 2335 DCHECK(false); |
| 2336 return false; |
| 2337 } |
| 2338 i::Handle<i::Object> lookup(table->Lookup(key), isolate); |
| 2339 return !lookup->IsTheHole(); |
| 2340 } |
| 2341 |
| 2342 |
| 2343 bool NativeWeakMap::Delete(Handle<Value> v8_key) { |
| 2344 v8::HandleScope handleScope(isolate_); |
| 2345 Local<Object> map_handle = Local<Object>::New(isolate_, map_); |
| 2346 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_); |
| 2347 ENTER_V8(isolate); |
| 2348 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key); |
| 2349 i::Handle<i::JSWeakMap> weak_collection = |
| 2350 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle)); |
| 2351 if (!key->IsJSReceiver() && !key->IsSymbol()) { |
| 2352 DCHECK(false); |
| 2353 return false; |
| 2354 } |
| 2355 i::Handle<i::ObjectHashTable> table( |
| 2356 i::ObjectHashTable::cast(weak_collection->table())); |
| 2357 if (!table->IsKey(*key)) { |
| 2358 DCHECK(false); |
| 2359 return false; |
| 2360 } |
| 2361 return i::Runtime::WeakCollectionDelete(weak_collection, key); |
| 2362 } |
| 2363 |
| 2364 |
2252 // --- J S O N --- | 2365 // --- J S O N --- |
2253 | 2366 |
2254 Local<Value> JSON::Parse(Local<String> json_string) { | 2367 Local<Value> JSON::Parse(Local<String> json_string) { |
2255 i::Handle<i::String> string = Utils::OpenHandle(*json_string); | 2368 i::Handle<i::String> string = Utils::OpenHandle(*json_string); |
2256 i::Isolate* isolate = string->GetIsolate(); | 2369 i::Isolate* isolate = string->GetIsolate(); |
2257 ENTER_V8(isolate); | 2370 ENTER_V8(isolate); |
2258 i::HandleScope scope(isolate); | 2371 i::HandleScope scope(isolate); |
2259 i::Handle<i::String> source = i::String::Flatten(string); | 2372 i::Handle<i::String> source = i::String::Flatten(string); |
2260 EXCEPTION_PREAMBLE(isolate); | 2373 EXCEPTION_PREAMBLE(isolate); |
2261 i::MaybeHandle<i::Object> maybe_result = | 2374 i::MaybeHandle<i::Object> maybe_result = |
(...skipping 5373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7635 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7748 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7636 Address callback_address = | 7749 Address callback_address = |
7637 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7750 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7638 VMState<EXTERNAL> state(isolate); | 7751 VMState<EXTERNAL> state(isolate); |
7639 ExternalCallbackScope call_scope(isolate, callback_address); | 7752 ExternalCallbackScope call_scope(isolate, callback_address); |
7640 callback(info); | 7753 callback(info); |
7641 } | 7754 } |
7642 | 7755 |
7643 | 7756 |
7644 } } // namespace v8::internal | 7757 } } // namespace v8::internal |
OLD | NEW |