fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | c7657a0 | 2018-04-09 17:42:01 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014-2018 Apple Inc. All rights reserved. |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "FTLOperations.h" |
| 28 | |
| 29 | #if ENABLE(FTL_JIT) |
| 30 | |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 31 | #include "BytecodeStructs.h" |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 32 | #include "ClonedArguments.h" |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 33 | #include "CommonSlowPaths.h" |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 34 | #include "DirectArguments.h" |
fpizlo@apple.com | 6e69796 | 2015-10-12 17:56:26 +0000 | [diff] [blame] | 35 | #include "FTLJITCode.h" |
| 36 | #include "FTLLazySlowPath.h" |
ggaren@apple.com | 21cd702 | 2015-08-18 18:28:54 +0000 | [diff] [blame] | 37 | #include "InlineCallFrame.h" |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 38 | #include "Interpreter.h" |
caitp@igalia.com | 8bc562d | 2016-11-14 21:14:15 +0000 | [diff] [blame] | 39 | #include "JSAsyncFunction.h" |
gskachkov@gmail.com | ab749fd | 2017-08-23 17:05:33 +0000 | [diff] [blame] | 40 | #include "JSAsyncGeneratorFunction.h" |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 41 | #include "JSCInlines.h" |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 42 | #include "JSFixedArray.h" |
utatane.tea@gmail.com | 9d9fd32 | 2015-12-17 10:33:08 +0000 | [diff] [blame] | 43 | #include "JSGeneratorFunction.h" |
keith_miller@apple.com | c02f5d3 | 2018-05-22 18:04:31 +0000 | [diff] [blame] | 44 | #include "JSImmutableButterfly.h" |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 45 | #include "JSLexicalEnvironment.h" |
utatane.tea@gmail.com | 19a21f0 | 2018-01-18 04:17:32 +0000 | [diff] [blame] | 46 | #include "RegExpObject.h" |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 47 | |
| 48 | namespace JSC { namespace FTL { |
| 49 | |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 50 | extern "C" void JIT_OPERATION operationPopulateObjectInOSR( |
| 51 | ExecState* exec, ExitTimeObjectMaterialization* materialization, |
| 52 | EncodedJSValue* encodedValue, EncodedJSValue* values) |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 53 | { |
keith_miller@apple.com | 504d585 | 2017-09-13 01:31:07 +0000 | [diff] [blame] | 54 | using namespace DFG; |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 55 | VM& vm = exec->vm(); |
| 56 | CodeBlock* codeBlock = exec->codeBlock(); |
| 57 | |
| 58 | // We cannot GC. We've got pointers in evil places. |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 59 | // FIXME: We are not doing anything that can GC here, and this is |
| 60 | // probably unnecessary. |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 61 | DeferGCForAWhile deferGC(vm.heap); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 62 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 63 | switch (materialization->type()) { |
| 64 | case PhantomNewObject: { |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 65 | JSFinalObject* object = jsCast<JSFinalObject*>(JSValue::decode(*encodedValue)); |
utatane.tea@gmail.com | b860d69 | 2018-05-31 06:19:33 +0000 | [diff] [blame] | 66 | Structure* structure = object->structure(vm); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 67 | |
| 68 | // Figure out what the heck to populate the object with. Use |
| 69 | // getPropertiesConcurrently() because that happens to be |
| 70 | // lower-level and more convenient. It doesn't change the |
| 71 | // materialization of the property table. We want to have |
| 72 | // minimal visible effects on the system. Also, don't mind |
| 73 | // that this is O(n^2). It doesn't matter. We only get here |
| 74 | // from OSR exit. |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 75 | for (PropertyMapEntry entry : structure->getPropertiesConcurrently()) { |
| 76 | for (unsigned i = materialization->properties().size(); i--;) { |
| 77 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 78 | if (property.location().kind() != NamedPropertyPLoc) |
| 79 | continue; |
| 80 | if (codeBlock->identifier(property.location().info()).impl() != entry.key) |
| 81 | continue; |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 82 | |
| 83 | object->putDirect(vm, entry.offset, JSValue::decode(values[i])); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 84 | } |
| 85 | } |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 86 | break; |
| 87 | } |
| 88 | |
| 89 | case PhantomNewFunction: |
utatane.tea@gmail.com | 9d9fd32 | 2015-12-17 10:33:08 +0000 | [diff] [blame] | 90 | case PhantomNewGeneratorFunction: |
caitp@igalia.com | 8bc562d | 2016-11-14 21:14:15 +0000 | [diff] [blame] | 91 | case PhantomNewAsyncFunction: |
gskachkov@gmail.com | ab749fd | 2017-08-23 17:05:33 +0000 | [diff] [blame] | 92 | case PhantomNewAsyncGeneratorFunction: |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 93 | case PhantomDirectArguments: |
| 94 | case PhantomClonedArguments: |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 95 | case PhantomCreateRest: |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 96 | case PhantomSpread: |
| 97 | case PhantomNewArrayWithSpread: |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 98 | case PhantomNewArrayBuffer: |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 99 | // Those are completely handled by operationMaterializeObjectInOSR |
| 100 | break; |
| 101 | |
| 102 | case PhantomCreateActivation: { |
| 103 | JSLexicalEnvironment* activation = jsCast<JSLexicalEnvironment*>(JSValue::decode(*encodedValue)); |
| 104 | |
| 105 | // Figure out what to populate the activation with |
| 106 | for (unsigned i = materialization->properties().size(); i--;) { |
| 107 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 108 | if (property.location().kind() != ClosureVarPLoc) |
| 109 | continue; |
| 110 | |
mark.lam@apple.com | 23e9624 | 2017-09-09 16:21:45 +0000 | [diff] [blame] | 111 | activation->variableAt(ScopeOffset(property.location().info())).set(vm, activation, JSValue::decode(values[i])); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | break; |
| 115 | } |
| 116 | |
utatane.tea@gmail.com | 19a21f0 | 2018-01-18 04:17:32 +0000 | [diff] [blame] | 117 | case PhantomNewRegexp: { |
| 118 | RegExpObject* regExpObject = jsCast<RegExpObject*>(JSValue::decode(*encodedValue)); |
| 119 | |
| 120 | for (unsigned i = materialization->properties().size(); i--;) { |
| 121 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 122 | if (property.location().kind() != RegExpObjectLastIndexPLoc) |
| 123 | continue; |
| 124 | |
| 125 | regExpObject->setLastIndex(exec, JSValue::decode(values[i]), false /* shouldThrow */); |
| 126 | break; |
| 127 | } |
| 128 | break; |
| 129 | } |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 130 | |
| 131 | default: |
| 132 | RELEASE_ASSERT_NOT_REACHED(); |
| 133 | break; |
| 134 | |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | extern "C" JSCell* JIT_OPERATION operationMaterializeObjectInOSR( |
| 139 | ExecState* exec, ExitTimeObjectMaterialization* materialization, EncodedJSValue* values) |
| 140 | { |
keith_miller@apple.com | 504d585 | 2017-09-13 01:31:07 +0000 | [diff] [blame] | 141 | using namespace DFG; |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 142 | VM& vm = exec->vm(); |
| 143 | |
| 144 | // We cannot GC. We've got pointers in evil places. |
| 145 | DeferGCForAWhile deferGC(vm.heap); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 146 | |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 147 | switch (materialization->type()) { |
| 148 | case PhantomNewObject: { |
| 149 | // Figure out what the structure is |
| 150 | Structure* structure = nullptr; |
| 151 | for (unsigned i = materialization->properties().size(); i--;) { |
| 152 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 153 | if (property.location() != PromotedLocationDescriptor(StructurePLoc)) |
| 154 | continue; |
| 155 | |
utatane.tea@gmail.com | dd7199d | 2018-03-08 16:06:48 +0000 | [diff] [blame] | 156 | RELEASE_ASSERT(JSValue::decode(values[i]).asCell()->inherits<Structure>(vm)); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 157 | structure = jsCast<Structure*>(JSValue::decode(values[i])); |
| 158 | break; |
| 159 | } |
| 160 | RELEASE_ASSERT(structure); |
| 161 | |
| 162 | JSFinalObject* result = JSFinalObject::create(vm, structure); |
| 163 | |
| 164 | // The real values will be put subsequently by |
| 165 | // operationPopulateNewObjectInOSR. We can't fill them in |
| 166 | // now, because they may not be available yet (typically |
| 167 | // because we have a cyclic dependency graph). |
| 168 | |
| 169 | // We put a dummy value here in order to avoid super-subtle |
| 170 | // GC-and-OSR-exit crashes in case we have a bug and some |
| 171 | // field is, for any reason, not filled later. |
| 172 | // We use a random-ish number instead of a sensible value like |
| 173 | // undefined to make possible bugs easier to track. |
| 174 | for (PropertyMapEntry entry : structure->getPropertiesConcurrently()) |
| 175 | result->putDirect(vm, entry.offset, jsNumber(19723)); |
| 176 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 177 | return result; |
| 178 | } |
commit-queue@webkit.org | 88ab4e7 | 2015-04-24 02:23:36 +0000 | [diff] [blame] | 179 | |
utatane.tea@gmail.com | 9d9fd32 | 2015-12-17 10:33:08 +0000 | [diff] [blame] | 180 | case PhantomNewFunction: |
caitp@igalia.com | 8bc562d | 2016-11-14 21:14:15 +0000 | [diff] [blame] | 181 | case PhantomNewGeneratorFunction: |
gskachkov@gmail.com | ab749fd | 2017-08-23 17:05:33 +0000 | [diff] [blame] | 182 | case PhantomNewAsyncGeneratorFunction: |
caitp@igalia.com | 8bc562d | 2016-11-14 21:14:15 +0000 | [diff] [blame] | 183 | case PhantomNewAsyncFunction: { |
commit-queue@webkit.org | 88ab4e7 | 2015-04-24 02:23:36 +0000 | [diff] [blame] | 184 | // Figure out what the executable and activation are |
| 185 | FunctionExecutable* executable = nullptr; |
| 186 | JSScope* activation = nullptr; |
| 187 | for (unsigned i = materialization->properties().size(); i--;) { |
| 188 | const ExitPropertyValue& property = materialization->properties()[i]; |
sbarati@apple.com | 78e87c7 | 2017-02-11 04:05:06 +0000 | [diff] [blame] | 189 | if (property.location() == PromotedLocationDescriptor(FunctionExecutablePLoc)) { |
utatane.tea@gmail.com | dd7199d | 2018-03-08 16:06:48 +0000 | [diff] [blame] | 190 | RELEASE_ASSERT(JSValue::decode(values[i]).asCell()->inherits<FunctionExecutable>(vm)); |
commit-queue@webkit.org | 88ab4e7 | 2015-04-24 02:23:36 +0000 | [diff] [blame] | 191 | executable = jsCast<FunctionExecutable*>(JSValue::decode(values[i])); |
sbarati@apple.com | 78e87c7 | 2017-02-11 04:05:06 +0000 | [diff] [blame] | 192 | } |
| 193 | if (property.location() == PromotedLocationDescriptor(FunctionActivationPLoc)) { |
utatane.tea@gmail.com | dd7199d | 2018-03-08 16:06:48 +0000 | [diff] [blame] | 194 | RELEASE_ASSERT(JSValue::decode(values[i]).asCell()->inherits<JSScope>(vm)); |
commit-queue@webkit.org | 88ab4e7 | 2015-04-24 02:23:36 +0000 | [diff] [blame] | 195 | activation = jsCast<JSScope*>(JSValue::decode(values[i])); |
sbarati@apple.com | 78e87c7 | 2017-02-11 04:05:06 +0000 | [diff] [blame] | 196 | } |
commit-queue@webkit.org | 88ab4e7 | 2015-04-24 02:23:36 +0000 | [diff] [blame] | 197 | } |
| 198 | RELEASE_ASSERT(executable && activation); |
| 199 | |
utatane.tea@gmail.com | 9d9fd32 | 2015-12-17 10:33:08 +0000 | [diff] [blame] | 200 | if (materialization->type() == PhantomNewFunction) |
| 201 | return JSFunction::createWithInvalidatedReallocationWatchpoint(vm, executable, activation); |
caitp@igalia.com | 8bc562d | 2016-11-14 21:14:15 +0000 | [diff] [blame] | 202 | else if (materialization->type() == PhantomNewGeneratorFunction) |
| 203 | return JSGeneratorFunction::createWithInvalidatedReallocationWatchpoint(vm, executable, activation); |
gskachkov@gmail.com | ab749fd | 2017-08-23 17:05:33 +0000 | [diff] [blame] | 204 | else if (materialization->type() == PhantomNewAsyncGeneratorFunction) |
| 205 | return JSAsyncGeneratorFunction::createWithInvalidatedReallocationWatchpoint(vm, executable, activation); |
caitp@igalia.com | 8bc562d | 2016-11-14 21:14:15 +0000 | [diff] [blame] | 206 | ASSERT(materialization->type() == PhantomNewAsyncFunction); |
| 207 | return JSAsyncFunction::createWithInvalidatedReallocationWatchpoint(vm, executable, activation); |
commit-queue@webkit.org | 88ab4e7 | 2015-04-24 02:23:36 +0000 | [diff] [blame] | 208 | } |
| 209 | |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 210 | case PhantomCreateActivation: { |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 211 | // Figure out what the scope and symbol table are |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 212 | JSScope* scope = nullptr; |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 213 | SymbolTable* table = nullptr; |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 214 | for (unsigned i = materialization->properties().size(); i--;) { |
| 215 | const ExitPropertyValue& property = materialization->properties()[i]; |
sbarati@apple.com | 78e87c7 | 2017-02-11 04:05:06 +0000 | [diff] [blame] | 216 | if (property.location() == PromotedLocationDescriptor(ActivationScopePLoc)) { |
utatane.tea@gmail.com | dd7199d | 2018-03-08 16:06:48 +0000 | [diff] [blame] | 217 | RELEASE_ASSERT(JSValue::decode(values[i]).asCell()->inherits<JSScope>(vm)); |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 218 | scope = jsCast<JSScope*>(JSValue::decode(values[i])); |
sbarati@apple.com | 78e87c7 | 2017-02-11 04:05:06 +0000 | [diff] [blame] | 219 | } else if (property.location() == PromotedLocationDescriptor(ActivationSymbolTablePLoc)) { |
utatane.tea@gmail.com | dd7199d | 2018-03-08 16:06:48 +0000 | [diff] [blame] | 220 | RELEASE_ASSERT(JSValue::decode(values[i]).asCell()->inherits<SymbolTable>(vm)); |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 221 | table = jsCast<SymbolTable*>(JSValue::decode(values[i])); |
sbarati@apple.com | 78e87c7 | 2017-02-11 04:05:06 +0000 | [diff] [blame] | 222 | } |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 223 | } |
| 224 | RELEASE_ASSERT(scope); |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 225 | RELEASE_ASSERT(table); |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 226 | |
| 227 | CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock( |
sbarati@apple.com | 0d9999e0 | 2018-09-26 03:14:09 +0000 | [diff] [blame] | 228 | materialization->origin(), exec->codeBlock()->baselineAlternative()); |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 229 | Structure* structure = codeBlock->globalObject()->activationStructure(); |
| 230 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 231 | // It doesn't matter what values we initialize as bottom values inside the activation constructor because |
| 232 | // activation sinking will set bottom values for each slot. |
| 233 | // FIXME: Slight optimization would be to create a constructor that doesn't initialize all slots. |
| 234 | JSLexicalEnvironment* result = JSLexicalEnvironment::create(vm, structure, scope, table, jsUndefined()); |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 235 | |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 236 | RELEASE_ASSERT(materialization->properties().size() - 2 == table->scopeSize()); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 237 | |
| 238 | // The real values will be put subsequently by |
| 239 | // operationPopulateNewObjectInOSR. See the PhantomNewObject |
| 240 | // case for details. |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 241 | for (unsigned i = materialization->properties().size(); i--;) { |
| 242 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 243 | if (property.location().kind() != ClosureVarPLoc) |
| 244 | continue; |
| 245 | |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 246 | result->variableAt(ScopeOffset(property.location().info())).set( |
mark.lam@apple.com | 23e9624 | 2017-09-09 16:21:45 +0000 | [diff] [blame] | 247 | vm, result, jsNumber(29834)); |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 248 | } |
| 249 | |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 250 | if (validationEnabled()) { |
| 251 | // Validate to make sure every slot in the scope has one value. |
fpizlo@apple.com | 171d06f | 2016-11-15 23:21:50 +0000 | [diff] [blame] | 252 | ConcurrentJSLocker locker(table->m_lock); |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 253 | for (auto iter = table->begin(locker), end = table->end(locker); iter != end; ++iter) { |
| 254 | bool found = false; |
| 255 | for (unsigned i = materialization->properties().size(); i--;) { |
| 256 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 257 | if (property.location().kind() != ClosureVarPLoc) |
| 258 | continue; |
| 259 | if (ScopeOffset(property.location().info()) == iter->value.scopeOffset()) { |
| 260 | found = true; |
| 261 | break; |
| 262 | } |
| 263 | } |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 264 | ASSERT_UNUSED(found, found); |
saambarati1@gmail.com | 402b585 | 2015-05-22 02:39:25 +0000 | [diff] [blame] | 265 | } |
| 266 | unsigned numberOfClosureVarPloc = 0; |
| 267 | for (unsigned i = materialization->properties().size(); i--;) { |
| 268 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 269 | if (property.location().kind() == ClosureVarPLoc) |
| 270 | numberOfClosureVarPloc++; |
| 271 | } |
| 272 | ASSERT(numberOfClosureVarPloc == table->scopeSize()); |
| 273 | } |
| 274 | |
basile_clement@apple.com | 2ca1f7b | 2015-05-05 16:34:21 +0000 | [diff] [blame] | 275 | return result; |
| 276 | } |
| 277 | |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 278 | case PhantomCreateRest: |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 279 | case PhantomDirectArguments: |
| 280 | case PhantomClonedArguments: { |
| 281 | if (!materialization->origin().inlineCallFrame) { |
| 282 | switch (materialization->type()) { |
| 283 | case PhantomDirectArguments: |
| 284 | return DirectArguments::createByCopying(exec); |
| 285 | case PhantomClonedArguments: |
| 286 | return ClonedArguments::createWithMachineFrame(exec, exec, ArgumentsMode::Cloned); |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 287 | case PhantomCreateRest: { |
| 288 | CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock( |
sbarati@apple.com | 0d9999e0 | 2018-09-26 03:14:09 +0000 | [diff] [blame] | 289 | materialization->origin(), exec->codeBlock()->baselineAlternative()); |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 290 | |
utatane.tea@gmail.com | 463aee1 | 2017-03-16 13:24:46 +0000 | [diff] [blame] | 291 | unsigned numberOfArgumentsToSkip = codeBlock->numberOfArgumentsToSkip(); |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 292 | JSGlobalObject* globalObject = codeBlock->globalObject(); |
| 293 | Structure* structure = globalObject->restParameterStructure(); |
| 294 | JSValue* argumentsToCopyRegion = exec->addressOfArgumentsStart() + numberOfArgumentsToSkip; |
| 295 | unsigned arraySize = exec->argumentCount() > numberOfArgumentsToSkip ? exec->argumentCount() - numberOfArgumentsToSkip : 0; |
| 296 | return constructArray(exec, structure, argumentsToCopyRegion, arraySize); |
| 297 | } |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 298 | default: |
| 299 | RELEASE_ASSERT_NOT_REACHED(); |
| 300 | return nullptr; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // First figure out the argument count. If there isn't one then we represent the machine frame. |
| 305 | unsigned argumentCount = 0; |
| 306 | if (materialization->origin().inlineCallFrame->isVarargs()) { |
| 307 | for (unsigned i = materialization->properties().size(); i--;) { |
| 308 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 309 | if (property.location() != PromotedLocationDescriptor(ArgumentCountPLoc)) |
| 310 | continue; |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 311 | argumentCount = JSValue::decode(values[i]).asUInt32(); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 312 | break; |
| 313 | } |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 314 | } else |
utatane.tea@gmail.com | 0c7cd0b | 2017-09-02 08:35:46 +0000 | [diff] [blame] | 315 | argumentCount = materialization->origin().inlineCallFrame->argumentCountIncludingThis; |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 316 | RELEASE_ASSERT(argumentCount); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 317 | |
| 318 | JSFunction* callee = nullptr; |
| 319 | if (materialization->origin().inlineCallFrame->isClosureCall) { |
| 320 | for (unsigned i = materialization->properties().size(); i--;) { |
| 321 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 322 | if (property.location() != PromotedLocationDescriptor(ArgumentsCalleePLoc)) |
| 323 | continue; |
| 324 | |
| 325 | callee = jsCast<JSFunction*>(JSValue::decode(values[i])); |
| 326 | break; |
| 327 | } |
| 328 | } else |
| 329 | callee = materialization->origin().inlineCallFrame->calleeConstant(); |
| 330 | RELEASE_ASSERT(callee); |
| 331 | |
| 332 | CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock( |
sbarati@apple.com | 0d9999e0 | 2018-09-26 03:14:09 +0000 | [diff] [blame] | 333 | materialization->origin(), exec->codeBlock()->baselineAlternative()); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 334 | |
| 335 | // We have an inline frame and we have all of the data we need to recreate it. |
| 336 | switch (materialization->type()) { |
| 337 | case PhantomDirectArguments: { |
| 338 | unsigned length = argumentCount - 1; |
| 339 | unsigned capacity = std::max(length, static_cast<unsigned>(codeBlock->numParameters() - 1)); |
| 340 | DirectArguments* result = DirectArguments::create( |
| 341 | vm, codeBlock->globalObject()->directArgumentsStructure(), length, capacity); |
fpizlo@apple.com | 92acb5a | 2018-03-22 02:15:44 +0000 | [diff] [blame] | 342 | result->setCallee(vm, callee); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 343 | for (unsigned i = materialization->properties().size(); i--;) { |
| 344 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 345 | if (property.location().kind() != ArgumentPLoc) |
| 346 | continue; |
| 347 | |
| 348 | unsigned index = property.location().info(); |
| 349 | if (index >= capacity) |
| 350 | continue; |
fpizlo@apple.com | 49b1d72 | 2015-05-18 03:39:28 +0000 | [diff] [blame] | 351 | |
| 352 | // We don't want to use setIndexQuickly(), since that's only for the passed-in |
| 353 | // arguments but sometimes the number of named arguments is greater. For |
| 354 | // example: |
| 355 | // |
| 356 | // function foo(a, b, c) { ... } |
| 357 | // foo(); |
| 358 | // |
| 359 | // setIndexQuickly() would fail for indices 0, 1, 2 - but we need to recover |
| 360 | // those here. |
| 361 | result->argument(DirectArgumentsOffset(index)).set( |
| 362 | vm, result, JSValue::decode(values[i])); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 363 | } |
| 364 | return result; |
| 365 | } |
| 366 | case PhantomClonedArguments: { |
| 367 | unsigned length = argumentCount - 1; |
| 368 | ClonedArguments* result = ClonedArguments::createEmpty( |
keith_miller@apple.com | 2636739 | 2016-03-14 20:55:15 +0000 | [diff] [blame] | 369 | vm, codeBlock->globalObject()->clonedArgumentsStructure(), callee, length); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 370 | |
| 371 | for (unsigned i = materialization->properties().size(); i--;) { |
| 372 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 373 | if (property.location().kind() != ArgumentPLoc) |
| 374 | continue; |
| 375 | |
| 376 | unsigned index = property.location().info(); |
| 377 | if (index >= length) |
| 378 | continue; |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 379 | result->putDirectIndex(exec, index, JSValue::decode(values[i])); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 380 | } |
| 381 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 382 | return result; |
| 383 | } |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 384 | case PhantomCreateRest: { |
utatane.tea@gmail.com | 463aee1 | 2017-03-16 13:24:46 +0000 | [diff] [blame] | 385 | unsigned numberOfArgumentsToSkip = codeBlock->numberOfArgumentsToSkip(); |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 386 | JSGlobalObject* globalObject = codeBlock->globalObject(); |
| 387 | Structure* structure = globalObject->restParameterStructure(); |
| 388 | ASSERT(argumentCount > 0); |
| 389 | unsigned arraySize = (argumentCount - 1) > numberOfArgumentsToSkip ? argumentCount - 1 - numberOfArgumentsToSkip : 0; |
mark.lam@apple.com | c2e98e8 | 2017-03-23 20:31:18 +0000 | [diff] [blame] | 390 | |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 391 | // FIXME: we should throw an out of memory error here if tryCreate() fails. |
mark.lam@apple.com | c2e98e8 | 2017-03-23 20:31:18 +0000 | [diff] [blame] | 392 | // https://bugs.webkit.org/show_bug.cgi?id=169784 |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 393 | JSArray* array = JSArray::tryCreate(vm, structure, arraySize); |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 394 | RELEASE_ASSERT(array); |
| 395 | |
| 396 | for (unsigned i = materialization->properties().size(); i--;) { |
| 397 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 398 | if (property.location().kind() != ArgumentPLoc) |
| 399 | continue; |
| 400 | |
| 401 | unsigned argIndex = property.location().info(); |
| 402 | if (numberOfArgumentsToSkip > argIndex) |
| 403 | continue; |
| 404 | unsigned arrayIndex = argIndex - numberOfArgumentsToSkip; |
| 405 | if (arrayIndex >= arraySize) |
| 406 | continue; |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 407 | array->putDirectIndex(exec, arrayIndex, JSValue::decode(values[i])); |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | #if !ASSERT_DISABLED |
| 411 | // We avoid this O(n^2) loop when asserts are disabled, but the condition checked here |
| 412 | // must hold to ensure the correctness of the above loop because of how we allocate the array. |
| 413 | for (unsigned targetIndex = 0; targetIndex < arraySize; ++targetIndex) { |
| 414 | bool found = false; |
| 415 | for (unsigned i = materialization->properties().size(); i--;) { |
| 416 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 417 | if (property.location().kind() != ArgumentPLoc) |
| 418 | continue; |
| 419 | |
| 420 | unsigned argIndex = property.location().info(); |
| 421 | if (numberOfArgumentsToSkip > argIndex) |
| 422 | continue; |
| 423 | unsigned arrayIndex = argIndex - numberOfArgumentsToSkip; |
| 424 | if (arrayIndex >= arraySize) |
| 425 | continue; |
| 426 | if (arrayIndex == targetIndex) { |
| 427 | found = true; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | ASSERT(found); |
| 432 | } |
| 433 | #endif |
sbarati@apple.com | 7a74ce7 | 2016-11-01 20:03:03 +0000 | [diff] [blame] | 434 | return array; |
| 435 | } |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 436 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 437 | default: |
| 438 | RELEASE_ASSERT_NOT_REACHED(); |
| 439 | return nullptr; |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 442 | |
| 443 | case PhantomSpread: { |
| 444 | JSArray* array = nullptr; |
| 445 | for (unsigned i = materialization->properties().size(); i--;) { |
| 446 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 447 | if (property.location().kind() == SpreadPLoc) { |
| 448 | array = jsCast<JSArray*>(JSValue::decode(values[i])); |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | RELEASE_ASSERT(array); |
| 453 | |
| 454 | // Note: it is sound for JSFixedArray::createFromArray to call getDirectIndex here |
| 455 | // because we're guaranteed we won't be calling any getters. The reason for this is |
| 456 | // that we only support PhantomSpread over CreateRest, which is an array we create. |
| 457 | // Any attempts to put a getter on any indices on the rest array will escape the array. |
| 458 | JSFixedArray* fixedArray = JSFixedArray::createFromArray(exec, vm, array); |
mark.lam@apple.com | b269fb9 | 2017-04-28 04:15:00 +0000 | [diff] [blame] | 459 | RELEASE_ASSERT(fixedArray); |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 460 | return fixedArray; |
| 461 | } |
| 462 | |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 463 | case PhantomNewArrayBuffer: { |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 464 | JSImmutableButterfly* immutableButterfly = nullptr; |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 465 | for (unsigned i = materialization->properties().size(); i--;) { |
| 466 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 467 | if (property.location().kind() == NewArrayBufferPLoc) { |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 468 | immutableButterfly = jsCast<JSImmutableButterfly*>(JSValue::decode(values[i])); |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 469 | break; |
| 470 | } |
| 471 | } |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 472 | RELEASE_ASSERT(immutableButterfly); |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 473 | |
| 474 | // For now, we use array allocation profile in the actual CodeBlock. It is OK since current NewArrayBuffer |
| 475 | // and PhantomNewArrayBuffer are always bound to a specific op_new_array_buffer. |
sbarati@apple.com | 0d9999e0 | 2018-09-26 03:14:09 +0000 | [diff] [blame] | 476 | CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock(materialization->origin(), exec->codeBlock()->baselineAlternative()); |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 477 | Instruction* currentInstruction = &codeBlock->instructions()[materialization->origin().bytecodeIndex]; |
| 478 | RELEASE_ASSERT(Interpreter::getOpcodeID(currentInstruction[0].u.opcode) == op_new_array_buffer); |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 479 | auto* newArrayBuffer = bitwise_cast<OpNewArrayBuffer*>(currentInstruction); |
| 480 | ArrayAllocationProfile* profile = currentInstruction[3].u.arrayAllocationProfile; |
| 481 | |
| 482 | // FIXME: Share the code with CommonSlowPaths. Currently, codeBlock etc. are slightly different. |
| 483 | IndexingType indexingMode = profile->selectIndexingType(); |
| 484 | Structure* structure = exec->lexicalGlobalObject()->arrayStructureForIndexingTypeDuringAllocation(indexingMode); |
| 485 | ASSERT(isCopyOnWrite(indexingMode)); |
keith_miller@apple.com | c02f5d3 | 2018-05-22 18:04:31 +0000 | [diff] [blame] | 486 | ASSERT(!structure->outOfLineCapacity()); |
utatane.tea@gmail.com | 7b95a22 | 2018-06-16 16:33:58 +0000 | [diff] [blame] | 487 | |
| 488 | if (UNLIKELY(immutableButterfly->indexingMode() != indexingMode)) { |
| 489 | auto* newButterfly = JSImmutableButterfly::create(vm, indexingMode, immutableButterfly->length()); |
| 490 | for (unsigned i = 0; i < immutableButterfly->length(); ++i) |
| 491 | newButterfly->setIndex(vm, i, immutableButterfly->get(i)); |
| 492 | immutableButterfly = newButterfly; |
| 493 | |
| 494 | // FIXME: This is kinda gross and only works because we can't inline new_array_bufffer in the baseline. |
| 495 | // We also cannot allocate a new butterfly from compilation threads since it's invalid to allocate cells from |
| 496 | // a compilation thread. |
| 497 | WTF::storeStoreFence(); |
| 498 | codeBlock->constantRegister(newArrayBuffer->immutableButterfly()).set(vm, codeBlock, immutableButterfly); |
| 499 | WTF::storeStoreFence(); |
| 500 | } |
| 501 | |
| 502 | JSArray* result = CommonSlowPaths::allocateNewArrayBuffer(vm, structure, immutableButterfly); |
| 503 | ArrayAllocationProfile::updateLastAllocationFor(profile, result); |
| 504 | return result; |
utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 505 | } |
| 506 | |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 507 | case PhantomNewArrayWithSpread: { |
| 508 | CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock( |
sbarati@apple.com | 0d9999e0 | 2018-09-26 03:14:09 +0000 | [diff] [blame] | 509 | materialization->origin(), exec->codeBlock()->baselineAlternative()); |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 510 | JSGlobalObject* globalObject = codeBlock->globalObject(); |
| 511 | Structure* structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); |
| 512 | |
mark.lam@apple.com | 61dbb71 | 2017-03-16 21:53:33 +0000 | [diff] [blame] | 513 | Checked<unsigned, RecordOverflow> checkedArraySize = 0; |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 514 | unsigned numProperties = 0; |
| 515 | for (unsigned i = materialization->properties().size(); i--;) { |
| 516 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 517 | if (property.location().kind() == NewArrayWithSpreadArgumentPLoc) { |
| 518 | ++numProperties; |
| 519 | JSValue value = JSValue::decode(values[i]); |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 520 | if (JSFixedArray* fixedArray = jsDynamicCast<JSFixedArray*>(vm, value)) |
mark.lam@apple.com | 61dbb71 | 2017-03-16 21:53:33 +0000 | [diff] [blame] | 521 | checkedArraySize += fixedArray->size(); |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 522 | else |
mark.lam@apple.com | 61dbb71 | 2017-03-16 21:53:33 +0000 | [diff] [blame] | 523 | checkedArraySize += 1; |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 527 | // FIXME: we should throw an out of memory error here if checkedArraySize has hasOverflowed() or tryCreate() fails. |
mark.lam@apple.com | c2e98e8 | 2017-03-23 20:31:18 +0000 | [diff] [blame] | 528 | // https://bugs.webkit.org/show_bug.cgi?id=169784 |
mark.lam@apple.com | 61dbb71 | 2017-03-16 21:53:33 +0000 | [diff] [blame] | 529 | unsigned arraySize = checkedArraySize.unsafeGet(); // Crashes if overflowed. |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 530 | JSArray* result = JSArray::tryCreate(vm, structure, arraySize); |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 531 | RELEASE_ASSERT(result); |
| 532 | |
| 533 | #if !ASSERT_DISABLED |
| 534 | // Ensure we see indices for everything in the range: [0, numProperties) |
| 535 | for (unsigned i = 0; i < numProperties; ++i) { |
| 536 | bool found = false; |
| 537 | for (unsigned j = 0; j < materialization->properties().size(); ++j) { |
| 538 | const ExitPropertyValue& property = materialization->properties()[j]; |
| 539 | if (property.location().kind() == NewArrayWithSpreadArgumentPLoc && property.location().info() == i) { |
| 540 | found = true; |
| 541 | break; |
| 542 | } |
| 543 | } |
| 544 | ASSERT(found); |
| 545 | } |
| 546 | #endif |
| 547 | |
| 548 | Vector<JSValue, 8> arguments; |
| 549 | arguments.grow(numProperties); |
| 550 | |
| 551 | for (unsigned i = materialization->properties().size(); i--;) { |
| 552 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 553 | if (property.location().kind() == NewArrayWithSpreadArgumentPLoc) { |
| 554 | JSValue value = JSValue::decode(values[i]); |
| 555 | RELEASE_ASSERT(property.location().info() < numProperties); |
| 556 | arguments[property.location().info()] = value; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | unsigned arrayIndex = 0; |
| 561 | for (JSValue value : arguments) { |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 562 | if (JSFixedArray* fixedArray = jsDynamicCast<JSFixedArray*>(vm, value)) { |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 563 | for (unsigned i = 0; i < fixedArray->size(); i++) { |
| 564 | ASSERT(fixedArray->get(i)); |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 565 | result->putDirectIndex(exec, arrayIndex, fixedArray->get(i)); |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 566 | ++arrayIndex; |
| 567 | } |
| 568 | } else { |
| 569 | // We are not spreading. |
mark.lam@apple.com | 2147640 | 2017-04-27 19:24:07 +0000 | [diff] [blame] | 570 | result->putDirectIndex(exec, arrayIndex, value); |
sbarati@apple.com | e20444a | 2016-11-30 06:24:44 +0000 | [diff] [blame] | 571 | ++arrayIndex; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | return result; |
| 576 | } |
| 577 | |
utatane.tea@gmail.com | 19a21f0 | 2018-01-18 04:17:32 +0000 | [diff] [blame] | 578 | case PhantomNewRegexp: { |
| 579 | RegExp* regExp = nullptr; |
| 580 | for (unsigned i = materialization->properties().size(); i--;) { |
| 581 | const ExitPropertyValue& property = materialization->properties()[i]; |
| 582 | if (property.location() == PromotedLocationDescriptor(RegExpObjectRegExpPLoc)) { |
utatane.tea@gmail.com | dd7199d | 2018-03-08 16:06:48 +0000 | [diff] [blame] | 583 | RELEASE_ASSERT(JSValue::decode(values[i]).asCell()->inherits<RegExp>(vm)); |
utatane.tea@gmail.com | 19a21f0 | 2018-01-18 04:17:32 +0000 | [diff] [blame] | 584 | regExp = jsCast<RegExp*>(JSValue::decode(values[i])); |
| 585 | } |
| 586 | } |
| 587 | RELEASE_ASSERT(regExp); |
sbarati@apple.com | 0d9999e0 | 2018-09-26 03:14:09 +0000 | [diff] [blame] | 588 | CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock(materialization->origin(), exec->codeBlock()->baselineAlternative()); |
utatane.tea@gmail.com | 19a21f0 | 2018-01-18 04:17:32 +0000 | [diff] [blame] | 589 | Structure* structure = codeBlock->globalObject()->regExpStructure(); |
| 590 | return RegExpObject::create(vm, structure, regExp); |
| 591 | } |
| 592 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 593 | default: |
| 594 | RELEASE_ASSERT_NOT_REACHED(); |
| 595 | return nullptr; |
| 596 | } |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 597 | } |
| 598 | |
fpizlo@apple.com | 6e69796 | 2015-10-12 17:56:26 +0000 | [diff] [blame] | 599 | extern "C" void* JIT_OPERATION compileFTLLazySlowPath(ExecState* exec, unsigned index) |
| 600 | { |
| 601 | VM& vm = exec->vm(); |
| 602 | |
| 603 | // We cannot GC. We've got pointers in evil places. |
| 604 | DeferGCForAWhile deferGC(vm.heap); |
| 605 | |
| 606 | CodeBlock* codeBlock = exec->codeBlock(); |
| 607 | JITCode* jitCode = codeBlock->jitCode()->ftl(); |
| 608 | |
| 609 | LazySlowPath& lazySlowPath = *jitCode->lazySlowPaths[index]; |
| 610 | lazySlowPath.generate(codeBlock); |
| 611 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 612 | return lazySlowPath.stub().code().executableAddress(); |
fpizlo@apple.com | 6e69796 | 2015-10-12 17:56:26 +0000 | [diff] [blame] | 613 | } |
| 614 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 615 | } } // namespace JSC::FTL |
| 616 | |
| 617 | #endif // ENABLE(FTL_JIT) |
| 618 | |