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

Side by Side Diff: src/runtime.cc

Issue 196103004: Add support for per-isolate private symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 9 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 | Annotate | Revision Log
« include/v8.h ('K') | « src/runtime.h ('k') | src/symbol.js » ('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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 Handle<Object> name(args[0], isolate); 614 Handle<Object> name(args[0], isolate);
615 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); 615 RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
616 Symbol* symbol; 616 Symbol* symbol;
617 MaybeObject* maybe = isolate->heap()->AllocatePrivateSymbol(); 617 MaybeObject* maybe = isolate->heap()->AllocatePrivateSymbol();
618 if (!maybe->To(&symbol)) return maybe; 618 if (!maybe->To(&symbol)) return maybe;
619 if (name->IsString()) symbol->set_name(*name); 619 if (name->IsString()) symbol->set_name(*name);
620 return symbol; 620 return symbol;
621 } 621 }
622 622
623 623
624 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateGlobalPrivateSymbol) {
625 HandleScope scope(isolate);
626 ASSERT(args.length() == 1);
627 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
628 Handle<JSObject> registry = handle(isolate->heap()->symbol_registry());
629 Handle<String> part = handle(isolate->heap()->private_intern_string());
630 Handle<Object> privates_val = JSReceiver::GetProperty(registry, part);
631 Handle<JSObject> privates;
632 if (privates_val->IsJSObject()) {
633 privates = Handle<JSObject>::cast(privates_val);
634 } else {
635 ASSERT(privates_val->IsUndefined());
636 privates =
637 isolate->factory()->NewJSObject(isolate->object_function(), TENURED);
Michael Starzinger 2014/03/24 10:04:33 As discussed offline: This will create a JSObject
rossberg 2014/03/24 15:09:49 I moved the whole registry creation and initializa
638 JSObject::SetPrototype(privates, isolate->factory()->null_value());
639 JSObject::SetProperty(registry, part, privates, NONE, STRICT);
640 }
641 Handle<Object> symbol = JSObject::GetProperty(privates, name);
642 if (!symbol->IsSymbol()) {
643 ASSERT(symbol->IsUndefined());
644 symbol = isolate->factory()->NewPrivateSymbol();
645 Handle<Symbol>::cast(symbol)->set_name(*name);
646 JSObject::SetProperty(privates, name, symbol, NONE, STRICT);
647 }
648 return *symbol;
649 }
650
651
624 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewSymbolWrapper) { 652 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewSymbolWrapper) {
625 ASSERT(args.length() == 1); 653 ASSERT(args.length() == 1);
626 CONVERT_ARG_CHECKED(Symbol, symbol, 0); 654 CONVERT_ARG_CHECKED(Symbol, symbol, 0);
627 return symbol->ToObject(isolate); 655 return symbol->ToObject(isolate);
628 } 656 }
629 657
630 658
631 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolDescription) { 659 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolDescription) {
632 SealHandleScope shs(isolate); 660 SealHandleScope shs(isolate);
633 ASSERT(args.length() == 1); 661 ASSERT(args.length() == 1);
(...skipping 14426 matching lines...) Expand 10 before | Expand all | Expand 10 after
15060 // Handle last resort GC and make sure to allow future allocations 15088 // Handle last resort GC and make sure to allow future allocations
15061 // to grow the heap without causing GCs (if possible). 15089 // to grow the heap without causing GCs (if possible).
15062 isolate->counters()->gc_last_resort_from_js()->Increment(); 15090 isolate->counters()->gc_last_resort_from_js()->Increment();
15063 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 15091 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
15064 "Runtime::PerformGC"); 15092 "Runtime::PerformGC");
15065 } 15093 }
15066 } 15094 }
15067 15095
15068 15096
15069 } } // namespace v8::internal 15097 } } // namespace v8::internal
OLDNEW
« include/v8.h ('K') | « src/runtime.h ('k') | src/symbol.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698