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

Side by Side Diff: src/runtime.cc

Issue 48923002: Provide private symbols through internal APIs (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Mo comments Created 7 years, 1 month 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
« no previous file with comments | « src/runtime.h ('k') | test/cctest/test-api.cc » ('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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 Handle<Object> name(args[0], isolate); 607 Handle<Object> name(args[0], isolate);
608 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); 608 RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
609 Symbol* symbol; 609 Symbol* symbol;
610 MaybeObject* maybe = isolate->heap()->AllocateSymbol(); 610 MaybeObject* maybe = isolate->heap()->AllocateSymbol();
611 if (!maybe->To(&symbol)) return maybe; 611 if (!maybe->To(&symbol)) return maybe;
612 if (name->IsString()) symbol->set_name(*name); 612 if (name->IsString()) symbol->set_name(*name);
613 return symbol; 613 return symbol;
614 } 614 }
615 615
616 616
617 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreatePrivateSymbol) {
618 HandleScope scope(isolate);
619 ASSERT(args.length() == 1);
620 Handle<Object> name(args[0], isolate);
621 RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
622 Symbol* symbol;
623 MaybeObject* maybe = isolate->heap()->AllocatePrivateSymbol();
624 if (!maybe->To(&symbol)) return maybe;
625 if (name->IsString()) symbol->set_name(*name);
626 return symbol;
627 }
628
629
617 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolName) { 630 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolName) {
618 SealHandleScope shs(isolate); 631 SealHandleScope shs(isolate);
619 ASSERT(args.length() == 1); 632 ASSERT(args.length() == 1);
620 CONVERT_ARG_CHECKED(Symbol, symbol, 0); 633 CONVERT_ARG_CHECKED(Symbol, symbol, 0);
621 return symbol->name(); 634 return symbol->name();
622 } 635 }
623 636
624 637
638 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolIsPrivate) {
639 SealHandleScope shs(isolate);
640 ASSERT(args.length() == 1);
641 CONVERT_ARG_CHECKED(Symbol, symbol, 0);
642 return isolate->heap()->ToBoolean(symbol->is_private());
643 }
644
645
625 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) { 646 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) {
626 SealHandleScope shs(isolate); 647 SealHandleScope shs(isolate);
627 ASSERT(args.length() == 2); 648 ASSERT(args.length() == 2);
628 CONVERT_ARG_CHECKED(JSReceiver, handler, 0); 649 CONVERT_ARG_CHECKED(JSReceiver, handler, 0);
629 Object* prototype = args[1]; 650 Object* prototype = args[1];
630 Object* used_prototype = 651 Object* used_prototype =
631 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); 652 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value();
632 return isolate->heap()->AllocateJSProxy(handler, used_prototype); 653 return isolate->heap()->AllocateJSProxy(handler, used_prototype);
633 } 654 }
634 655
(...skipping 4176 matching lines...) Expand 10 before | Expand all | Expand 10 after
4811 } 4832 }
4812 4833
4813 if (object->IsString() || object->IsNumber() || object->IsBoolean()) { 4834 if (object->IsString() || object->IsNumber() || object->IsBoolean()) {
4814 return object->GetPrototype(isolate)->GetElement(isolate, index); 4835 return object->GetPrototype(isolate)->GetElement(isolate, index);
4815 } 4836 }
4816 4837
4817 return object->GetElement(isolate, index); 4838 return object->GetElement(isolate, index);
4818 } 4839 }
4819 4840
4820 4841
4842 static Handle<Name> ToName(Isolate* isolate, Handle<Object> key) {
4843 if (key->IsName()) {
4844 return Handle<Name>::cast(key);
4845 } else {
4846 bool has_pending_exception = false;
4847 Handle<Object> converted =
4848 Execution::ToString(isolate, key, &has_pending_exception);
4849 if (has_pending_exception) return Handle<Name>();
4850 return Handle<Name>::cast(converted);
4851 }
4852 }
4853
4854
4821 MaybeObject* Runtime::HasObjectProperty(Isolate* isolate, 4855 MaybeObject* Runtime::HasObjectProperty(Isolate* isolate,
4822 Handle<JSReceiver> object, 4856 Handle<JSReceiver> object,
4823 Handle<Object> key) { 4857 Handle<Object> key) {
4824 HandleScope scope(isolate); 4858 HandleScope scope(isolate);
4825 4859
4826 // Check if the given key is an array index. 4860 // Check if the given key is an array index.
4827 uint32_t index; 4861 uint32_t index;
4828 if (key->ToArrayIndex(&index)) { 4862 if (key->ToArrayIndex(&index)) {
4829 return isolate->heap()->ToBoolean(JSReceiver::HasElement(object, index)); 4863 return isolate->heap()->ToBoolean(JSReceiver::HasElement(object, index));
4830 } 4864 }
4831 4865
4832 // Convert the key to a name - possibly by calling back into JavaScript. 4866 // Convert the key to a name - possibly by calling back into JavaScript.
4833 Handle<Name> name; 4867 Handle<Name> name = ToName(isolate, key);
4834 if (key->IsName()) { 4868 RETURN_IF_EMPTY_HANDLE(isolate, name);
4835 name = Handle<Name>::cast(key);
4836 } else {
4837 bool has_pending_exception = false;
4838 Handle<Object> converted =
4839 Execution::ToString(isolate, key, &has_pending_exception);
4840 if (has_pending_exception) return Failure::Exception();
4841 name = Handle<Name>::cast(converted);
4842 }
4843 4869
4844 return isolate->heap()->ToBoolean(JSReceiver::HasProperty(object, name)); 4870 return isolate->heap()->ToBoolean(JSReceiver::HasProperty(object, name));
4845 } 4871 }
4846 4872
4847 MaybeObject* Runtime::GetObjectPropertyOrFail( 4873 MaybeObject* Runtime::GetObjectPropertyOrFail(
4848 Isolate* isolate, 4874 Isolate* isolate,
4849 Handle<Object> object, 4875 Handle<Object> object,
4850 Handle<Object> key) { 4876 Handle<Object> key) {
4851 CALL_HEAP_FUNCTION_PASS_EXCEPTION(isolate, 4877 CALL_HEAP_FUNCTION_PASS_EXCEPTION(isolate,
4852 GetObjectProperty(isolate, object, key)); 4878 GetObjectProperty(isolate, object, key));
(...skipping 12 matching lines...) Expand all
4865 return isolate->Throw(*error); 4891 return isolate->Throw(*error);
4866 } 4892 }
4867 4893
4868 // Check if the given key is an array index. 4894 // Check if the given key is an array index.
4869 uint32_t index; 4895 uint32_t index;
4870 if (key->ToArrayIndex(&index)) { 4896 if (key->ToArrayIndex(&index)) {
4871 return GetElementOrCharAt(isolate, object, index); 4897 return GetElementOrCharAt(isolate, object, index);
4872 } 4898 }
4873 4899
4874 // Convert the key to a name - possibly by calling back into JavaScript. 4900 // Convert the key to a name - possibly by calling back into JavaScript.
4875 Handle<Name> name; 4901 Handle<Name> name = ToName(isolate, key);
4876 if (key->IsName()) { 4902 RETURN_IF_EMPTY_HANDLE(isolate, name);
4877 name = Handle<Name>::cast(key);
4878 } else {
4879 bool has_pending_exception = false;
4880 Handle<Object> converted =
4881 Execution::ToString(isolate, key, &has_pending_exception);
4882 if (has_pending_exception) return Failure::Exception();
4883 name = Handle<Name>::cast(converted);
4884 }
4885 4903
4886 // Check if the name is trivially convertible to an index and get 4904 // Check if the name is trivially convertible to an index and get
4887 // the element if so. 4905 // the element if so.
4888 if (name->AsArrayIndex(&index)) { 4906 if (name->AsArrayIndex(&index)) {
4889 return GetElementOrCharAt(isolate, object, index); 4907 return GetElementOrCharAt(isolate, object, index);
4890 } else { 4908 } else {
4891 return object->GetProperty(*name); 4909 return object->GetProperty(*name);
4892 } 4910 }
4893 } 4911 }
4894 4912
(...skipping 9971 matching lines...) Expand 10 before | Expand all | Expand 10 after
14866 // Handle last resort GC and make sure to allow future allocations 14884 // Handle last resort GC and make sure to allow future allocations
14867 // to grow the heap without causing GCs (if possible). 14885 // to grow the heap without causing GCs (if possible).
14868 isolate->counters()->gc_last_resort_from_js()->Increment(); 14886 isolate->counters()->gc_last_resort_from_js()->Increment();
14869 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14887 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14870 "Runtime::PerformGC"); 14888 "Runtime::PerformGC");
14871 } 14889 }
14872 } 14890 }
14873 14891
14874 14892
14875 } } // namespace v8::internal 14893 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698