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

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

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

Powered by Google App Engine
This is Rietveld 408576698