OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/api-natives.h" | 9 #include "src/api-natives.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 RETURN_RESULT_OR_FAILURE( | 264 RETURN_RESULT_OR_FAILURE( |
265 isolate, HandleApiCallHelper<true>(isolate, function, new_target, | 265 isolate, HandleApiCallHelper<true>(isolate, function, new_target, |
266 fun_data, receiver, args)); | 266 fun_data, receiver, args)); |
267 } else { | 267 } else { |
268 RETURN_RESULT_OR_FAILURE( | 268 RETURN_RESULT_OR_FAILURE( |
269 isolate, HandleApiCallHelper<false>(isolate, function, new_target, | 269 isolate, HandleApiCallHelper<false>(isolate, function, new_target, |
270 fun_data, receiver, args)); | 270 fun_data, receiver, args)); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 namespace { | |
275 | |
276 bool CodeGenerationFromStringsAllowed(Isolate* isolate, | |
277 Handle<Context> context) { | |
278 DCHECK(context->allow_code_gen_from_strings()->IsFalse(isolate)); | |
279 // Check with callback if set. | |
280 AllowCodeGenerationFromStringsCallback callback = | |
281 isolate->allow_code_gen_callback(); | |
282 if (callback == NULL) { | |
283 // No callback set and code generation disallowed. | |
284 return false; | |
285 } else { | |
286 // Callback set. Let it decide if code generation is allowed. | |
287 VMState<EXTERNAL> state(isolate); | |
288 return callback(v8::Utils::ToLocal(context)); | |
289 } | |
290 } | |
291 | |
292 } // namespace | |
293 | |
294 MaybeHandle<JSFunction> Builtins::CompileString(Handle<Context> context, | |
295 Handle<String> source, | |
296 ParseRestriction restriction) { | |
297 Isolate* const isolate = context->GetIsolate(); | |
298 Handle<Context> native_context(context->native_context(), isolate); | |
299 | |
300 // Check if native context allows code generation from | |
301 // strings. Throw an exception if it doesn't. | |
302 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && | |
303 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | |
304 Handle<Object> error_message = | |
305 native_context->ErrorMessageForCodeGenerationFromStrings(); | |
306 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, | |
307 error_message), | |
308 JSFunction); | |
309 } | |
310 | |
311 // Compile source string in the native context. | |
312 int eval_scope_position = 0; | |
313 int eval_position = kNoSourcePosition; | |
314 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); | |
315 return Compiler::GetFunctionFromEval(source, outer_info, native_context, | |
316 SLOPPY, restriction, eval_scope_position, | |
317 eval_position); | |
318 } | |
319 | |
320 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode, | 274 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode, |
321 TailCallMode tail_call_mode) { | 275 TailCallMode tail_call_mode) { |
322 switch (tail_call_mode) { | 276 switch (tail_call_mode) { |
323 case TailCallMode::kDisallow: | 277 case TailCallMode::kDisallow: |
324 switch (mode) { | 278 switch (mode) { |
325 case ConvertReceiverMode::kNullOrUndefined: | 279 case ConvertReceiverMode::kNullOrUndefined: |
326 return CallFunction_ReceiverIsNullOrUndefined(); | 280 return CallFunction_ReceiverIsNullOrUndefined(); |
327 case ConvertReceiverMode::kNotNullOrUndefined: | 281 case ConvertReceiverMode::kNotNullOrUndefined: |
328 return CallFunction_ReceiverIsNotNullOrUndefined(); | 282 return CallFunction_ReceiverIsNotNullOrUndefined(); |
329 case ConvertReceiverMode::kAny: | 283 case ConvertReceiverMode::kAny: |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ | 1253 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ |
1300 Handle<Code> Builtins::Name() { \ | 1254 Handle<Code> Builtins::Name() { \ |
1301 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ | 1255 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ |
1302 return Handle<Code>(code_address); \ | 1256 return Handle<Code>(code_address); \ |
1303 } | 1257 } |
1304 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) | 1258 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) |
1305 #undef DEFINE_BUILTIN_ACCESSOR | 1259 #undef DEFINE_BUILTIN_ACCESSOR |
1306 | 1260 |
1307 } // namespace internal | 1261 } // namespace internal |
1308 } // namespace v8 | 1262 } // namespace v8 |
OLD | NEW |