Changeset 34854 in webkit for trunk/JavaScriptCore/kjs/ObjectConstructor.cpp
- Timestamp:
- Jun 28, 2008, 2:22:01 PM (17 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ObjectConstructor.cpp
r34853 r34854 20 20 21 21 #include "config.h" 22 #include " object_object.h"22 #include "ObjectConstructor.h" 23 23 24 24 #include "JSGlobalObject.h" 25 #include "operations.h"26 25 #include "FunctionPrototype.h" 27 #include <stdio.h>28 26 29 27 namespace KJS { 30 31 // ------------------------------ ObjectPrototype --------------------------------32 33 static JSValue* objectProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&);34 static JSValue* objectProtoFuncHasOwnProperty(ExecState*, JSObject*, JSValue*, const ArgList&);35 static JSValue* objectProtoFuncIsPrototypeOf(ExecState*, JSObject*, JSValue*, const ArgList&);36 static JSValue* objectProtoFuncDefineGetter(ExecState*, JSObject*, JSValue*, const ArgList&);37 static JSValue* objectProtoFuncDefineSetter(ExecState*, JSObject*, JSValue*, const ArgList&);38 static JSValue* objectProtoFuncLookupGetter(ExecState*, JSObject*, JSValue*, const ArgList&);39 static JSValue* objectProtoFuncLookupSetter(ExecState*, JSObject*, JSValue*, const ArgList&);40 static JSValue* objectProtoFuncPropertyIsEnumerable(ExecState*, JSObject*, JSValue*, const ArgList&);41 static JSValue* objectProtoFuncToLocaleString(ExecState*, JSObject*, JSValue*, const ArgList&);42 43 ObjectPrototype::ObjectPrototype(ExecState* exec, FunctionPrototype* functionPrototype)44 : JSObject() // [[Prototype]] is null45 {46 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, objectProtoFuncToString), DontEnum);47 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toLocaleString, objectProtoFuncToLocaleString), DontEnum);48 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, objectProtoFuncValueOf), DontEnum);49 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().hasOwnProperty, objectProtoFuncHasOwnProperty), DontEnum);50 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().propertyIsEnumerable, objectProtoFuncPropertyIsEnumerable), DontEnum);51 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().isPrototypeOf, objectProtoFuncIsPrototypeOf), DontEnum);52 53 // Mozilla extensions54 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 2, exec->propertyNames().__defineGetter__, objectProtoFuncDefineGetter), DontEnum);55 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 2, exec->propertyNames().__defineSetter__, objectProtoFuncDefineSetter), DontEnum);56 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().__lookupGetter__, objectProtoFuncLookupGetter), DontEnum);57 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().__lookupSetter__, objectProtoFuncLookupSetter), DontEnum);58 }59 60 61 // ------------------------------ Functions --------------------------------62 63 // ECMA 15.2.4.2, 15.2.4.4, 15.2.4.5, 15.2.4.764 65 JSValue* objectProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)66 {67 return thisValue->toThisObject(exec);68 }69 70 JSValue* objectProtoFuncHasOwnProperty(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)71 {72 return jsBoolean(thisValue->toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, args[0]->toString(exec))));73 }74 75 JSValue* objectProtoFuncIsPrototypeOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)76 {77 JSObject* thisObj = thisValue->toThisObject(exec);78 79 if (!args[0]->isObject())80 return jsBoolean(false);81 82 JSValue* v = static_cast<JSObject*>(args[0])->prototype();83 84 while (true) {85 if (!v->isObject())86 return jsBoolean(false);87 if (thisObj == v)88 89 return jsBoolean(true);90 v = static_cast<JSObject*>(v)->prototype();91 }92 }93 94 JSValue* objectProtoFuncDefineGetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)95 {96 CallData callData;97 if (args[1]->getCallData(callData) == CallTypeNone)98 return throwError(exec, SyntaxError, "invalid getter usage");99 thisValue->toThisObject(exec)->defineGetter(exec, Identifier(exec, args[0]->toString(exec)), static_cast<JSObject*>(args[1]));100 return jsUndefined();101 }102 103 JSValue* objectProtoFuncDefineSetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)104 {105 CallData callData;106 if (args[1]->getCallData(callData) == CallTypeNone)107 return throwError(exec, SyntaxError, "invalid setter usage");108 thisValue->toThisObject(exec)->defineSetter(exec, Identifier(exec, args[0]->toString(exec)), static_cast<JSObject*>(args[1]));109 return jsUndefined();110 }111 112 JSValue* objectProtoFuncLookupGetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)113 {114 return thisValue->toThisObject(exec)->lookupGetter(exec, Identifier(exec, args[0]->toString(exec)));115 }116 117 JSValue* objectProtoFuncLookupSetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)118 {119 return thisValue->toThisObject(exec)->lookupSetter(exec, Identifier(exec, args[0]->toString(exec)));120 }121 122 JSValue* objectProtoFuncPropertyIsEnumerable(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)123 {124 return jsBoolean(thisValue->toThisObject(exec)->propertyIsEnumerable(exec, Identifier(exec, args[0]->toString(exec))));125 }126 127 JSValue* objectProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)128 {129 return jsString(exec, thisValue->toThisObject(exec)->toString(exec));130 }131 132 JSValue* objectProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)133 {134 return jsString(exec, "[object " + thisValue->toThisObject(exec)->className() + "]");135 }136 137 // ------------------------------ ObjectConstructor --------------------------------138 28 139 29 ObjectConstructor::ObjectConstructor(ExecState* exec, ObjectPrototype* objProto, FunctionPrototype* funcProto)
Note:
See TracChangeset
for help on using the changeset viewer.