OLD | NEW |
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-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/string-builder.h" | 10 #include "src/string-builder.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 IncrementalStringBuilder builder(isolate); | 36 IncrementalStringBuilder builder(isolate); |
37 builder.AppendCharacter('('); | 37 builder.AppendCharacter('('); |
38 builder.AppendCString(token); | 38 builder.AppendCString(token); |
39 builder.AppendCharacter('('); | 39 builder.AppendCharacter('('); |
40 bool parenthesis_in_arg_string = false; | 40 bool parenthesis_in_arg_string = false; |
41 if (argc > 1) { | 41 if (argc > 1) { |
42 for (int i = 1; i < argc; ++i) { | 42 for (int i = 1; i < argc; ++i) { |
43 if (i > 1) builder.AppendCharacter(','); | 43 if (i > 1) builder.AppendCharacter(','); |
44 Handle<String> param; | 44 Handle<String> param; |
45 ASSIGN_RETURN_ON_EXCEPTION( | 45 ASSIGN_RETURN_ON_EXCEPTION( |
46 isolate, param, Object::ToString(isolate, args.at<Object>(i)), | 46 isolate, param, Object::ToString(isolate, args.at(i)), Object); |
47 Object); | |
48 param = String::Flatten(param); | 47 param = String::Flatten(param); |
49 builder.AppendString(param); | 48 builder.AppendString(param); |
50 // If the formal parameters string include ) - an illegal | 49 // If the formal parameters string include ) - an illegal |
51 // character - it may make the combined function expression | 50 // character - it may make the combined function expression |
52 // compile. We avoid this problem by checking for this early on. | 51 // compile. We avoid this problem by checking for this early on. |
53 DisallowHeapAllocation no_gc; // Ensure vectors stay valid. | 52 DisallowHeapAllocation no_gc; // Ensure vectors stay valid. |
54 String::FlatContent param_content = param->GetFlatContent(); | 53 String::FlatContent param_content = param->GetFlatContent(); |
55 for (int i = 0, length = param->length(); i < length; ++i) { | 54 for (int i = 0, length = param->length(); i < length; ++i) { |
56 if (param_content.Get(i) == ')') { | 55 if (param_content.Get(i) == ')') { |
57 parenthesis_in_arg_string = true; | 56 parenthesis_in_arg_string = true; |
58 break; | 57 break; |
59 } | 58 } |
60 } | 59 } |
61 } | 60 } |
62 // If the formal parameters include an unbalanced block comment, the | 61 // If the formal parameters include an unbalanced block comment, the |
63 // function must be rejected. Since JavaScript does not allow nested | 62 // function must be rejected. Since JavaScript does not allow nested |
64 // comments we can include a trailing block comment to catch this. | 63 // comments we can include a trailing block comment to catch this. |
65 builder.AppendCString("\n/*``*/"); | 64 builder.AppendCString("\n/*``*/"); |
66 } | 65 } |
67 builder.AppendCString(") {\n"); | 66 builder.AppendCString(") {\n"); |
68 if (argc > 0) { | 67 if (argc > 0) { |
69 Handle<String> body; | 68 Handle<String> body; |
70 ASSIGN_RETURN_ON_EXCEPTION( | 69 ASSIGN_RETURN_ON_EXCEPTION( |
71 isolate, body, Object::ToString(isolate, args.at<Object>(argc)), | 70 isolate, body, Object::ToString(isolate, args.at(argc)), Object); |
72 Object); | |
73 builder.AppendString(body); | 71 builder.AppendString(body); |
74 } | 72 } |
75 builder.AppendCString("\n})"); | 73 builder.AppendCString("\n})"); |
76 ASSIGN_RETURN_ON_EXCEPTION(isolate, source, builder.Finish(), Object); | 74 ASSIGN_RETURN_ON_EXCEPTION(isolate, source, builder.Finish(), Object); |
77 | 75 |
78 // The SyntaxError must be thrown after all the (observable) ToString | 76 // The SyntaxError must be thrown after all the (observable) ToString |
79 // conversions are done. | 77 // conversions are done. |
80 if (parenthesis_in_arg_string) { | 78 if (parenthesis_in_arg_string) { |
81 THROW_NEW_ERROR(isolate, | 79 THROW_NEW_ERROR(isolate, |
82 NewSyntaxError(MessageTemplate::kParenthesisInArgString), | 80 NewSyntaxError(MessageTemplate::kParenthesisInArgString), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 if (!args.receiver()->IsCallable()) { | 171 if (!args.receiver()->IsCallable()) { |
174 THROW_NEW_ERROR_RETURN_FAILURE( | 172 THROW_NEW_ERROR_RETURN_FAILURE( |
175 isolate, NewTypeError(MessageTemplate::kFunctionBind)); | 173 isolate, NewTypeError(MessageTemplate::kFunctionBind)); |
176 } | 174 } |
177 | 175 |
178 // Allocate the bound function with the given {this_arg} and {args}. | 176 // Allocate the bound function with the given {this_arg} and {args}. |
179 Handle<JSReceiver> target = args.at<JSReceiver>(0); | 177 Handle<JSReceiver> target = args.at<JSReceiver>(0); |
180 Handle<Object> this_arg = isolate->factory()->undefined_value(); | 178 Handle<Object> this_arg = isolate->factory()->undefined_value(); |
181 ScopedVector<Handle<Object>> argv(std::max(0, args.length() - 2)); | 179 ScopedVector<Handle<Object>> argv(std::max(0, args.length() - 2)); |
182 if (args.length() > 1) { | 180 if (args.length() > 1) { |
183 this_arg = args.at<Object>(1); | 181 this_arg = args.at(1); |
184 for (int i = 2; i < args.length(); ++i) { | 182 for (int i = 2; i < args.length(); ++i) { |
185 argv[i - 2] = args.at<Object>(i); | 183 argv[i - 2] = args.at(i); |
186 } | 184 } |
187 } | 185 } |
188 Handle<JSBoundFunction> function; | 186 Handle<JSBoundFunction> function; |
189 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 187 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
190 isolate, function, | 188 isolate, function, |
191 isolate->factory()->NewJSBoundFunction(target, this_arg, argv)); | 189 isolate->factory()->NewJSBoundFunction(target, this_arg, argv)); |
192 | 190 |
193 LookupIterator length_lookup(target, isolate->factory()->length_string(), | 191 LookupIterator length_lookup(target, isolate->factory()->length_string(), |
194 target, LookupIterator::OWN); | 192 target, LookupIterator::OWN); |
195 // Setup the "length" property based on the "length" of the {target}. | 193 // Setup the "length" property based on the "length" of the {target}. |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 466 |
469 Node* f = assembler.Parameter(0); | 467 Node* f = assembler.Parameter(0); |
470 Node* v = assembler.Parameter(1); | 468 Node* v = assembler.Parameter(1); |
471 Node* context = assembler.Parameter(4); | 469 Node* context = assembler.Parameter(4); |
472 Node* result = assembler.OrdinaryHasInstance(context, f, v); | 470 Node* result = assembler.OrdinaryHasInstance(context, f, v); |
473 assembler.Return(result); | 471 assembler.Return(result); |
474 } | 472 } |
475 | 473 |
476 } // namespace internal | 474 } // namespace internal |
477 } // namespace v8 | 475 } // namespace v8 |
OLD | NEW |