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

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

Issue 1593553002: [runtime] Throw exception for derived constructors in correct context. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: disable regression test for ignition Created 4 years, 11 months 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.h ('k') | src/mips/builtins-mips.cc » ('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 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 #if V8_TARGET_ARCH_IA32 5 #if V8_TARGET_ARCH_IA32
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); 111 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode);
112 GenerateTailCallToReturnedCode(masm); 112 GenerateTailCallToReturnedCode(masm);
113 113
114 __ bind(&ok); 114 __ bind(&ok);
115 GenerateTailCallToSharedCode(masm); 115 GenerateTailCallToSharedCode(masm);
116 } 116 }
117 117
118 118
119 static void Generate_JSConstructStubHelper(MacroAssembler* masm, 119 static void Generate_JSConstructStubHelper(MacroAssembler* masm,
120 bool is_api_function, 120 bool is_api_function,
121 bool create_implicit_receiver) { 121 bool create_implicit_receiver,
122 bool check_derived_construct) {
122 // ----------- S t a t e ------------- 123 // ----------- S t a t e -------------
123 // -- eax: number of arguments 124 // -- eax: number of arguments
124 // -- edi: constructor function 125 // -- edi: constructor function
125 // -- ebx: allocation site or undefined 126 // -- ebx: allocation site or undefined
126 // -- edx: new target 127 // -- edx: new target
127 // ----------------------------------- 128 // -----------------------------------
128 129
129 // Enter a construct frame. 130 // Enter a construct frame.
130 { 131 {
131 FrameScope scope(masm, StackFrame::CONSTRUCT); 132 FrameScope scope(masm, StackFrame::CONSTRUCT);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // Store offset of return address for deoptimizer. 325 // Store offset of return address for deoptimizer.
325 if (create_implicit_receiver && !is_api_function) { 326 if (create_implicit_receiver && !is_api_function) {
326 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); 327 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
327 } 328 }
328 329
329 // Restore context from the frame. 330 // Restore context from the frame.
330 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 331 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
331 332
332 if (create_implicit_receiver) { 333 if (create_implicit_receiver) {
333 // If the result is an object (in the ECMA sense), we should get rid 334 // If the result is an object (in the ECMA sense), we should get rid
334 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 335 // of the receiver and use the result.
335 // on page 74.
336 Label use_receiver, exit; 336 Label use_receiver, exit;
337 337
338 // If the result is a smi, it is *not* an object in the ECMA sense. 338 // If the result is a smi, it is *not* an object in the ECMA sense.
339 __ JumpIfSmi(eax, &use_receiver); 339 __ JumpIfSmi(eax, &use_receiver);
340 340
341 // If the type of the result (stored in its map) is less than 341 // If the type of the result (stored in its map) is less than
342 // FIRST_JS_RECEIVER_TYPE, it is not an object in the ECMA sense. 342 // FIRST_JS_RECEIVER_TYPE, it is not an object in the ECMA sense.
343 __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, ecx); 343 __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, ecx);
344 __ j(above_equal, &exit); 344 __ j(above_equal, &exit);
345 345
346 // Throw away the result of the constructor invocation and use the 346 // Throw away the result of the constructor invocation and use the
347 // on-stack receiver as the result. 347 // on-stack receiver as the result.
348 __ bind(&use_receiver); 348 __ bind(&use_receiver);
349 __ mov(eax, Operand(esp, 0)); 349 __ mov(eax, Operand(esp, 0));
350 350
351 // Restore the arguments count and leave the construct frame. The 351 // Restore the arguments count and leave the construct frame. The
352 // arguments count is stored below the receiver. 352 // arguments count is stored below the receiver.
353 __ bind(&exit); 353 __ bind(&exit);
354 __ mov(ebx, Operand(esp, 1 * kPointerSize)); 354 __ mov(ebx, Operand(esp, 1 * kPointerSize));
355 } else { 355 } else {
356 __ mov(ebx, Operand(esp, 0)); 356 __ mov(ebx, Operand(esp, 0));
357 } 357 }
358 358
359 // Leave construct frame. 359 // Leave construct frame.
360 } 360 }
361 361
362 // ES6 9.2.2. Step 13+
363 // Check that the result is not a Smi, indicating that the constructor result
364 // from a derived class is neither undefined nor an Object.
365 if (check_derived_construct) {
366 Label dont_throw;
367 __ JumpIfNotSmi(eax, &dont_throw);
368 {
369 FrameScope scope(masm, StackFrame::INTERNAL);
370 __ CallRuntime(Runtime::kThrowDerivedConstructorReturnedNonObject);
371 }
372 __ bind(&dont_throw);
373 }
374
362 // Remove caller arguments from the stack and return. 375 // Remove caller arguments from the stack and return.
363 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); 376 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
364 __ pop(ecx); 377 __ pop(ecx);
365 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver 378 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver
366 __ push(ecx); 379 __ push(ecx);
367 if (create_implicit_receiver) { 380 if (create_implicit_receiver) {
368 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1); 381 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1);
369 } 382 }
370 __ ret(0); 383 __ ret(0);
371 } 384 }
372 385
373 386
374 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { 387 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
375 Generate_JSConstructStubHelper(masm, false, true); 388 Generate_JSConstructStubHelper(masm, false, true, false);
376 } 389 }
377 390
378 391
379 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { 392 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
380 Generate_JSConstructStubHelper(masm, true, true); 393 Generate_JSConstructStubHelper(masm, true, true, false);
381 } 394 }
382 395
383 396
384 void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) { 397 void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
385 Generate_JSConstructStubHelper(masm, false, false); 398 Generate_JSConstructStubHelper(masm, false, false, false);
386 } 399 }
387 400
388 401
402 void Builtins::Generate_JSBuiltinsConstructStubForDerived(
403 MacroAssembler* masm) {
404 Generate_JSConstructStubHelper(masm, false, false, true);
405 }
406
407
389 void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) { 408 void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) {
390 FrameScope scope(masm, StackFrame::INTERNAL); 409 FrameScope scope(masm, StackFrame::INTERNAL);
391 __ push(edi); 410 __ push(edi);
392 __ CallRuntime(Runtime::kThrowConstructedNonConstructable); 411 __ CallRuntime(Runtime::kThrowConstructedNonConstructable);
393 } 412 }
394 413
395 414
396 enum IsTagged { kEaxIsSmiTagged, kEaxIsUntaggedInt }; 415 enum IsTagged { kEaxIsSmiTagged, kEaxIsUntaggedInt };
397 416
398 417
(...skipping 2100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 2518
2500 __ bind(&ok); 2519 __ bind(&ok);
2501 __ ret(0); 2520 __ ret(0);
2502 } 2521 }
2503 2522
2504 #undef __ 2523 #undef __
2505 } // namespace internal 2524 } // namespace internal
2506 } // namespace v8 2525 } // namespace v8
2507 2526
2508 #endif // V8_TARGET_ARCH_IA32 2527 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698