Changeset 197205 in webkit for trunk/Source/JavaScriptCore/runtime
- Timestamp:
- Feb 26, 2016, 2:29:59 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore/runtime
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/FunctionRareData.h
r196956 r197205 94 94 void setBoundFunctionStructure(VM& vm, Structure* structure) { m_boundFunctionStructure.set(vm, this, structure); } 95 95 96 bool hasReifiedLength() const { return m_hasReifiedLength; } 97 void setHasReifiedLength() { m_hasReifiedLength = true; } 98 bool hasReifiedName() const { return m_hasReifiedName; } 99 void setHasReifiedName() { m_hasReifiedName = true; } 100 96 101 protected: 97 102 FunctionRareData(VM&); … … 119 124 InternalFunctionAllocationProfile m_internalFunctionAllocationProfile; 120 125 WriteBarrier<Structure> m_boundFunctionStructure; 126 bool m_hasReifiedLength { false }; 127 bool m_hasReifiedName { false }; 121 128 }; 122 129 -
trunk/Source/JavaScriptCore/runtime/JSFunction.cpp
r196722 r197205 117 117 ASSERT(inherits(info())); 118 118 m_executable.set(vm, this, executable); 119 putDirect(vm, vm.propertyNames->name, jsString(&vm, name), DontDelete |ReadOnly | DontEnum);120 putDirect(vm, vm.propertyNames->length, jsNumber(length), DontDelete |ReadOnly | DontEnum);119 putDirect(vm, vm.propertyNames->name, jsString(&vm, name), ReadOnly | DontEnum); 120 putDirect(vm, vm.propertyNames->length, jsNumber(length), ReadOnly | DontEnum); 121 121 } 122 122 … … 124 124 { 125 125 JSFunction* function = create(vm, executable, globalObject); 126 function->putDirect(vm, vm.propertyNames->name, jsString(&vm, executable->name().string()), DontDelete |ReadOnly | DontEnum);127 function->putDirect(vm, vm.propertyNames->length, jsNumber(executable->parameterCount()), DontDelete |ReadOnly | DontEnum);126 function->putDirect(vm, vm.propertyNames->name, jsString(&vm, executable->name().string()), ReadOnly | DontEnum); 127 function->putDirect(vm, vm.propertyNames->length, jsNumber(executable->parameterCount()), ReadOnly | DontEnum); 128 128 return function; 129 129 } … … 132 132 { 133 133 JSFunction* function = create(vm, executable, globalObject); 134 function->putDirect(vm, vm.propertyNames->name, jsString(&vm, name), DontDelete |ReadOnly | DontEnum);135 function->putDirect(vm, vm.propertyNames->length, jsNumber(executable->parameterCount()), DontDelete |ReadOnly | DontEnum);134 function->putDirect(vm, vm.propertyNames->name, jsString(&vm, name), ReadOnly | DontEnum); 135 function->putDirect(vm, vm.propertyNames->length, jsNumber(executable->parameterCount()), ReadOnly | DontEnum); 136 136 return function; 137 137 } … … 342 342 return JSValue::encode(caller); 343 343 return JSValue::encode(throwTypeError(exec, ASCIILiteral("Function.caller used to retrieve strict caller"))); 344 }345 346 EncodedJSValue JSFunction::lengthGetter(ExecState*, EncodedJSValue thisValue, PropertyName)347 {348 JSFunction* thisObj = jsCast<JSFunction*>(JSValue::decode(thisValue));349 ASSERT(!thisObj->isHostFunction());350 return JSValue::encode(jsNumber(thisObj->jsExecutable()->parameterCount()));351 }352 353 EncodedJSValue JSFunction::nameGetter(ExecState*, EncodedJSValue thisValue, PropertyName)354 {355 JSFunction* thisObj = jsCast<JSFunction*>(JSValue::decode(thisValue));356 ASSERT(!thisObj->isHostFunction());357 return JSValue::encode(thisObj->jsExecutable()->nameValue());358 344 } 359 345 … … 398 384 } 399 385 400 if (propertyName == exec->propertyNames().length) {401 slot.setCacheableCustom(thisObject, ReadOnly | DontEnum | DontDelete, lengthGetter);402 return true;403 }404 405 if (propertyName == exec->propertyNames().name) {406 slot.setCacheableCustom(thisObject, ReadOnly | DontEnum | DontDelete, nameGetter);407 return true;408 }409 410 386 if (propertyName == exec->propertyNames().caller) { 411 387 if (thisObject->jsExecutable()->isStrictMode()) { … … 422 398 } 423 399 400 thisObject->reifyLazyPropertyIfNeeded(exec, propertyName); 401 424 402 return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot); 425 403 } … … 436 414 propertyNames.add(vm.propertyNames->arguments); 437 415 propertyNames.add(vm.propertyNames->caller); 438 propertyNames.add(vm.propertyNames->length); 439 propertyNames.add(vm.propertyNames->name); 416 if (!thisObject->hasReifiedLength()) 417 propertyNames.add(vm.propertyNames->length); 418 if (!thisObject->hasReifiedName()) 419 propertyNames.add(vm.propertyNames->name); 440 420 } 441 421 Base::getOwnNonIndexPropertyNames(thisObject, exec, propertyNames, mode); … … 468 448 return; 469 449 } 470 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames(). length || propertyName == exec->propertyNames().name || propertyName == exec->propertyNames().caller) {450 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().caller) { 471 451 if (slot.isStrictMode()) 472 452 throwTypeError(exec, StrictModeReadonlyPropertyWriteError); 473 453 return; 474 454 } 455 thisObject->reifyLazyPropertyIfNeeded(exec, propertyName); 475 456 Base::put(thisObject, exec, propertyName, value, slot); 476 457 } … … 483 464 FunctionExecutable* executable = thisObject->jsExecutable(); 484 465 if (propertyName == exec->propertyNames().arguments 485 || propertyName == exec->propertyNames().length486 || propertyName == exec->propertyNames().name487 466 || (propertyName == exec->propertyNames().prototype && !executable->isArrowFunction()) 488 467 || propertyName == exec->propertyNames().caller) 489 return false; 468 return false; 469 470 thisObject->reifyLazyPropertyIfNeeded(exec, propertyName); 490 471 } 491 472 … … 526 507 } 527 508 valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), retrieveCallerFunction(exec, thisObject)); 528 } else if (propertyName == exec->propertyNames().length) 529 valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), jsNumber(thisObject->jsExecutable()->parameterCount())); 530 else if (propertyName == exec->propertyNames().name) 531 valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), thisObject->jsExecutable()->nameValue()); 532 else 509 } else { 510 thisObject->reifyLazyPropertyIfNeeded(exec, propertyName); 533 511 return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); 512 } 534 513 535 514 if (descriptor.configurablePresent() && descriptor.configurable()) { … … 589 568 } 590 569 570 void JSFunction::reifyLength(ExecState* exec) 571 { 572 VM& vm = exec->vm(); 573 FunctionRareData* rareData = this->rareData(vm); 574 575 ASSERT(!hasReifiedLength()); 576 ASSERT(!isHostFunction()); 577 JSValue initialValue = jsNumber(jsExecutable()->parameterCount()); 578 unsigned initialAttributes = DontEnum | ReadOnly; 579 const Identifier& identifier = exec->propertyNames().length; 580 putDirect(vm, identifier, initialValue, initialAttributes); 581 582 rareData->setHasReifiedLength(); 583 } 584 585 void JSFunction::reifyName(ExecState* exec) 586 { 587 VM& vm = exec->vm(); 588 FunctionRareData* rareData = this->rareData(vm); 589 590 ASSERT(!hasReifiedName()); 591 ASSERT(!isHostFunction()); 592 JSValue initialValue = jsExecutable()->nameValue(); 593 unsigned initialAttributes = DontEnum | ReadOnly; 594 const Identifier& identifier = exec->propertyNames().name; 595 putDirect(vm, identifier, initialValue, initialAttributes); 596 597 rareData->setHasReifiedName(); 598 } 599 600 void JSFunction::reifyLazyPropertyIfNeeded(ExecState* exec, PropertyName propertyName) 601 { 602 if (propertyName == exec->propertyNames().length) { 603 if (!hasReifiedLength()) 604 reifyLength(exec); 605 } else if (propertyName == exec->propertyNames().name) { 606 if (!hasReifiedName()) 607 reifyName(exec); 608 } 609 } 610 591 611 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/JSFunction.h
r196331 r197205 187 187 return function; 188 188 } 189 189 190 bool hasReifiedLength() const; 191 bool hasReifiedName() const; 192 void reifyLength(ExecState*); 193 void reifyName(ExecState*); 194 void reifyLazyPropertyIfNeeded(ExecState*, PropertyName propertyName); 195 190 196 friend class LLIntOffsetsExtractor; 191 197 -
trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h
r195070 r197205 1 1 /* 2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.2 * Copyright (C) 2013, 2015-2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 111 111 } 112 112 113 inline bool JSFunction::hasReifiedLength() const 114 { 115 return m_rareData ? m_rareData->hasReifiedLength() : false; 116 } 117 118 inline bool JSFunction::hasReifiedName() const 119 { 120 return m_rareData ? m_rareData->hasReifiedName() : false; 121 } 122 113 123 } // namespace JSC 114 124
Note:
See TracChangeset
for help on using the changeset viewer.