Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: src/api.cc

Issue 875113004: Revert of Add WeakMap to v8.h (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // --- W e a k M a p ---
2253
2254 WeakMap* WeakMap::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 WeakMap(v8_isolate, v8_obj);
2262 }
2263
2264
2265 void WeakMap::Set(Handle<Value> v8_key, Handle<Value> v8_value) {
2266 v8::HandleScope handleScope(isolate_);
2267 Local<Object> map_handle = Local<Object>::New(isolate_, map_);
2268 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
2269 ENTER_V8(isolate);
2270 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
2271 i::Handle<i::Object> value = Utils::OpenHandle(*v8_value);
2272 i::Handle<i::JSWeakMap> weak_collection =
2273 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle));
2274 if (!key->IsJSReceiver() && !key->IsSymbol()) {
2275 DCHECK(false);
2276 return;
2277 }
2278 i::Handle<i::ObjectHashTable> table(
2279 i::ObjectHashTable::cast(weak_collection->table()));
2280 if (!table->IsKey(*key)) {
2281 DCHECK(false);
2282 return;
2283 }
2284 i::Runtime::WeakCollectionSet(weak_collection, key, value);
2285 }
2286
2287
2288 Local<Value> WeakMap::Get(Handle<Value> v8_key) {
2289 v8::EscapableHandleScope handleScope(isolate_);
2290 Local<Object> map_handle = Local<Object>::New(isolate_, map_);
2291 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
2292 ENTER_V8(isolate);
2293 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
2294 i::Handle<i::JSWeakMap> weak_collection =
2295 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle));
2296 if (!key->IsJSReceiver() && !key->IsSymbol()) {
2297 DCHECK(false);
2298 return Undefined(isolate_);
2299 }
2300 i::Handle<i::ObjectHashTable> table(
2301 i::ObjectHashTable::cast(weak_collection->table()));
2302 if (!table->IsKey(*key)) {
2303 DCHECK(false);
2304 return Undefined(isolate_);
2305 }
2306 i::Handle<i::Object> lookup(table->Lookup(key), isolate);
2307 if (lookup->IsTheHole()) return Undefined(isolate_);
2308 Local<Value> result = Utils::ToLocal(lookup);
2309 return handleScope.Escape(result);
2310 }
2311
2312
2313 bool WeakMap::Has(Handle<Value> v8_key) {
2314 v8::HandleScope handleScope(isolate_);
2315 Local<Object> map_handle = Local<Object>::New(isolate_, map_);
2316 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
2317 ENTER_V8(isolate);
2318 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
2319 i::Handle<i::JSWeakMap> weak_collection =
2320 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle));
2321 if (!key->IsJSReceiver() && !key->IsSymbol()) {
2322 DCHECK(false);
2323 return false;
2324 }
2325 i::Handle<i::ObjectHashTable> table(
2326 i::ObjectHashTable::cast(weak_collection->table()));
2327 if (!table->IsKey(*key)) {
2328 DCHECK(false);
2329 return false;
2330 }
2331 i::Handle<i::Object> lookup(table->Lookup(key), isolate);
2332 return !lookup->IsTheHole();
2333 }
2334
2335
2336 bool WeakMap::Delete(Handle<Value> v8_key) {
2337 v8::HandleScope handleScope(isolate_);
2338 Local<Object> map_handle = Local<Object>::New(isolate_, map_);
2339 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
2340 ENTER_V8(isolate);
2341 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
2342 i::Handle<i::JSWeakMap> weak_collection =
2343 i::Handle<i::JSWeakMap>::cast(Utils::OpenHandle(*map_handle));
2344 if (!key->IsJSReceiver() && !key->IsSymbol()) {
2345 DCHECK(false);
2346 return false;
2347 }
2348 i::Handle<i::ObjectHashTable> table(
2349 i::ObjectHashTable::cast(weak_collection->table()));
2350 if (!table->IsKey(*key)) {
2351 DCHECK(false);
2352 return false;
2353 }
2354 return i::Runtime::WeakCollectionDelete(weak_collection, key);
2355 }
2356
2357
2358 // --- J S O N --- 2252 // --- J S O N ---
2359 2253
2360 Local<Value> JSON::Parse(Local<String> json_string) { 2254 Local<Value> JSON::Parse(Local<String> json_string) {
2361 i::Handle<i::String> string = Utils::OpenHandle(*json_string); 2255 i::Handle<i::String> string = Utils::OpenHandle(*json_string);
2362 i::Isolate* isolate = string->GetIsolate(); 2256 i::Isolate* isolate = string->GetIsolate();
2363 ENTER_V8(isolate); 2257 ENTER_V8(isolate);
2364 i::HandleScope scope(isolate); 2258 i::HandleScope scope(isolate);
2365 i::Handle<i::String> source = i::String::Flatten(string); 2259 i::Handle<i::String> source = i::String::Flatten(string);
2366 EXCEPTION_PREAMBLE(isolate); 2260 EXCEPTION_PREAMBLE(isolate);
2367 i::MaybeHandle<i::Object> maybe_result = 2261 i::MaybeHandle<i::Object> maybe_result =
(...skipping 5412 matching lines...) Expand 10 before | Expand all | Expand 10 after
7780 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7674 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7781 Address callback_address = 7675 Address callback_address =
7782 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7676 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7783 VMState<EXTERNAL> state(isolate); 7677 VMState<EXTERNAL> state(isolate);
7784 ExternalCallbackScope call_scope(isolate, callback_address); 7678 ExternalCallbackScope call_scope(isolate, callback_address);
7785 callback(info); 7679 callback(info);
7786 } 7680 }
7787 7681
7788 7682
7789 } } // namespace v8::internal 7683 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698