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

Side by Side Diff: src/builtins/builtins-symbol.cc

Issue 2551763003: v8::Private::ForApi should be context-independent. (Closed)
Patch Set: fix Created 4 years 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 | « src/builtins/builtins.h ('k') | src/heap-symbols.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/builtins/builtins.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 namespace v8 { 8 namespace v8 {
9 namespace internal { 9 namespace internal {
10 10
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. 27 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case.
28 BUILTIN(SymbolConstructor_ConstructStub) { 28 BUILTIN(SymbolConstructor_ConstructStub) {
29 HandleScope scope(isolate); 29 HandleScope scope(isolate);
30 THROW_NEW_ERROR_RETURN_FAILURE( 30 THROW_NEW_ERROR_RETURN_FAILURE(
31 isolate, NewTypeError(MessageTemplate::kNotConstructor, 31 isolate, NewTypeError(MessageTemplate::kNotConstructor,
32 isolate->factory()->Symbol_string())); 32 isolate->factory()->Symbol_string()));
33 } 33 }
34 34
35 // ES6 section 19.4.2.1 Symbol.for.
36 BUILTIN(SymbolFor) {
37 HandleScope scope(isolate);
38 Handle<Object> key_obj = args.atOrUndefined(isolate, 1);
39 Handle<String> key;
40 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
41 Object::ToString(isolate, key_obj));
42 return *isolate->SymbolFor(Heap::kPublicSymbolTableRootIndex, key, false);
43 }
44
45 // ES6 section 19.4.2.5 Symbol.keyFor.
46 BUILTIN(SymbolKeyFor) {
47 HandleScope scope(isolate);
48 Handle<Object> obj = args.atOrUndefined(isolate, 1);
49 if (!obj->IsSymbol()) {
50 THROW_NEW_ERROR_RETURN_FAILURE(
51 isolate, NewTypeError(MessageTemplate::kSymbolKeyFor, obj));
52 }
53 Handle<Symbol> symbol = Handle<Symbol>::cast(obj);
54 DisallowHeapAllocation no_gc;
55 Object* result;
56 if (symbol->is_public()) {
57 result = symbol->name();
58 DCHECK(result->IsString());
59 } else {
60 result = isolate->heap()->undefined_value();
61 }
62 DCHECK_EQ(isolate->heap()->public_symbol_table()->SlowReverseLookup(*symbol),
63 result);
64 return result;
65 }
66
35 // ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) 67 // ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
36 void Builtins::Generate_SymbolPrototypeToPrimitive( 68 void Builtins::Generate_SymbolPrototypeToPrimitive(
37 compiler::CodeAssemblerState* state) { 69 compiler::CodeAssemblerState* state) {
38 typedef compiler::Node Node; 70 typedef compiler::Node Node;
39 CodeStubAssembler assembler(state); 71 CodeStubAssembler assembler(state);
40 72
41 Node* receiver = assembler.Parameter(0); 73 Node* receiver = assembler.Parameter(0);
42 Node* context = assembler.Parameter(4); 74 Node* context = assembler.Parameter(4);
43 75
44 Node* result = 76 Node* result =
(...skipping 27 matching lines...) Expand all
72 Node* receiver = assembler.Parameter(0); 104 Node* receiver = assembler.Parameter(0);
73 Node* context = assembler.Parameter(3); 105 Node* context = assembler.Parameter(3);
74 106
75 Node* result = assembler.ToThisValue( 107 Node* result = assembler.ToThisValue(
76 context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.valueOf"); 108 context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.valueOf");
77 assembler.Return(result); 109 assembler.Return(result);
78 } 110 }
79 111
80 } // namespace internal 112 } // namespace internal
81 } // namespace v8 113 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/heap-symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698