Просмотр исходного кода

fix(runtime-core): set appContext.provides to Object.create(null) (#781)

djy0 6 лет назад
Родитель
Сommit
04f83fa681

+ 4 - 0
packages/runtime-core/__tests__/apiCreateApp.spec.ts

@@ -79,6 +79,9 @@ describe('api: createApp', () => {
       setup() {
         const foo = inject('foo')
         const bar = inject('bar')
+        try {
+          inject('__proto__')
+        } catch (e) {}
         return () => `${foo},${bar}`
       }
     }
@@ -90,6 +93,7 @@ describe('api: createApp', () => {
     const root = nodeOps.createElement('div')
     app.mount(root)
     expect(serializeInner(root)).toBe(`3,2`)
+    expect('[Vue warn]: injection "__proto__" not found.').toHaveBeenWarned()
   })
 
   test('component', () => {

+ 1 - 1
packages/runtime-core/src/apiCreateApp.ts

@@ -82,7 +82,7 @@ export function createAppContext(): AppContext {
     mixins: [],
     components: {},
     directives: {},
-    provides: {}
+    provides: Object.create(null)
   }
 }