Changeset 128265 in webkit
- Timestamp:
- Sep 11, 2012 11:14:56 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r128262 r128265 1 2012-09-11 Geoffrey Garen <ggaren@apple.com> 2 3 Don't allocate a backing store just for a function's name 4 https://bugs.webkit.org/show_bug.cgi?id=96468 5 6 Reviewed by Oliver Hunt. 7 8 Treat function.name like function.length etc., and use a custom getter. 9 This saves space in closures. 10 11 * debugger/DebuggerCallFrame.cpp: 12 (JSC::DebuggerCallFrame::functionName): 13 * debugger/DebuggerCallFrame.h: 14 (DebuggerCallFrame): Updated for interface change. 15 16 * runtime/Executable.h: 17 (JSC::JSFunction::JSFunction): Do a little inlining. 18 19 * runtime/JSFunction.cpp: 20 (JSC::JSFunction::finishCreation): Gone now. That's the point of the patch. 21 22 (JSC::JSFunction::name): 23 (JSC::JSFunction::displayName): 24 (JSC::JSFunction::nameGetter): 25 (JSC::JSFunction::getOwnPropertySlot): 26 (JSC::JSFunction::getOwnPropertyDescriptor): 27 (JSC::JSFunction::getOwnPropertyNames): 28 (JSC::JSFunction::put): 29 (JSC::JSFunction::deleteProperty): 30 (JSC::JSFunction::defineOwnProperty): Added custom accessors for .name 31 just like .length and others. 32 33 * runtime/JSFunction.h: 34 (JSC::JSFunction::create): 35 (JSFunction): Updated for interface changes. 36 1 37 2012-09-11 Mark Hahnenberg <mhahnenberg@apple.com> 2 38 -
trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp
r127202 r128265 37 37 namespace JSC { 38 38 39 const String*DebuggerCallFrame::functionName() const39 String DebuggerCallFrame::functionName() const 40 40 { 41 41 if (!m_callFrame->codeBlock()) 42 return 0;42 return String(); 43 43 44 44 if (!m_callFrame->callee()) 45 return 0;45 return String(); 46 46 47 47 JSObject* function = m_callFrame->callee(); 48 48 if (!function || !function->inherits(&JSFunction::s_info)) 49 return 0;50 return &jsCast<JSFunction*>(function)->name(m_callFrame);49 return String(); 50 return jsCast<JSFunction*>(function)->name(m_callFrame); 51 51 } 52 52 -
trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.h
r127202 r128265 52 52 JSGlobalObject* dynamicGlobalObject() const { return m_callFrame->dynamicGlobalObject(); } 53 53 JSScope* scope() const { return m_callFrame->scope(); } 54 JS_EXPORT_PRIVATE const String*functionName() const;54 JS_EXPORT_PRIVATE String functionName() const; 55 55 JS_EXPORT_PRIVATE String calculatedFunctionName() const; 56 56 JS_EXPORT_PRIVATE Type type() const; -
trunk/Source/JavaScriptCore/runtime/Executable.h
r127958 r128265 32 32 #include "JSFunction.h" 33 33 #include "Interpreter.h" 34 #include "JSGlobalObject.h" 34 35 #include "LLIntCLoop.h" 35 36 #include "Nodes.h" … … 754 755 WriteBarrier<SharedSymbolTable> m_symbolTable; 755 756 }; 757 758 inline JSFunction::JSFunction(JSGlobalData& globalData, FunctionExecutable* executable, JSScope* scope) 759 : Base(globalData, scope->globalObject()->functionStructure()) 760 , m_executable(globalData, this, executable) 761 , m_scope(globalData, this, scope) 762 { 763 } 756 764 757 765 inline FunctionExecutable* JSFunction::jsExecutable() const -
trunk/Source/JavaScriptCore/runtime/JSFunction.cpp
r127958 r128265 85 85 } 86 86 87 JSFunction::JSFunction(ExecState* exec, FunctionExecutable* executable, JSScope* scope)88 : Base(exec->globalData(), scope->globalObject()->functionStructure())89 , m_executable(exec->globalData(), this, executable)90 , m_scope(exec->globalData(), this, scope)91 {92 }93 94 87 void JSFunction::finishCreation(ExecState* exec, NativeExecutable* executable, int length, const String& name) 95 88 { … … 99 92 putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name), DontDelete | ReadOnly | DontEnum); 100 93 putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum); 101 }102 103 void JSFunction::finishCreation(ExecState* exec, FunctionExecutable* executable, JSScope* scope)104 {105 JSGlobalData& globalData = exec->globalData();106 Base::finishCreation(globalData);107 ASSERT(inherits(&s_info));108 109 // Switching the structure here is only safe if we currently have the function structure!110 ASSERT(structure() == scope->globalObject()->functionStructure());111 setStructureAndReallocateStorageIfNecessary(112 globalData,113 scope->globalObject()->namedFunctionStructure());114 putDirectOffset(globalData, scope->globalObject()->functionNameOffset(), executable->nameValue());115 94 } 116 95 … … 125 104 } 126 105 127 const String&JSFunction::name(ExecState* exec)128 { 129 return asString(getDirect(exec->globalData(), exec->globalData().propertyNames->name))->tryGetValue();130 } 131 132 constString JSFunction::displayName(ExecState* exec)106 String JSFunction::name(ExecState* exec) 107 { 108 return get(exec, exec->globalData().propertyNames->name).toWTFString(exec); 109 } 110 111 String JSFunction::displayName(ExecState* exec) 133 112 { 134 113 JSValue displayName = getDirect(exec->globalData(), exec->globalData().propertyNames->displayName); … … 214 193 } 215 194 195 JSValue JSFunction::nameGetter(ExecState*, JSValue slotBase, PropertyName) 196 { 197 JSFunction* thisObj = jsCast<JSFunction*>(slotBase); 198 ASSERT(!thisObj->isHostFunction()); 199 return thisObj->jsExecutable()->nameValue(); 200 } 201 216 202 bool JSFunction::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) 217 203 { … … 252 238 } 253 239 240 if (propertyName == exec->propertyNames().name) { 241 slot.setCacheableCustom(thisObject, nameGetter); 242 return true; 243 } 244 254 245 if (propertyName == exec->propertyNames().caller) { 255 246 if (thisObject->jsExecutable()->isStrictMode()) { … … 300 291 } 301 292 293 if (propertyName == exec->propertyNames().name) { 294 descriptor.setDescriptor(thisObject->jsExecutable()->nameValue(), ReadOnly | DontEnum | DontDelete); 295 return true; 296 } 297 302 298 if (propertyName == exec->propertyNames().caller) { 303 299 if (thisObject->jsExecutable()->isStrictMode()) { … … 328 324 propertyNames.add(exec->propertyNames().caller); 329 325 propertyNames.add(exec->propertyNames().length); 326 propertyNames.add(exec->propertyNames().name); 330 327 } 331 328 Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode); … … 357 354 return; 358 355 } 359 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length || propertyName == exec->propertyNames(). caller) {356 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length || propertyName == exec->propertyNames().name || propertyName == exec->propertyNames().caller) { 360 357 if (slot.isStrictMode()) 361 358 throwTypeError(exec, StrictModeReadonlyPropertyWriteError); … … 372 369 && (propertyName == exec->propertyNames().arguments 373 370 || propertyName == exec->propertyNames().length 371 || propertyName == exec->propertyNames().name 374 372 || propertyName == exec->propertyNames().prototype 375 373 || propertyName == exec->propertyNames().caller)) … … 410 408 } else if (propertyName == exec->propertyNames().length) 411 409 valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), jsNumber(thisObject->jsExecutable()->parameterCount())); 410 else if (propertyName == exec->propertyNames().name) 411 valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), thisObject->jsExecutable()->nameValue()); 412 412 else 413 413 return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException); -
trunk/Source/JavaScriptCore/runtime/JSFunction.h
r127202 r128265 60 60 static JSFunction* create(ExecState* exec, FunctionExecutable* executable, JSScope* scope) 61 61 { 62 JSFunction* function = new (NotNull, allocateCell<JSFunction>(*exec->heap())) JSFunction(exec, executable, scope); 62 JSGlobalData& globalData = exec->globalData(); 63 JSFunction* function = new (NotNull, allocateCell<JSFunction>(globalData.heap)) JSFunction(globalData, executable, scope); 63 64 ASSERT(function->structure()->globalObject()); 64 function->finishCreation( exec, executable, scope);65 function->finishCreation(globalData); 65 66 return function; 66 67 } 67 68 68 JS_EXPORT_PRIVATE const String&name(ExecState*);69 JS_EXPORT_PRIVATE constString displayName(ExecState*);69 JS_EXPORT_PRIVATE String name(ExecState*); 70 JS_EXPORT_PRIVATE String displayName(ExecState*); 70 71 const String calculatedDisplayName(ExecState*); 71 72 … … 138 139 139 140 JS_EXPORT_PRIVATE JSFunction(ExecState*, JSGlobalObject*, Structure*); 140 JSFunction( ExecState*, FunctionExecutable*, JSScope*);141 JSFunction(JSGlobalData&, FunctionExecutable*, JSScope*); 141 142 142 143 void finishCreation(ExecState*, NativeExecutable*, int length, const String& name); 143 void finishCreation(ExecState*, FunctionExecutable*, JSScope*);144 using Base::finishCreation; 144 145 145 146 Structure* cacheInheritorID(ExecState*); … … 164 165 static JSValue callerGetter(ExecState*, JSValue, PropertyName); 165 166 static JSValue lengthGetter(ExecState*, JSValue, PropertyName); 167 static JSValue nameGetter(ExecState*, JSValue, PropertyName); 166 168 167 169 WriteBarrier<ExecutableBase> m_executable;
Note: See TracChangeset
for help on using the changeset viewer.