Changeset 197489 in webkit for trunk/Source/JavaScriptCore/jsc.cpp
- Timestamp:
- Mar 2, 2016, 9:15:56 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/jsc.cpp
r197261 r197489 33 33 #include "Exception.h" 34 34 #include "ExceptionHelpers.h" 35 #include "HeapProfiler.h" 36 #include "HeapSnapshotBuilder.h" 35 37 #include "HeapStatistics.h" 36 38 #include "InitializeThreading.h" … … 466 468 }; 467 469 470 class SimpleObject : public JSNonFinalObject { 471 public: 472 SimpleObject(VM& vm, Structure* structure) 473 : Base(vm, structure) 474 { 475 } 476 477 typedef JSNonFinalObject Base; 478 static const bool needsDestruction = false; 479 480 static SimpleObject* create(VM& vm, JSGlobalObject* globalObject) 481 { 482 Structure* structure = createStructure(vm, globalObject, jsNull()); 483 SimpleObject* simpleObject = new (NotNull, allocateCell<SimpleObject>(vm.heap, sizeof(SimpleObject))) SimpleObject(vm, structure); 484 simpleObject->finishCreation(vm); 485 return simpleObject; 486 } 487 488 void finishCreation(VM& vm) 489 { 490 Base::finishCreation(vm); 491 } 492 493 static void visitChildren(JSCell* cell, SlotVisitor& visitor) 494 { 495 SimpleObject* thisObject = jsCast<SimpleObject*>(cell); 496 ASSERT_GC_OBJECT_INHERITS(thisObject, info()); 497 Base::visitChildren(thisObject, visitor); 498 visitor.append(&thisObject->m_hiddenValue); 499 } 500 501 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 502 { 503 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); 504 } 505 506 JSValue hiddenValue() 507 { 508 return m_hiddenValue.get(); 509 } 510 511 void setHiddenValue(VM& vm, JSValue value) 512 { 513 ASSERT(value.isCell()); 514 m_hiddenValue.set(vm, this, value); 515 } 516 517 DECLARE_INFO; 518 519 private: 520 WriteBarrier<Unknown> m_hiddenValue; 521 }; 522 523 468 524 const ClassInfo Element::s_info = { "Element", &Base::s_info, 0, CREATE_METHOD_TABLE(Element) }; 469 525 const ClassInfo Masquerader::s_info = { "Masquerader", &Base::s_info, 0, CREATE_METHOD_TABLE(Masquerader) }; … … 472 528 const ClassInfo CustomGetter::s_info = { "CustomGetter", &Base::s_info, 0, CREATE_METHOD_TABLE(CustomGetter) }; 473 529 const ClassInfo RuntimeArray::s_info = { "RuntimeArray", &Base::s_info, 0, CREATE_METHOD_TABLE(RuntimeArray) }; 530 const ClassInfo SimpleObject::s_info = { "SimpleObject", &Base::s_info, 0, CREATE_METHOD_TABLE(SimpleObject) }; 474 531 475 532 ElementHandleOwner* Element::handleOwner() … … 502 559 static EncodedJSValue JSC_HOST_CALL functionCreateElement(ExecState*); 503 560 static EncodedJSValue JSC_HOST_CALL functionGetElement(ExecState*); 561 static EncodedJSValue JSC_HOST_CALL functionCreateSimpleObject(ExecState*); 562 static EncodedJSValue JSC_HOST_CALL functionGetHiddenValue(ExecState*); 563 static EncodedJSValue JSC_HOST_CALL functionSetHiddenValue(ExecState*); 504 564 static EncodedJSValue JSC_HOST_CALL functionPrint(ExecState*); 505 565 static EncodedJSValue JSC_HOST_CALL functionDebug(ExecState*); … … 556 616 static EncodedJSValue JSC_HOST_CALL functionCheckModuleSyntax(ExecState*); 557 617 static EncodedJSValue JSC_HOST_CALL functionPlatformSupportsSamplingProfiler(ExecState*); 618 static EncodedJSValue JSC_HOST_CALL functionGenerateHeapSnapshot(ExecState*); 558 619 #if ENABLE(SAMPLING_PROFILER) 559 620 static EncodedJSValue JSC_HOST_CALL functionStartSamplingProfiler(ExecState*); … … 709 770 addFunction(vm, "setElementRoot", functionSetElementRoot, 2); 710 771 772 addConstructableFunction(vm, "SimpleObject", functionCreateSimpleObject, 0); 773 addFunction(vm, "getHiddenValue", functionGetHiddenValue, 1); 774 addFunction(vm, "setHiddenValue", functionSetHiddenValue, 2); 775 711 776 putDirectNativeFunction(vm, this, Identifier::fromString(&vm, "DFGTrue"), 0, functionFalse1, DFGTrueIntrinsic, DontEnum); 712 777 putDirectNativeFunction(vm, this, Identifier::fromString(&vm, "OSRExit"), 0, functionUndefined1, OSRExitIntrinsic, DontEnum); … … 748 813 749 814 addFunction(vm, "platformSupportsSamplingProfiler", functionPlatformSupportsSamplingProfiler, 0); 815 addFunction(vm, "generateHeapSnapshot", functionGenerateHeapSnapshot, 0); 750 816 #if ENABLE(SAMPLING_PROFILER) 751 817 addFunction(vm, "startSamplingProfiler", functionStartSamplingProfiler, 0); … … 1134 1200 } 1135 1201 1202 EncodedJSValue JSC_HOST_CALL functionCreateSimpleObject(ExecState* exec) 1203 { 1204 JSLockHolder lock(exec); 1205 return JSValue::encode(SimpleObject::create(exec->vm(), exec->lexicalGlobalObject())); 1206 } 1207 1208 EncodedJSValue JSC_HOST_CALL functionGetHiddenValue(ExecState* exec) 1209 { 1210 JSLockHolder lock(exec); 1211 SimpleObject* simpleObject = jsCast<SimpleObject*>(exec->argument(0).asCell()); 1212 return JSValue::encode(simpleObject->hiddenValue()); 1213 } 1214 1215 EncodedJSValue JSC_HOST_CALL functionSetHiddenValue(ExecState* exec) 1216 { 1217 JSLockHolder lock(exec); 1218 SimpleObject* simpleObject = jsCast<SimpleObject*>(exec->argument(0).asCell()); 1219 JSValue value = exec->argument(1); 1220 simpleObject->setHiddenValue(exec->vm(), value); 1221 return JSValue::encode(jsUndefined()); 1222 } 1223 1136 1224 EncodedJSValue JSC_HOST_CALL functionCreateProxy(ExecState* exec) 1137 1225 { … … 1645 1733 return JSValue::encode(JSValue(JSC::JSValue::JSFalse)); 1646 1734 #endif 1735 } 1736 1737 EncodedJSValue JSC_HOST_CALL functionGenerateHeapSnapshot(ExecState* exec) 1738 { 1739 JSLockHolder lock(exec); 1740 1741 HeapSnapshotBuilder snapshotBuilder(exec->vm().ensureHeapProfiler()); 1742 snapshotBuilder.buildSnapshot(); 1743 1744 String jsonString = snapshotBuilder.json(); 1745 EncodedJSValue result = JSValue::encode(JSONParse(exec, jsonString)); 1746 RELEASE_ASSERT(!exec->hadException()); 1747 return result; 1647 1748 } 1648 1749
Note:
See TracChangeset
for help on using the changeset viewer.