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