OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/builtins/builtins.h" |
| 6 #include "src/builtins/builtins-utils.h" |
| 7 |
| 8 namespace v8 { |
| 9 namespace internal { |
| 10 |
| 11 // ----------------------------------------------------------------------------- |
| 12 // ES6 section 19.4 Symbol Objects |
| 13 |
| 14 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. |
| 15 BUILTIN(SymbolConstructor) { |
| 16 HandleScope scope(isolate); |
| 17 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
| 18 Handle<Object> description = args.atOrUndefined(isolate, 1); |
| 19 if (!description->IsUndefined(isolate)) { |
| 20 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
| 21 Object::ToString(isolate, description)); |
| 22 result->set_name(*description); |
| 23 } |
| 24 return *result; |
| 25 } |
| 26 |
| 27 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. |
| 28 BUILTIN(SymbolConstructor_ConstructStub) { |
| 29 HandleScope scope(isolate); |
| 30 THROW_NEW_ERROR_RETURN_FAILURE( |
| 31 isolate, NewTypeError(MessageTemplate::kNotConstructor, |
| 32 isolate->factory()->Symbol_string())); |
| 33 } |
| 34 |
| 35 // ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) |
| 36 void Builtins::Generate_SymbolPrototypeToPrimitive( |
| 37 CodeStubAssembler* assembler) { |
| 38 typedef compiler::Node Node; |
| 39 |
| 40 Node* receiver = assembler->Parameter(0); |
| 41 Node* context = assembler->Parameter(4); |
| 42 |
| 43 Node* result = |
| 44 assembler->ToThisValue(context, receiver, PrimitiveType::kSymbol, |
| 45 "Symbol.prototype [ @@toPrimitive ]"); |
| 46 assembler->Return(result); |
| 47 } |
| 48 |
| 49 // ES6 section 19.4.3.2 Symbol.prototype.toString ( ) |
| 50 void Builtins::Generate_SymbolPrototypeToString(CodeStubAssembler* assembler) { |
| 51 typedef compiler::Node Node; |
| 52 |
| 53 Node* receiver = assembler->Parameter(0); |
| 54 Node* context = assembler->Parameter(3); |
| 55 |
| 56 Node* value = assembler->ToThisValue( |
| 57 context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.toString"); |
| 58 Node* result = |
| 59 assembler->CallRuntime(Runtime::kSymbolDescriptiveString, context, value); |
| 60 assembler->Return(result); |
| 61 } |
| 62 |
| 63 // ES6 section 19.4.3.3 Symbol.prototype.valueOf ( ) |
| 64 void Builtins::Generate_SymbolPrototypeValueOf(CodeStubAssembler* assembler) { |
| 65 typedef compiler::Node Node; |
| 66 |
| 67 Node* receiver = assembler->Parameter(0); |
| 68 Node* context = assembler->Parameter(3); |
| 69 |
| 70 Node* result = assembler->ToThisValue( |
| 71 context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.valueOf"); |
| 72 assembler->Return(result); |
| 73 } |
| 74 |
| 75 } // namespace internal |
| 76 } // namespace v8 |
OLD | NEW |