Changeset 69977 in webkit


Ignore:
Timestamp:
Oct 18, 2010 11:32:39 AM (14 years ago)
Author:
oliver@apple.com
Message:

2010-10-18 Oliver Hunt <oliver@apple.com>

Reviewed by Darin Adler.

Strict mode: |this| should be undefined if it is not explicitly provided
https://bugs.webkit.org/show_bug.cgi?id=47833

To make strict mode behave correctly we want to pass undefined instead of null
as the default this value. This has no impact on behaviour outside of strict
mode as both values are replaced with the global object if necessary.

  • bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallValueNode::emitBytecode): (JSC::FunctionCallResolveNode::emitBytecode): (JSC::CallFunctionCallDotNode::emitBytecode): (JSC::ApplyFunctionCallDotNode::emitBytecode):

2010-10-18 Oliver Hunt <oliver@apple.com>

Reviewed by Darin Adler.

Strict mode: |this| should be undefined if it is not explicitly provided
https://bugs.webkit.org/show_bug.cgi?id=47833

Add tests to ensure that |this| is undefined rather than null when it has
not been explicitly provided.

  • fast/js/basic-strict-mode-expected.txt:
  • fast/js/script-tests/basic-strict-mode.js:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r69970 r69977  
     12010-10-18  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Strict mode: |this| should be undefined if it is not explicitly provided
     6        https://bugs.webkit.org/show_bug.cgi?id=47833
     7
     8        To make strict mode behave correctly we want to pass undefined instead of null
     9        as the default this value.  This has no impact on behaviour outside of strict
     10        mode as both values are replaced with the global object if necessary.
     11
     12        * bytecompiler/NodesCodegen.cpp:
     13        (JSC::FunctionCallValueNode::emitBytecode):
     14        (JSC::FunctionCallResolveNode::emitBytecode):
     15        (JSC::CallFunctionCallDotNode::emitBytecode):
     16        (JSC::ApplyFunctionCallDotNode::emitBytecode):
     17
     18
    1192010-10-18  Darin Adler  <darin@apple.com>
    220
  • trunk/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r69940 r69977  
    372372    RefPtr<RegisterID> func = generator.emitNode(m_expr);
    373373    CallArguments callArguments(generator, m_args);
    374     generator.emitLoad(callArguments.thisRegister(), jsNull());
     374    generator.emitLoad(callArguments.thisRegister(), jsUndefined());
    375375    return generator.emitCall(generator.finalDestinationOrIgnored(dst, func.get()), func.get(), callArguments, divot(), startOffset(), endOffset());
    376376}
     
    382382    if (RefPtr<RegisterID> local = generator.registerFor(m_ident)) {
    383383        CallArguments callArguments(generator, m_args);
    384         generator.emitLoad(callArguments.thisRegister(), jsNull());
     384        generator.emitLoad(callArguments.thisRegister(), jsUndefined());
    385385        return generator.emitCall(generator.finalDestinationOrIgnored(dst, callArguments.thisRegister()), local.get(), callArguments, divot(), startOffset(), endOffset());
    386386    }
     
    393393        RefPtr<RegisterID> func = generator.emitGetScopedVar(generator.newTemporary(), depth, index, globalObject);
    394394        CallArguments callArguments(generator, m_args);
    395         generator.emitLoad(callArguments.thisRegister(), jsNull());
     395        generator.emitLoad(callArguments.thisRegister(), jsUndefined());
    396396        return generator.emitCall(generator.finalDestinationOrIgnored(dst, func.get()), func.get(), callArguments, divot(), startOffset(), endOffset());
    397397    }
     
    456456            RefPtr<RegisterID> realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
    457457            CallArguments callArguments(generator, m_args);
    458             generator.emitLoad(callArguments.thisRegister(), jsNull());
     458            generator.emitLoad(callArguments.thisRegister(), jsUndefined());
    459459            generator.emitCall(finalDestinationOrIgnored.get(), realFunction.get(), callArguments, divot(), startOffset(), endOffset());
    460460            generator.emitJump(end.get());
     
    514514                RefPtr<RegisterID> realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
    515515                CallArguments callArguments(generator, m_args);
    516                 generator.emitLoad(callArguments.thisRegister(), jsNull());
     516                generator.emitLoad(callArguments.thisRegister(), jsUndefined());
    517517                generator.emitCall(finalDestinationOrIgnored.get(), realFunction.get(), callArguments, divot(), startOffset(), endOffset());
    518518            }
  • trunk/LayoutTests/ChangeLog

    r69975 r69977  
     12010-10-18  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Strict mode: |this| should be undefined if it is not explicitly provided
     6        https://bugs.webkit.org/show_bug.cgi?id=47833
     7
     8        Add tests to ensure that |this| is undefined rather than null when it has
     9        not been explicitly provided.
     10
     11        * fast/js/basic-strict-mode-expected.txt:
     12        * fast/js/script-tests/basic-strict-mode.js:
     13
    1142010-10-18  Robert Hogan  <robert@webkit.org>
    215
  • trunk/LayoutTests/fast/js/basic-strict-mode-expected.txt

    r69965 r69977  
    2222PASS testThisBracketAccess.call(false, 'length') is undefined.
    2323PASS testThisBracketAccess.call(1, 'length') is undefined.
    24 PASS testGlobalAccess() is null
     24PASS testGlobalAccess() is undefined
     25PASS testThis.call() is undefined
     26PASS testThis.apply() is undefined
     27PASS testThis.call(undefined) is undefined
     28PASS testThis.apply(undefined) is undefined
    2529PASS (function eval(){'use strict';}) threw exception SyntaxError: Parse error.
    2630PASS (function (eval){'use strict';}) threw exception SyntaxError: Parse error.
  • trunk/LayoutTests/fast/js/script-tests/basic-strict-mode.js

    r69965 r69977  
    3737
    3838
    39 shouldBe("testGlobalAccess()", "null");
     39shouldBe("testGlobalAccess()", "undefined");
     40shouldBe("testThis.call()", "undefined");
     41shouldBe("testThis.apply()", "undefined");
     42shouldBe("testThis.call(undefined)", "undefined");
     43shouldBe("testThis.apply(undefined)", "undefined");
    4044
    4145shouldThrow("(function eval(){'use strict';})");
Note: See TracChangeset for help on using the changeset viewer.