Title: [192155] trunk/Source
Revision
192155
Author
youenn.fab...@crf.canon.fr
Date
2015-11-09 06:15:21 -0800 (Mon, 09 Nov 2015)

Log Message

JS Built-ins functions should be able to assert
https://bugs.webkit.org/show_bug.cgi?id=150333

Reviewed by Yusuke Suzuki.

Source/_javascript_Core:

Introduced @assert to enable asserting in JS built-ins.
Adding a new bytecode 'assert' to implement it.
In debug builds, @assert generates 'assert' bytecodes.
In release builds, no byte code is produced for @assert.

In case assert is false, the JS built-in and the line number are dumped.

* bytecode/BytecodeList.json:
* bytecode/BytecodeUseDef.h:
(JSC::computeUsesForBytecodeOffset):
(JSC::computeDefsForBytecodeOffset):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::dumpBytecode):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitAssert):
* bytecompiler/BytecodeGenerator.h:
* bytecompiler/NodesCodegen.cpp: Generating op_assert bytecode for @assert for Debug builds.
(JSC::BytecodeIntrinsicNode::emit_intrinsic_assert):
* jit/JIT.cpp:
(JSC::JIT::privateCompileMainPass):
* jit/JIT.h:
* jit/JITOpcodes.cpp:
(JSC::JIT::emit_op_assert):
* jit/JITOpcodes32_64.cpp:
(JSC::JIT::emit_op_create_assert):
* llint/LowLevelInterpreter.asm:
* runtime/CommonIdentifiers.h: Adding @assert identifier as intrinsic.
* runtime/CommonSlowPaths.cpp:
(JSC::SLOW_PATH_DECL):
* runtime/CommonSlowPaths.h:

Source/WebCore:

* Modules/streams/ReadableStreamInternals.js:
(privateInitializeReadableStreamReader): Activating an @assert.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (192154 => 192155)


--- trunk/Source/_javascript_Core/ChangeLog	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-11-09 14:15:21 UTC (rev 192155)
@@ -1,3 +1,41 @@
+2015-11-09  Youenn Fablet  <youenn.fab...@crf.canon.fr>
+
+        JS Built-ins functions should be able to assert
+        https://bugs.webkit.org/show_bug.cgi?id=150333
+
+        Reviewed by Yusuke Suzuki.
+
+        Introduced @assert to enable asserting in JS built-ins.
+        Adding a new bytecode 'assert' to implement it.
+        In debug builds, @assert generates 'assert' bytecodes.
+        In release builds, no byte code is produced for @assert.
+
+        In case assert is false, the JS built-in and the line number are dumped.
+
+        * bytecode/BytecodeList.json:
+        * bytecode/BytecodeUseDef.h:
+        (JSC::computeUsesForBytecodeOffset):
+        (JSC::computeDefsForBytecodeOffset):
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::dumpBytecode):
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::emitAssert):
+        * bytecompiler/BytecodeGenerator.h:
+        * bytecompiler/NodesCodegen.cpp: Generating op_assert bytecode for @assert for Debug builds.
+        (JSC::BytecodeIntrinsicNode::emit_intrinsic_assert):
+        * jit/JIT.cpp:
+        (JSC::JIT::privateCompileMainPass):
+        * jit/JIT.h:
+        * jit/JITOpcodes.cpp:
+        (JSC::JIT::emit_op_assert):
+        * jit/JITOpcodes32_64.cpp:
+        (JSC::JIT::emit_op_create_assert):
+        * llint/LowLevelInterpreter.asm:
+        * runtime/CommonIdentifiers.h: Adding @assert identifier as intrinsic.
+        * runtime/CommonSlowPaths.cpp:
+        (JSC::SLOW_PATH_DECL):
+        * runtime/CommonSlowPaths.h:
+
 2015-11-08  Yusuke Suzuki  <utatane....@gmail.com>
 
         [ES6] Minimize ES6_CLASS_SYNTAX ifdefs

Modified: trunk/Source/_javascript_Core/bytecode/BytecodeList.json (192154 => 192155)


--- trunk/Source/_javascript_Core/bytecode/BytecodeList.json	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeList.json	2015-11-09 14:15:21 UTC (rev 192155)
@@ -127,7 +127,8 @@
             { "name" : "op_enumerator_structure_pname", "length" : 4 },
             { "name" : "op_enumerator_generic_pname", "length" : 4 },
             { "name" : "op_to_index_string", "length" : 3 },
-            { "name" : "op_load_arrowfunction_this", "length" : 2 }
+            { "name" : "op_load_arrowfunction_this", "length" : 2 },
+            { "name" : "op_assert", "length" : 3 }
         ]
     },
     {

Modified: trunk/Source/_javascript_Core/bytecode/BytecodeUseDef.h (192154 => 192155)


--- trunk/Source/_javascript_Core/bytecode/BytecodeUseDef.h	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeUseDef.h	2015-11-09 14:15:21 UTC (rev 192155)
@@ -43,6 +43,7 @@
     case op_new_regexp:
     case op_new_array_buffer:
     case op_throw_static_error:
+    case op_assert:
     case op_debug:
     case op_jneq_ptr:
     case op_loop_hint:
@@ -252,6 +253,7 @@
     case op_profile_did_call:
     case op_throw:
     case op_throw_static_error:
+    case op_assert:
     case op_debug:
     case op_ret:
     case op_jmp:

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -1488,9 +1488,16 @@
             int debugHookID = (++it)->u.operand;
             int hasBreakpointFlag = (++it)->u.operand;
             printLocationAndOp(out, exec, location, it, "debug");
-            out.printf("%s %d", debugHookName(debugHookID), hasBreakpointFlag);
+            out.printf("%s, %d", debugHookName(debugHookID), hasBreakpointFlag);
             break;
         }
+        case op_assert: {
+            int condition = (++it)->u.operand;
+            int line = (++it)->u.operand;
+            printLocationAndOp(out, exec, location, it, "assert");
+            out.printf("%s, %d", registerName(condition).data(), line);
+            break;
+        }
         case op_profile_will_call: {
             int function = (++it)->u.operand;
             printLocationOpAndRegisterOperand(out, exec, location, it, "profile_will_call", function);

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -2283,6 +2283,14 @@
     return value;
 }
 
+RegisterID* BytecodeGenerator::emitAssert(RegisterID* condition, int line)
+{
+    emitOpcode(op_assert);
+    instructions().append(condition->index());
+    instructions().append(line);
+    return condition;
+}
+
 RegisterID* BytecodeGenerator::emitCreateThis(RegisterID* dst)
 {
     size_t begin = instructions().size();

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h (192154 => 192155)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2015-11-09 14:15:21 UTC (rev 192155)
@@ -531,6 +531,8 @@
         RegisterID* emitDeleteByVal(RegisterID* dst, RegisterID* base, RegisterID* property);
         RegisterID* emitPutByIndex(RegisterID* base, unsigned index, RegisterID* value);
 
+        RegisterID* emitAssert(RegisterID* condition, int line);
+
         void emitPutGetterById(RegisterID* base, const Identifier& property, unsigned propertyDescriptorOptions, RegisterID* getter);
         void emitPutSetterById(RegisterID* base, const Identifier& property, unsigned propertyDescriptorOptions, RegisterID* setter);
         void emitPutGetterSetter(RegisterID* base, const Identifier& property, unsigned attributes, RegisterID* getter, RegisterID* setter);

Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -774,6 +774,19 @@
     return (this->*m_emitter)(generator, dst);
 }
 
+RegisterID* BytecodeIntrinsicNode::emit_intrinsic_assert(BytecodeGenerator& generator, RegisterID* dst)
+{
+#ifndef NDEBUG
+    ArgumentListNode* node = m_args->m_listNode;
+    RefPtr<RegisterID> condition = generator.emitNode(node);
+    generator.emitAssert(condition.get(), node->firstLine());
+    return dst;
+#else
+    UNUSED_PARAM(generator);
+    return dst;
+#endif
+}
+
 RegisterID* BytecodeIntrinsicNode::emit_intrinsic_putByValDirect(BytecodeGenerator& generator, RegisterID* dst)
 {
     ArgumentListNode* node = m_args->m_listNode;

Modified: trunk/Source/_javascript_Core/jit/JIT.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/jit/JIT.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/jit/JIT.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -212,6 +212,7 @@
         DEFINE_OP(op_create_scoped_arguments)
         DEFINE_OP(op_create_out_of_band_arguments)
         DEFINE_OP(op_check_tdz)
+        DEFINE_OP(op_assert)
         DEFINE_OP(op_debug)
         DEFINE_OP(op_del_by_id)
         DEFINE_OP(op_div)

Modified: trunk/Source/_javascript_Core/jit/JIT.h (192154 => 192155)


--- trunk/Source/_javascript_Core/jit/JIT.h	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/jit/JIT.h	2015-11-09 14:15:21 UTC (rev 192155)
@@ -492,6 +492,7 @@
         void emit_op_create_scoped_arguments(Instruction*);
         void emit_op_create_out_of_band_arguments(Instruction*);
         void emit_op_check_tdz(Instruction*);
+        void emit_op_assert(Instruction*);
         void emit_op_debug(Instruction*);
         void emit_op_del_by_id(Instruction*);
         void emit_op_div(Instruction*);

Modified: trunk/Source/_javascript_Core/jit/JITOpcodes.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/jit/JITOpcodes.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/jit/JITOpcodes.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -519,6 +519,12 @@
     emitPutVirtualRegister(currentInstruction[2].u.operand);
 }
 
+void JIT::emit_op_assert(Instruction* currentInstruction)
+{
+    JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_assert);
+    slowPathCall.call();
+}
+
 void JIT::emit_op_create_lexical_environment(Instruction* currentInstruction)
 {
     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_create_lexical_environment);

Modified: trunk/Source/_javascript_Core/jit/JITOpcodes32_64.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/jit/JITOpcodes32_64.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/jit/JITOpcodes32_64.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -834,6 +834,12 @@
     emitStore(thrownValue, regT1, regT0);
 }
 
+void JIT::emit_op_assert(Instruction* currentInstruction)
+{
+    JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_assert);
+    slowPathCall.call();
+}
+
 void JIT::emit_op_create_lexical_environment(Instruction* currentInstruction)
 {
     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_create_lexical_environment);

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm (192154 => 192155)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2015-11-09 14:15:21 UTC (rev 192155)
@@ -1567,6 +1567,12 @@
     dispatch(4)
 
 
+_llint_op_assert:
+    traceExecution()
+    callSlowPath(_slow_path_assert)
+    dispatch(3)
+
+
 _llint_op_create_lexical_environment:
     traceExecution()
     callSlowPath(_slow_path_create_lexical_environment)

Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (192154 => 192155)


--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h	2015-11-09 14:15:21 UTC (rev 192155)
@@ -264,6 +264,7 @@
     macro(toStringTag)
 
 #define JSC_COMMON_BYTECODE_INTRINSICS_EACH_NAME(macro) \
+    macro(assert) \
     macro(putByValDirect) \
     macro(toString)
 

Modified: trunk/Source/_javascript_Core/runtime/CommonSlowPaths.cpp (192154 => 192155)


--- trunk/Source/_javascript_Core/runtime/CommonSlowPaths.cpp	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/runtime/CommonSlowPaths.cpp	2015-11-09 14:15:21 UTC (rev 192155)
@@ -637,6 +637,13 @@
     END();
 }
 
+SLOW_PATH_DECL(slow_path_assert)
+{
+    BEGIN();
+    ASSERT_WITH_MESSAGE(OP(1).jsValue().asBoolean(), "JS assertion failed at line %d in:\n%s\n", pc[2].u.operand, exec->codeBlock()->sourceCodeForTools().data());
+    END();
+}
+
 SLOW_PATH_DECL(slow_path_create_lexical_environment)
 {
     BEGIN();

Modified: trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h (192154 => 192155)


--- trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h	2015-11-09 14:15:21 UTC (rev 192155)
@@ -289,6 +289,7 @@
 SLOW_PATH_HIDDEN_DECL(slow_path_next_generic_enumerator_pname);
 SLOW_PATH_HIDDEN_DECL(slow_path_to_index_string);
 SLOW_PATH_HIDDEN_DECL(slow_path_profile_type_clear_log);
+SLOW_PATH_HIDDEN_DECL(slow_path_assert);
 SLOW_PATH_HIDDEN_DECL(slow_path_create_lexical_environment);
 SLOW_PATH_HIDDEN_DECL(slow_path_push_with_scope);
 SLOW_PATH_HIDDEN_DECL(slow_path_resolve_scope);

Modified: trunk/Source/WebCore/ChangeLog (192154 => 192155)


--- trunk/Source/WebCore/ChangeLog	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/WebCore/ChangeLog	2015-11-09 14:15:21 UTC (rev 192155)
@@ -1,3 +1,13 @@
+2015-11-09  Youenn Fablet  <youenn.fab...@crf.canon.fr>
+
+        JS Built-ins functions should be able to assert
+        https://bugs.webkit.org/show_bug.cgi?id=150333
+
+        Reviewed by Yusuke Suzuki.
+
+        * Modules/streams/ReadableStreamInternals.js:
+        (privateInitializeReadableStreamReader): Activating an @assert.
+
 2015-11-02  Sergio Villar Senin  <svil...@igalia.com>
 
         [css-grid] Improve grid container sizing with size constraints and intrinsic sizes

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (192154 => 192155)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2015-11-09 12:56:43 UTC (rev 192154)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2015-11-09 14:15:21 UTC (rev 192155)
@@ -51,7 +51,7 @@
         this.@closedPromiseCapability = { @promise: @Promise.@resolve() };
         return this;
     }
-    // FIXME: ASSERT(stream.@state === @streamErrored);
+    @assert(stream.@state === @streamErrored);
     this.@ownerReadableStream = null;
     this.@storedError = stream.@storedError;
     this.@closedPromiseCapability = { @promise: @Promise.@reject(stream.@storedError) };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to